diff options
author | sbrandt <sbrandt@17b73243-c579-4c4c-a9d2-2d5706c11dac> | 2013-03-22 19:46:56 +0000 |
---|---|---|
committer | sbrandt <sbrandt@17b73243-c579-4c4c-a9d2-2d5706c11dac> | 2013-03-22 19:46:56 +0000 |
commit | f74e867aab6e3a36824f5c33ed1d75bac90ef06f (patch) | |
tree | cecf6e882ad4ef16dce092ac06dff36d16c84489 /src/piraha/Piraha.hpp | |
parent | 249587f1e95ea75de1e7a04161124751750e42c0 (diff) |
Updates to Piraha:
1) Added some debug code
2) Fix logic bugs that only I noticed
Still passes the ET testsuite.
git-svn-id: http://svn.cactuscode.org/flesh/trunk@4988 17b73243-c579-4c4c-a9d2-2d5706c11dac
Diffstat (limited to 'src/piraha/Piraha.hpp')
-rw-r--r-- | src/piraha/Piraha.hpp | 68 |
1 files changed, 67 insertions, 1 deletions
diff --git a/src/piraha/Piraha.hpp b/src/piraha/Piraha.hpp index 3addbc83..4308b1fc 100644 --- a/src/piraha/Piraha.hpp +++ b/src/piraha/Piraha.hpp @@ -76,8 +76,14 @@ public: Pattern() {} virtual ~Pattern() {} virtual std::string fmt() { return "blank"; } + virtual void insert(std::ostream& o) { o << "{?}"; } }; +inline std::ostream& operator<<(std::ostream& o,Pattern& p) { + p.insert(o); + return o; +} + class JMap { map<std::string,smart_ptr<Pattern> > m; public: @@ -127,6 +133,10 @@ public: Seq(vector<smart_ptr<Pattern> > patterns,bool ign,bool show); virtual ~Seq() {} bool match(Matcher *m); + virtual void insert(std::ostream& o) { + for(int i=0;i<patterns.size();i++) + o << *patterns[i]; + } }; class Or : public Pattern { @@ -137,6 +147,14 @@ public: Or(Pattern *p,...); virtual ~Or() {} bool match(Matcher *m); + virtual void insert(std::ostream& o) { + o << "("; + for(int i=0;i<patterns.size();i++) { + if(i > 0) o << "|"; + o << *patterns[i]; + } + o << ")"; + } }; class Literal : public Pattern { @@ -149,6 +167,24 @@ public: s += c+")"; return s; } + virtual void insert(std::ostream& o) { + if(c == '\n') + o << "\\n"; + else if(c == '\r') + o << "\\r"; + else if(c == '\t') + o << "\\t"; + else if(c == '\b') + o << "\\b"; + else if(c >= 'a' && c <= 'z') + o << c; + else if(c >= 'A' && c <= 'Z') + o << c; + else if(c >= '0' && c <= '9') + o << c; + else + o << "\\" << c; + } }; class ILiteral : public Pattern { @@ -164,6 +200,27 @@ public: s += ")"; return s; } + virtual void insert(std::ostream& o) { + char c = lc; + if(lc != uc) + o << "[" << lc << uc << "]"; + else if(c == '\n') + o << "\\n"; + else if(c == '\r') + o << "\\r"; + else if(c == '\t') + o << "\\t"; + else if(c == '\b') + o << "\\b"; + else if(c >= 'a' && c <= 'z') + o << c; + else if(c >= 'A' && c <= 'Z') + o << c; + else if(c >= '0' && c <= '9') + o << c; + else + o << "\\" << c; + } }; class Lookup : public Pattern { @@ -177,6 +234,9 @@ public: std::string fmt() { return "Literal:"+name; } + virtual void insert(std::ostream& o) { + o << "{" << name << "}"; + } }; class Nothing : public Pattern { @@ -189,18 +249,21 @@ class Start : public Pattern { public: Start() {} bool match(Matcher *m); + virtual void insert(std::ostream& o) { o << "^"; } }; class End : public Pattern { public: End() {} bool match(Matcher *m); + virtual void insert(std::ostream& o) { o << "$"; } }; class Dot : public Pattern { public: Dot() {} bool match(Matcher *m); + virtual void insert(std::ostream& o) { o << "."; } }; class Multi : public Pattern { @@ -211,6 +274,9 @@ public: Multi(Pattern *p,int min_,int max_) : minv(min_), maxv(max_), pattern(p) {} virtual ~Multi() {} bool match(Matcher *m); + virtual void insert(std::ostream& o) { + o << *pattern << "{" << minv << "," << maxv << "}"; + } }; class Range : public Pattern { @@ -230,8 +296,8 @@ public: Bracket *addRange(char lo,char hi); Bracket *addRange(char lo,char hi,bool ign); bool match(Matcher *m); + virtual void insert(std::ostream& o); }; -extern std::ostream& operator<<(std::ostream&,Bracket&); class NegLookAhead : public Pattern { public: |