2013-11-12 18:37:02 -08:00
|
|
|
#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({
|
2013-11-12 18:37:02 -08:00
|
|
|
seq({
|
|
|
|
|
sym("term"),
|
|
|
|
|
sym("plus"),
|
|
|
|
|
sym("term") }),
|
2013-11-13 20:22:06 -08:00
|
|
|
sym("term") }) },
|
|
|
|
|
{ "term", choice({
|
2013-11-12 18:37:02 -08:00
|
|
|
seq({
|
|
|
|
|
sym("factor"),
|
|
|
|
|
sym("times"),
|
|
|
|
|
sym("factor") }),
|
2013-11-13 20:22:06 -08:00
|
|
|
sym("factor") }) },
|
|
|
|
|
{ "factor", choice({
|
2013-11-12 18:37:02 -08:00
|
|
|
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(")") }
|
2013-11-12 18:37:02 -08:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|