2014-03-24 07:19:31 -07:00
|
|
|
#include "tree_sitter/compiler.h"
|
2014-04-27 21:45:05 -07:00
|
|
|
#include "helpers.h"
|
2014-03-24 07:19:31 -07:00
|
|
|
|
2014-03-28 13:51:32 -07:00
|
|
|
namespace tree_sitter_examples {
|
|
|
|
|
using tree_sitter::Grammar;
|
|
|
|
|
using namespace tree_sitter::rules;
|
2014-03-24 09:14:29 -07:00
|
|
|
|
2014-03-28 13:51:32 -07:00
|
|
|
extern const Grammar json({
|
|
|
|
|
{ "value", choice({
|
|
|
|
|
sym("object"),
|
|
|
|
|
sym("array"),
|
|
|
|
|
sym("string"),
|
|
|
|
|
sym("number"),
|
|
|
|
|
sym("true"),
|
|
|
|
|
sym("false"),
|
|
|
|
|
sym("null"), }) },
|
2014-04-27 21:45:05 -07:00
|
|
|
{ "object", in_braces(comma_sep(err(seq({
|
|
|
|
|
sym("string"),
|
|
|
|
|
str(":"),
|
|
|
|
|
sym("value") })))) },
|
|
|
|
|
{ "array", in_brackets(comma_sep(err(sym("value")))) },
|
2014-05-19 20:54:59 -07:00
|
|
|
{ "string", pattern("\"([^\"]|\\\\\")*\"") },
|
2014-04-24 13:02:01 -07:00
|
|
|
{ "number", pattern("\\d+(\\.\\d+)?") },
|
2014-05-01 19:58:32 -07:00
|
|
|
{ "null", keyword("null") },
|
|
|
|
|
{ "true", keyword("true") },
|
|
|
|
|
{ "false", keyword("false") },
|
2014-03-28 13:51:32 -07:00
|
|
|
});
|
2014-03-24 07:19:31 -07:00
|
|
|
}
|