2014-01-23 13:44:49 -08:00
|
|
|
#include "test_grammars.h"
|
2013-11-12 18:37:02 -08:00
|
|
|
#include "rules.h"
|
|
|
|
|
|
|
|
|
|
using namespace tree_sitter;
|
2014-01-11 17:08:32 -08:00
|
|
|
using namespace rules;
|
2013-11-12 18:37:02 -08:00
|
|
|
|
|
|
|
|
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"),
|
2014-01-23 13:00:08 -08:00
|
|
|
sym("plus"),
|
2013-11-12 18:37:02 -08:00
|
|
|
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"),
|
2014-01-23 13:00:08 -08:00
|
|
|
sym("times"),
|
2013-11-12 18:37:02 -08:00
|
|
|
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({
|
2014-01-07 21:50:32 -08:00
|
|
|
str("("),
|
2013-11-12 18:37:02 -08:00
|
|
|
sym("expression"),
|
2014-01-07 21:50:32 -08:00
|
|
|
str(")") }) }) },
|
2014-01-23 13:00:08 -08:00
|
|
|
{ "plus", str("+") },
|
|
|
|
|
{ "times", str("*") },
|
2013-11-13 20:22:06 -08:00
|
|
|
{ "number", pattern("\\d+") },
|
|
|
|
|
{ "variable", pattern("\\w+") },
|
2013-11-12 18:37:02 -08:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|