tree-sitter/examples/grammars/arithmetic.cc
Max Brunsfeld 545e575508 Revert "Remove the separator characters construct"
This reverts commit 5cd07648fd.

The separators construct is useful as an optimization. It turns out that
constructing a node for every chunk of whitespace in a document causes a
significant performance regression.

Conflicts:
	src/compiler/build_tables/build_lex_table.cc
	src/compiler/grammar.cc
	src/runtime/parser.c
2014-09-02 08:03:51 -07:00

31 lines
828 B
C++

#include "tree_sitter/compiler.h"
#include "helpers.h"
namespace tree_sitter_examples {
using tree_sitter::Grammar;
using namespace tree_sitter::rules;
extern const Grammar arithmetic({
{ "expression", choice({
sym("sum"),
sym("difference"),
sym("product"),
sym("quotient"),
sym("exponent"),
sym("group"),
sym("number"),
sym("variable") }) },
{ "sum", infix_op("+", "expression", 1) },
{ "difference", infix_op("-", "expression", 1) },
{ "product", infix_op("*", "expression", 2) },
{ "quotient", infix_op("/", "expression", 2) },
{ "exponent", infix_op("^", "expression", 3) },
{ "group", in_parens(err(sym("expression"))) },
{ "number", pattern("\\d+") },
{ "variable", pattern("\\a[\\w_]*") },
});
} // namespace tree_sitter_examples