From f74e867aab6e3a36824f5c33ed1d75bac90ef06f Mon Sep 17 00:00:00 2001 From: sbrandt Date: Fri, 22 Mar 2013 19:46:56 +0000 Subject: 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 --- src/piraha/Piraha.hpp | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) (limited to 'src/piraha/Piraha.hpp') 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 > m; public: @@ -127,6 +133,10 @@ public: Seq(vector > patterns,bool ign,bool show); virtual ~Seq() {} bool match(Matcher *m); + virtual void insert(std::ostream& o) { + for(int i=0;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: -- cgit v1.2.3