1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
#include "Piraha.hpp"
namespace piraha {
extern smart_ptr<Pattern> compile(smart_ptr<Group> g,bool ignCase,smart_ptr<Grammar> gram);
smart_ptr<Grammar> pegGrammar = AutoGrammar::reparserGenerator();
void compile(smart_ptr<Grammar> thisg,std::string name,smart_ptr<Group> g) {
thisg->default_rule = name;
smart_ptr<Pattern> p = piraha::compile(g,false,thisg);
thisg->patterns.put(name,p);
}
void compile(smart_ptr<Grammar> thisg,std::string name,std::string pattern) {
thisg->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 = piraha::compile(g,false,thisg);
thisg->patterns.put(name,p);
} else {
std::cout << "Could not compile(" << name << "," << pattern << ")" << std::endl;
std::cout << "pos = " << m->pos << std::endl;
assert(false);
}
}
}
|