source: icGREP/icgrep-devel/icgrep/printer_re.cpp @ 4182

Last change on this file since 4182 was 4182, checked in by nmedfort, 5 years ago

RE Parser modification to use ParseFailure? exceptions; removed the list reversal within Alt and Seq constructors and adjusted the functions that relied on it occurring.

File size: 1.9 KB
Line 
1/*
2 *  Copyright (c) 2014 International Characters.
3 *  This software is licensed to the public under the Open Software License 3.0.
4 *  icgrep is a trademark of International Characters.
5 */
6
7#include "printer_re.h"
8
9
10std::string Printer_RE::PrintRE(RE * re)
11{
12    std::string retVal = "";
13
14    if (re == nullptr) {
15        retVal = "--> RE NullPtr! <--";
16    }
17    else if (Alt* re_alt = dynamic_cast<Alt*>(re))
18    {
19        retVal += "(Alt[";
20        for (RE * re : *re_alt) {
21            retVal += PrintRE(re) + ",";
22        }
23        retVal = retVal.substr(0, retVal.size() - 1);
24        retVal += "])";
25    }
26    else if (CC* re_cc = dynamic_cast<CC*>(re))
27    {
28        retVal += "CC \"";
29        retVal += re_cc->getName();
30        retVal += "\" ";
31
32        for (const CharSetItem & item : re_cc->getItems())
33        {
34            retVal += "[";
35            retVal += std::to_string(item.lo_codepoint) + ",";
36            retVal += std::to_string(item.hi_codepoint);
37            retVal += "]";
38        }
39    }
40    else if (Name* re_name = dynamic_cast<Name*>(re))
41    {
42        retVal += "Name \"";
43        retVal += re_name->getName();
44        retVal += "\" ";
45    }
46    else if (dynamic_cast<End*>(re))
47    {
48        retVal += "End";
49    }
50    else if (Rep* re_rep = dynamic_cast<Rep*>(re))
51    {
52        retVal += "Rep("  + PrintRE(re_rep->getRE()) + "," + std::to_string(re_rep->getLB()) + ",";
53        retVal += (re_rep->getUB() == UNBOUNDED_REP ? "Unbounded" : "UpperBound(" + std::to_string(re_rep->getUB()) + ")");
54    }
55    else if (Seq* re_seq = dynamic_cast<Seq*>(re))
56    {
57        retVal += "(Seq[";
58        for (RE * re : *re_seq) {
59            retVal += PrintRE(re) + ",";
60        }
61        retVal = retVal.substr(0, retVal.size() - 1);
62        retVal += "])";
63    }
64    else if (dynamic_cast<Start*>(re))
65    {
66        retVal += "Start";
67    }
68    else
69    {
70        retVal += "--> RE Unknown <--";
71    }
72
73    return retVal;
74}
Note: See TracBrowser for help on using the repository browser.