diff options
author | sbrandt <sbrandt@17b73243-c579-4c4c-a9d2-2d5706c11dac> | 2013-02-25 16:54:00 +0000 |
---|---|---|
committer | sbrandt <sbrandt@17b73243-c579-4c4c-a9d2-2d5706c11dac> | 2013-02-25 16:54:00 +0000 |
commit | 4730bc03f50318da9432bbd17f7c9cc91de1eb21 (patch) | |
tree | 740a46e73a289157f7cc45e281ecfdfb686977e5 /src/piraha/Grammar.cc | |
parent | f9f8fb05dc03fa339e37a04608009f62e4fcc3b0 (diff) |
Change the parameter parser to Piraha
git-svn-id: http://svn.cactuscode.org/flesh/trunk@4960 17b73243-c579-4c4c-a9d2-2d5706c11dac
Diffstat (limited to 'src/piraha/Grammar.cc')
-rw-r--r-- | src/piraha/Grammar.cc | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/piraha/Grammar.cc b/src/piraha/Grammar.cc new file mode 100644 index 00000000..9cb7f0b0 --- /dev/null +++ b/src/piraha/Grammar.cc @@ -0,0 +1,24 @@ +#include "Piraha.hpp" + +extern smart_ptr<Pattern> compile(smart_ptr<Group> g,bool ignCase,smart_ptr<Grammar> gram); + +smart_ptr<Grammar> pegGrammar = AutoGrammar::reparserGenerator(); + +void Grammar::compile(std::string name,smart_ptr<Group> g) { + default_rule = name; + smart_ptr<Pattern> p = ::compile(g,false,this); + patterns.put(name,p); +} +void Grammar::compile(std::string name,std::string pattern) { + default_rule = name; + smart_ptr<Matcher> m = new Matcher(pegGrammar,"pattern",pattern.c_str()); + smart_ptr<Group> g = m.dup<Group>(); + if(m->matches()) { + smart_ptr<Pattern> p = ::compile(g,false,this); + patterns.put(name,p); + } else { + std::cout << "Could not compile(" << name << "," << pattern << ")" << std::endl; + std::cout << "pos = " << m->pos << std::endl; + assert(false); + } +} |