tree-sitter/spec/fixtures/grammars/arithmetic.cpp
2014-01-07 21:50:32 -08:00

33 lines
906 B
C++

#include "arithmetic.h"
#include "rules.h"
using namespace tree_sitter;
using namespace tree_sitter::rules;
namespace test_grammars {
Grammar arithmetic() {
return Grammar({
{ "expression", choice({
seq({
sym("term"),
str("+"),
sym("term") }),
sym("term") }) },
{ "term", choice({
seq({
sym("factor"),
str("*"),
sym("factor") }),
sym("factor") }) },
{ "factor", choice({
sym("variable"),
sym("number"),
seq({
str("("),
sym("expression"),
str(")") }) }) },
{ "number", pattern("\\d+") },
{ "variable", pattern("\\w+") },
});
}
}