tree-sitter/spec/fixtures/grammars/arithmetic.cpp
2014-02-17 12:53:57 -08:00

35 lines
1,006 B
C++

#include "test_grammars.h"
#include "tree_sitter/compiler.h"
using namespace tree_sitter;
using namespace rules;
namespace test_grammars {
Grammar arithmetic() {
return Grammar("expression", {
{ "expression", choice({
seq({
sym("term"),
sym("plus"),
sym("term") }),
sym("term") }) },
{ "term", choice({
seq({
sym("factor"),
sym("times"),
sym("factor") }),
sym("factor") }) },
{ "factor", choice({
sym("variable"),
sym("number"),
seq({
str("("),
sym("expression"),
str(")") }) }) },
{ "plus", str("+") },
{ "times", str("*") },
{ "number", pattern("\\d+") },
{ "variable", pattern("[a-zA-Z]+") },
});
}
}