tree-sitter/spec/fixtures/grammars/arithmetic.cpp

36 lines
972 B
C++
Raw Normal View History

#include "test_grammars.h"
#include "rules.h"
using namespace tree_sitter;
2014-01-11 17:08:32 -08:00
using namespace rules;
namespace test_grammars {
Grammar arithmetic() {
return Grammar({
2013-11-13 20:22:06 -08:00
{ "expression", choice({
seq({
sym("term"),
2014-01-23 13:00:08 -08:00
sym("plus"),
sym("term") }),
2013-11-13 20:22:06 -08:00
sym("term") }) },
{ "term", choice({
seq({
sym("factor"),
2014-01-23 13:00:08 -08:00
sym("times"),
sym("factor") }),
2013-11-13 20:22:06 -08:00
sym("factor") }) },
{ "factor", choice({
sym("variable"),
sym("number"),
seq({
2014-01-07 21:50:32 -08:00
str("("),
sym("expression"),
2014-01-07 21:50:32 -08:00
str(")") }) }) },
2014-01-23 13:00:08 -08:00
{ "plus", str("+") },
{ "times", str("*") },
2013-11-13 20:22:06 -08:00
{ "number", pattern("\\d+") },
{ "variable", pattern("\\w+") },
});
}
}