summaryrefslogtreecommitdiff
path: root/src/piraha/Lookup.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/piraha/Lookup.cc')
-rw-r--r--src/piraha/Lookup.cc30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/piraha/Lookup.cc b/src/piraha/Lookup.cc
new file mode 100644
index 00000000..ed42e1d1
--- /dev/null
+++ b/src/piraha/Lookup.cc
@@ -0,0 +1,30 @@
+#include "Piraha.hpp"
+
+Lookup::Lookup(std::string name_,smart_ptr<Grammar> g) : gram(g), name(name_), capture(true) {
+ if(name[0] == '-') {
+ capture = false;
+ name = name.substr(1);
+ }
+}
+
+bool Lookup::match(Matcher *m) {
+ smart_ptr<Pattern> p = gram->patterns.get(name);
+ if(!p.valid()) std::cout << "Lookup of pattern [" << name << "] failed. Jmap = " << gram->patterns << std::endl;
+ assert(p.valid());
+ vector<smart_ptr<Group> > chSave = m->children;
+ m->children.clear();
+ int s = m->pos;
+ std::string save_name = m->inrule;
+ m->inrule += "::";
+ m->inrule += name;
+ bool b = p->match(m);
+ m->inrule = save_name;
+ int e = m->pos;
+ if(b) {
+ smart_ptr<Group> g = new Group(name,m->input,s,e,m->children);
+ if(capture)
+ chSave.push_back(g);
+ }
+ m->children = chSave;
+ return b;
+}