tree-sitter/spec/test_grammars/arithmetic.cpp

38 lines
1.1 KiB
C++
Raw Normal View History

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