Move example grammars from fixtures -> examples dir
This commit is contained in:
parent
585f9f0054
commit
fd757c20d0
8 changed files with 60 additions and 68 deletions
53
spec/fixtures/grammars/json.cpp
vendored
53
spec/fixtures/grammars/json.cpp
vendored
|
|
@ -1,53 +0,0 @@
|
|||
#include "test_grammars.h"
|
||||
#include "tree_sitter/compiler.h"
|
||||
|
||||
using namespace tree_sitter;
|
||||
using namespace rules;
|
||||
|
||||
static rule_ptr comma_sep(const rule_ptr &rule) {
|
||||
return choice({
|
||||
seq({
|
||||
rule,
|
||||
repeat(seq({ aux_sym("comma"), rule })),
|
||||
}),
|
||||
blank(),
|
||||
});
|
||||
}
|
||||
|
||||
namespace test_grammars {
|
||||
Grammar json() {
|
||||
return Grammar("value", {
|
||||
{ "value", choice({
|
||||
sym("object"),
|
||||
sym("array"),
|
||||
sym("string"),
|
||||
sym("number") }) },
|
||||
{ "object", seq({
|
||||
aux_sym("left_brace"),
|
||||
comma_sep(seq({
|
||||
sym("string"),
|
||||
aux_sym("colon"),
|
||||
sym("value") })),
|
||||
aux_sym("right_brace"), }) },
|
||||
{ "array", seq({
|
||||
aux_sym("left_bracket"),
|
||||
comma_sep(sym("value")),
|
||||
aux_sym("right_bracket"), }) },
|
||||
{ "string", seq({
|
||||
character({ '"' }),
|
||||
repeat(choice({
|
||||
pattern("[^\"]"),
|
||||
str("\\\""),
|
||||
})),
|
||||
character({ '"' }) }) },
|
||||
{ "number", pattern("\\d+") }
|
||||
}, {
|
||||
{ "comma", str(",") },
|
||||
{ "colon", str(":") },
|
||||
{ "left_bracket", str("[") },
|
||||
{ "right_bracket", str("]") },
|
||||
{ "left_brace", str("{") },
|
||||
{ "right_brace", str("}") },
|
||||
});
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue