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

34 lines
893 B
C++
Raw Normal View History

#include "arithmetic.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-07 21:50:32 -08:00
str("+"),
sym("term") }),
2013-11-13 20:22:06 -08:00
sym("term") }) },
{ "term", choice({
seq({
sym("factor"),
2014-01-07 21:50:32 -08:00
str("*"),
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(")") }) }) },
2013-11-13 20:22:06 -08:00
{ "number", pattern("\\d+") },
{ "variable", pattern("\\w+") },
});
}
}