2014-02-16 22:13:08 -08:00
|
|
|
#include "compiler.h"
|
|
|
|
|
#include "rule.h"
|
|
|
|
|
#include "blank.h"
|
|
|
|
|
#include "symbol.h"
|
|
|
|
|
#include "choice.h"
|
|
|
|
|
#include "seq.h"
|
|
|
|
|
#include "string.h"
|
|
|
|
|
#include "pattern.h"
|
|
|
|
|
#include "character_set.h"
|
|
|
|
|
#include "repeat.h"
|
2013-12-19 23:05:54 -08:00
|
|
|
|
|
|
|
|
namespace tree_sitter {
|
2014-02-16 22:13:08 -08:00
|
|
|
using std::make_shared;
|
|
|
|
|
using std::string;
|
|
|
|
|
using std::set;
|
|
|
|
|
using std::vector;
|
|
|
|
|
|
2013-12-19 23:05:54 -08:00
|
|
|
namespace rules {
|
|
|
|
|
rule_ptr blank() {
|
|
|
|
|
return make_shared<Blank>();
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-11 13:15:44 -08:00
|
|
|
rule_ptr character(const set<CharacterRange> &ranges) {
|
2014-02-05 18:56:04 -08:00
|
|
|
return make_shared<CharacterSet>(ranges);
|
2013-12-19 23:05:54 -08:00
|
|
|
}
|
2014-02-05 18:56:04 -08:00
|
|
|
|
2014-02-11 13:15:44 -08:00
|
|
|
rule_ptr character(const set<CharacterRange> &ranges, bool sign) {
|
2014-02-16 22:13:08 -08:00
|
|
|
if (sign)
|
|
|
|
|
return character(ranges);
|
|
|
|
|
else
|
|
|
|
|
return CharacterSet(ranges).complement().copy();
|
2014-01-29 19:18:21 -08:00
|
|
|
}
|
2013-12-21 23:53:26 -08:00
|
|
|
|
2014-02-07 13:26:51 -08:00
|
|
|
rule_ptr choice(const vector<rule_ptr> &rules) {
|
2014-02-16 22:13:08 -08:00
|
|
|
return Choice::Build(rules);
|
2013-12-19 23:05:54 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rule_ptr pattern(const string &value) {
|
|
|
|
|
return make_shared<Pattern>(value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rule_ptr repeat(const rule_ptr content) {
|
|
|
|
|
return std::make_shared<Repeat>(content);
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-07 13:26:51 -08:00
|
|
|
rule_ptr seq(const vector<rule_ptr> &rules) {
|
2014-02-16 22:13:08 -08:00
|
|
|
return Seq::Build(rules);
|
2013-12-19 23:05:54 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rule_ptr str(const string &value) {
|
|
|
|
|
return make_shared<String>(value);
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-11 13:15:44 -08:00
|
|
|
rule_ptr sym(const string &name) {
|
2014-01-28 13:27:30 -08:00
|
|
|
return make_shared<Symbol>(name, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rule_ptr aux_sym(const string &name) {
|
|
|
|
|
return make_shared<Symbol>(name, true);
|
2014-01-03 01:02:24 -08:00
|
|
|
}
|
2013-12-19 23:05:54 -08:00
|
|
|
}
|
|
|
|
|
}
|