mirror of https://github.com/Wilfred/difftastic/
Add 'vendor/tree-sitter-json/' from commit '65bceef69c3b0f24c0b19ce67d79f57c96e90fcb'
git-subtree-dir: vendor/tree-sitter-json git-subtree-mainline:ida_star59f80c20ddgit-subtree-split:65bceef69c
commit
e31b5b4925
@ -0,0 +1 @@
|
||||
/src/** linguist-vendored
|
||||
@ -0,0 +1,19 @@
|
||||
name: Build/test
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- "**"
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
fail-fast: true
|
||||
matrix:
|
||||
os: [macos-latest, ubuntu-latest, windows-latest]
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: 14
|
||||
- run: npm install
|
||||
- run: npm test
|
||||
@ -0,0 +1,6 @@
|
||||
node_modules
|
||||
build
|
||||
target
|
||||
*.log
|
||||
package-lock.json
|
||||
Cargo.lock
|
||||
@ -0,0 +1,4 @@
|
||||
corpus
|
||||
build
|
||||
script
|
||||
target
|
||||
@ -0,0 +1,27 @@
|
||||
[package]
|
||||
name = "tree-sitter-json"
|
||||
description = "json grammar for the tree-sitter parsing library"
|
||||
version = "0.19.0"
|
||||
keywords = ["incremental", "parsing", "json"]
|
||||
categories = ["parsing", "text-editors"]
|
||||
repository = "https://github.com/tree-sitter/tree-sitter-javascript"
|
||||
edition = "2018"
|
||||
license = "MIT"
|
||||
authors = ["Max Brunsfeld <maxbrunsfeld@gmail.com>"]
|
||||
|
||||
build = "bindings/rust/build.rs"
|
||||
include = [
|
||||
"bindings/rust/*",
|
||||
"grammar.js",
|
||||
"queries/*",
|
||||
"src/*",
|
||||
]
|
||||
|
||||
[lib]
|
||||
path = "bindings/rust/lib.rs"
|
||||
|
||||
[dependencies]
|
||||
tree-sitter = "0.19"
|
||||
|
||||
[build-dependencies]
|
||||
cc = "1.0"
|
||||
@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Max Brunsfeld
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@ -0,0 +1,6 @@
|
||||
tree-sitter-json
|
||||
===========================
|
||||
|
||||
[](https://github.com/tree-sitter/tree-sitter-json/actions/workflows/ci.yml)
|
||||
|
||||
JSON grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter)
|
||||
@ -0,0 +1,18 @@
|
||||
{
|
||||
"targets": [
|
||||
{
|
||||
"target_name": "tree_sitter_json_binding",
|
||||
"include_dirs": [
|
||||
"<!(node -e \"require('nan')\")",
|
||||
"src"
|
||||
],
|
||||
"sources": [
|
||||
"src/parser.c",
|
||||
"bindings/node/binding.cc"
|
||||
],
|
||||
"cflags_c": [
|
||||
"-std=c99",
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -0,0 +1,28 @@
|
||||
#include "tree_sitter/parser.h"
|
||||
#include <node.h>
|
||||
#include "nan.h"
|
||||
|
||||
using namespace v8;
|
||||
|
||||
extern "C" TSLanguage * tree_sitter_json();
|
||||
|
||||
namespace {
|
||||
|
||||
NAN_METHOD(New) {}
|
||||
|
||||
void Init(Local<Object> exports, Local<Object> module) {
|
||||
Local<FunctionTemplate> tpl = Nan::New<FunctionTemplate>(New);
|
||||
tpl->SetClassName(Nan::New("Language").ToLocalChecked());
|
||||
tpl->InstanceTemplate()->SetInternalFieldCount(1);
|
||||
|
||||
Local<Function> constructor = Nan::GetFunction(tpl).ToLocalChecked();
|
||||
Local<Object> instance = constructor->NewInstance(Nan::GetCurrentContext()).ToLocalChecked();
|
||||
Nan::SetInternalFieldPointer(instance, 0, tree_sitter_json());
|
||||
|
||||
Nan::Set(instance, Nan::New("name").ToLocalChecked(), Nan::New("json").ToLocalChecked());
|
||||
Nan::Set(module, Nan::New("exports").ToLocalChecked(), instance);
|
||||
}
|
||||
|
||||
NODE_MODULE(tree_sitter_json_binding, Init)
|
||||
|
||||
} // namespace
|
||||
@ -0,0 +1,19 @@
|
||||
try {
|
||||
module.exports = require("../../build/Release/tree_sitter_json_binding");
|
||||
} catch (error1) {
|
||||
if (error1.code !== 'MODULE_NOT_FOUND') {
|
||||
throw error1;
|
||||
}
|
||||
try {
|
||||
module.exports = require("../../build/Debug/tree_sitter_json_binding");
|
||||
} catch (error2) {
|
||||
if (error2.code !== 'MODULE_NOT_FOUND') {
|
||||
throw error2;
|
||||
}
|
||||
throw error1
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
module.exports.nodeTypeInfo = require("../../src/node-types.json");
|
||||
} catch (_) {}
|
||||
@ -0,0 +1,40 @@
|
||||
fn main() {
|
||||
let src_dir = std::path::Path::new("src");
|
||||
|
||||
let mut c_config = cc::Build::new();
|
||||
c_config.include(&src_dir);
|
||||
c_config
|
||||
.flag_if_supported("-Wno-unused-parameter")
|
||||
.flag_if_supported("-Wno-unused-but-set-variable")
|
||||
.flag_if_supported("-Wno-trigraphs");
|
||||
let parser_path = src_dir.join("parser.c");
|
||||
c_config.file(&parser_path);
|
||||
|
||||
// If your language uses an external scanner written in C,
|
||||
// then include this block of code:
|
||||
|
||||
/*
|
||||
let scanner_path = src_dir.join("scanner.c");
|
||||
c_config.file(&scanner_path);
|
||||
println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap());
|
||||
*/
|
||||
|
||||
c_config.compile("parser");
|
||||
println!("cargo:rerun-if-changed={}", parser_path.to_str().unwrap());
|
||||
|
||||
// If your language uses an external scanner written in C++,
|
||||
// then include this block of code:
|
||||
|
||||
/*
|
||||
let mut cpp_config = cc::Build::new();
|
||||
cpp_config.cpp(true);
|
||||
cpp_config.include(&src_dir);
|
||||
cpp_config
|
||||
.flag_if_supported("-Wno-unused-parameter")
|
||||
.flag_if_supported("-Wno-unused-but-set-variable");
|
||||
let scanner_path = src_dir.join("scanner.cc");
|
||||
cpp_config.file(&scanner_path);
|
||||
cpp_config.compile("scanner");
|
||||
println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap());
|
||||
*/
|
||||
}
|
||||
@ -0,0 +1,52 @@
|
||||
//! This crate provides json language support for the [tree-sitter][] parsing library.
|
||||
//!
|
||||
//! Typically, you will use the [language][language func] function to add this language to a
|
||||
//! tree-sitter [Parser][], and then use the parser to parse some code:
|
||||
//!
|
||||
//! ```
|
||||
//! let code = "";
|
||||
//! let mut parser = tree_sitter::Parser::new();
|
||||
//! parser.set_language(tree_sitter_json::language()).expect("Error loading json grammar");
|
||||
//! let tree = parser.parse(code, None).unwrap();
|
||||
//! ```
|
||||
//!
|
||||
//! [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
|
||||
//! [language func]: fn.language.html
|
||||
//! [Parser]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Parser.html
|
||||
//! [tree-sitter]: https://tree-sitter.github.io/
|
||||
|
||||
use tree_sitter::Language;
|
||||
|
||||
extern "C" {
|
||||
fn tree_sitter_json() -> Language;
|
||||
}
|
||||
|
||||
/// Get the tree-sitter [Language][] for this grammar.
|
||||
///
|
||||
/// [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
|
||||
pub fn language() -> Language {
|
||||
unsafe { tree_sitter_json() }
|
||||
}
|
||||
|
||||
/// The content of the [`node-types.json`][] file for this grammar.
|
||||
///
|
||||
/// [`node-types.json`]: https://tree-sitter.github.io/tree-sitter/using-parsers#static-node-types
|
||||
pub const NODE_TYPES: &'static str = include_str!("../../src/node-types.json");
|
||||
|
||||
// Uncomment these to include any queries that this grammar contains
|
||||
|
||||
// pub const HIGHLIGHTS_QUERY: &'static str = include_str!("../../queries/highlights.scm");
|
||||
// pub const INJECTIONS_QUERY: &'static str = include_str!("../../queries/injections.scm");
|
||||
// pub const LOCALS_QUERY: &'static str = include_str!("../../queries/locals.scm");
|
||||
// pub const TAGS_QUERY: &'static str = include_str!("../../queries/tags.scm");
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
fn test_can_load_grammar() {
|
||||
let mut parser = tree_sitter::Parser::new();
|
||||
parser
|
||||
.set_language(super::language())
|
||||
.expect("Error loading json language");
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,66 @@
|
||||
===================
|
||||
Arrays
|
||||
===================
|
||||
|
||||
[
|
||||
345,
|
||||
10.1,
|
||||
10,
|
||||
-10,
|
||||
null,
|
||||
true,
|
||||
false,
|
||||
{ "stuff": "good" }
|
||||
]
|
||||
|
||||
---
|
||||
|
||||
(document (array
|
||||
(number)
|
||||
(number)
|
||||
(number)
|
||||
(number)
|
||||
(null)
|
||||
(true)
|
||||
(false)
|
||||
(object (pair (string (string_content)) (string (string_content))))))
|
||||
|
||||
=====================
|
||||
String content
|
||||
=====================
|
||||
|
||||
[
|
||||
"",
|
||||
"abc",
|
||||
"def\n",
|
||||
"ghi\t"
|
||||
]
|
||||
|
||||
----
|
||||
|
||||
(document
|
||||
(array
|
||||
(string)
|
||||
(string (string_content))
|
||||
(string (string_content (escape_sequence)))
|
||||
(string (string_content (escape_sequence)))))
|
||||
|
||||
================================
|
||||
Top-level numbers
|
||||
================================
|
||||
|
||||
-1
|
||||
|
||||
---
|
||||
|
||||
(document (number))
|
||||
|
||||
================================
|
||||
Top-level null
|
||||
================================
|
||||
|
||||
null
|
||||
|
||||
---
|
||||
|
||||
(document (null))
|
||||
@ -0,0 +1,104 @@
|
||||
module.exports = grammar({
|
||||
name: 'json',
|
||||
|
||||
extras: $ => [
|
||||
/\s/
|
||||
],
|
||||
|
||||
supertypes: $ => [
|
||||
$._value
|
||||
],
|
||||
|
||||
rules: {
|
||||
document: $ => $._value,
|
||||
|
||||
_value: $ => choice(
|
||||
$.object,
|
||||
$.array,
|
||||
$.number,
|
||||
$.string,
|
||||
$.true,
|
||||
$.false,
|
||||
$.null
|
||||
),
|
||||
|
||||
object: $ => seq(
|
||||
"{", commaSep($.pair), "}"
|
||||
),
|
||||
|
||||
pair: $ => seq(
|
||||
field("key", choice($.string, $.number)),
|
||||
":",
|
||||
field("value", $._value)
|
||||
),
|
||||
|
||||
array: $ => seq(
|
||||
"[", commaSep($._value), "]"
|
||||
),
|
||||
|
||||
string: $ => choice(
|
||||
seq('"', '"'),
|
||||
seq('"', $.string_content, '"')
|
||||
),
|
||||
|
||||
string_content: $ => repeat1(choice(
|
||||
token.immediate(/[^\\"\n]+/),
|
||||
$.escape_sequence
|
||||
)),
|
||||
|
||||
escape_sequence: $ => token.immediate(seq(
|
||||
'\\',
|
||||
/(\"|\\|\/|b|n|r|t|u)/
|
||||
)),
|
||||
|
||||
number: $ => {
|
||||
const hex_literal = seq(
|
||||
choice('0x', '0X'),
|
||||
/[\da-fA-F]+/
|
||||
)
|
||||
|
||||
const decimal_digits = /\d+/
|
||||
const signed_integer = seq(optional(choice('-','+')), decimal_digits)
|
||||
const exponent_part = seq(choice('e', 'E'), signed_integer)
|
||||
|
||||
const binary_literal = seq(choice('0b', '0B'), /[0-1]+/)
|
||||
|
||||
const octal_literal = seq(choice('0o', '0O'), /[0-7]+/)
|
||||
|
||||
const decimal_integer_literal = seq(
|
||||
optional(choice('-','+')),
|
||||
choice(
|
||||
'0',
|
||||
seq(/[1-9]/, optional(decimal_digits))
|
||||
)
|
||||
)
|
||||
|
||||
const decimal_literal = choice(
|
||||
seq(decimal_integer_literal, '.', optional(decimal_digits), optional(exponent_part)),
|
||||
seq('.', decimal_digits, optional(exponent_part)),
|
||||
seq(decimal_integer_literal, optional(exponent_part))
|
||||
)
|
||||
|
||||
return token(choice(
|
||||
hex_literal,
|
||||
decimal_literal,
|
||||
binary_literal,
|
||||
octal_literal
|
||||
))
|
||||
},
|
||||
|
||||
true: $ => "true",
|
||||
|
||||
false: $ => "false",
|
||||
|
||||
null: $ => "null"
|
||||
}
|
||||
});
|
||||
|
||||
function commaSep1 (rule) {
|
||||
return seq(rule, repeat(seq(",", rule)))
|
||||
}
|
||||
|
||||
function commaSep (rule) {
|
||||
return optional(commaSep1(rule))
|
||||
}
|
||||
@ -0,0 +1,30 @@
|
||||
{
|
||||
"name": "tree-sitter-json",
|
||||
"version": "0.19.0",
|
||||
"description": "JSON grammar for tree-sitter",
|
||||
"main": "bindings/node",
|
||||
"keywords": [
|
||||
"parser",
|
||||
"json"
|
||||
],
|
||||
"author": "Max Brunsfeld",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"nan": "^2.14.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"tree-sitter-cli": "^0.19.1"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tree-sitter generate && node-gyp build",
|
||||
"test": "tree-sitter test"
|
||||
},
|
||||
"tree-sitter": [
|
||||
{
|
||||
"scope": "source.json",
|
||||
"file-types": [
|
||||
"json"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
(pair
|
||||
key: (_) @keyword)
|
||||
|
||||
(string) @string
|
||||
|
||||
(object
|
||||
"{" @escape
|
||||
(_)
|
||||
"}" @escape)
|
||||
@ -0,0 +1,662 @@
|
||||
{
|
||||
"name": "json",
|
||||
"rules": {
|
||||
"document": {
|
||||
"type": "SYMBOL",
|
||||
"name": "_value"
|
||||
},
|
||||
"_value": {
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "object"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "array"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "number"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "string"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "true"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "false"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "null"
|
||||
}
|
||||
]
|
||||
},
|
||||
"object": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "{"
|
||||
},
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "pair"
|
||||
},
|
||||
{
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": ","
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "pair"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "}"
|
||||
}
|
||||
]
|
||||
},
|
||||
"pair": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "FIELD",
|
||||
"name": "key",
|
||||
"content": {
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "string"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "number"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": ":"
|
||||
},
|
||||
{
|
||||
"type": "FIELD",
|
||||
"name": "value",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "_value"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"array": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "["
|
||||
},
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_value"
|
||||
},
|
||||
{
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": ","
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_value"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "]"
|
||||
}
|
||||
]
|
||||
},
|
||||
"string": {
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "\""
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "\""
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "\""
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "string_content"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "\""
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"string_content": {
|
||||
"type": "REPEAT1",
|
||||
"content": {
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "IMMEDIATE_TOKEN",
|
||||
"content": {
|
||||
"type": "PATTERN",
|
||||
"value": "[^\\\\\"\\n]+"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "escape_sequence"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"escape_sequence": {
|
||||
"type": "IMMEDIATE_TOKEN",
|
||||
"content": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "\\"
|
||||
},
|
||||
{
|
||||
"type": "PATTERN",
|
||||
"value": "(\\\"|\\\\|\\/|b|n|r|t|u)"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"number": {
|
||||
"type": "TOKEN",
|
||||
"content": {
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "0x"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "0X"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "PATTERN",
|
||||
"value": "[\\da-fA-F]+"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "-"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "+"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "0"
|
||||
},
|
||||
{
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "PATTERN",
|
||||
"value": "[1-9]"
|
||||
},
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "PATTERN",
|
||||
"value": "\\d+"
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "."
|
||||
},
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "PATTERN",
|
||||
"value": "\\d+"
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "e"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "E"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "-"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "+"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "PATTERN",
|
||||
"value": "\\d+"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "."
|
||||
},
|
||||
{
|
||||
"type": "PATTERN",
|
||||
"value": "\\d+"
|
||||
},
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "e"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "E"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "-"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "+"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "PATTERN",
|
||||
"value": "\\d+"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "-"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "+"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "0"
|
||||
},
|
||||
{
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "PATTERN",
|
||||
"value": "[1-9]"
|
||||
},
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "PATTERN",
|
||||
"value": "\\d+"
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "e"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "E"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "-"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "+"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "PATTERN",
|
||||
"value": "\\d+"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "0b"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "0B"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "PATTERN",
|
||||
"value": "[0-1]+"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "0o"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "0O"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "PATTERN",
|
||||
"value": "[0-7]+"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"true": {
|
||||
"type": "STRING",
|
||||
"value": "true"
|
||||
},
|
||||
"false": {
|
||||
"type": "STRING",
|
||||
"value": "false"
|
||||
},
|
||||
"null": {
|
||||
"type": "STRING",
|
||||
"value": "null"
|
||||
}
|
||||
},
|
||||
"extras": [
|
||||
{
|
||||
"type": "PATTERN",
|
||||
"value": "\\s"
|
||||
}
|
||||
],
|
||||
"conflicts": [],
|
||||
"precedences": [],
|
||||
"externals": [],
|
||||
"inline": [],
|
||||
"supertypes": [
|
||||
"_value"
|
||||
]
|
||||
}
|
||||
|
||||
@ -0,0 +1,189 @@
|
||||
[
|
||||
{
|
||||
"type": "_value",
|
||||
"named": true,
|
||||
"subtypes": [
|
||||
{
|
||||
"type": "array",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "false",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "null",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "number",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "true",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "array",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": true,
|
||||
"required": false,
|
||||
"types": [
|
||||
{
|
||||
"type": "_value",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "document",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "_value",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": true,
|
||||
"required": false,
|
||||
"types": [
|
||||
{
|
||||
"type": "pair",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "pair",
|
||||
"named": true,
|
||||
"fields": {
|
||||
"key": {
|
||||
"multiple": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "number",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"value": {
|
||||
"multiple": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "_value",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": false,
|
||||
"required": false,
|
||||
"types": [
|
||||
{
|
||||
"type": "string_content",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "string_content",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": true,
|
||||
"required": false,
|
||||
"types": [
|
||||
{
|
||||
"type": "escape_sequence",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "\"",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": ",",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": ":",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "[",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "]",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "escape_sequence",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "false",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "null",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "number",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "true",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "{",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "}",
|
||||
"named": false
|
||||
}
|
||||
]
|
||||
@ -0,0 +1,875 @@
|
||||
#include <tree_sitter/parser.h>
|
||||
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
|
||||
#endif
|
||||
|
||||
#define LANGUAGE_VERSION 13
|
||||
#define STATE_COUNT 32
|
||||
#define LARGE_STATE_COUNT 2
|
||||
#define SYMBOL_COUNT 24
|
||||
#define ALIAS_COUNT 0
|
||||
#define TOKEN_COUNT 14
|
||||
#define EXTERNAL_TOKEN_COUNT 0
|
||||
#define FIELD_COUNT 2
|
||||
#define MAX_ALIAS_SEQUENCE_LENGTH 4
|
||||
#define PRODUCTION_ID_COUNT 2
|
||||
|
||||
enum {
|
||||
anon_sym_LBRACE = 1,
|
||||
anon_sym_COMMA = 2,
|
||||
anon_sym_RBRACE = 3,
|
||||
anon_sym_COLON = 4,
|
||||
anon_sym_LBRACK = 5,
|
||||
anon_sym_RBRACK = 6,
|
||||
anon_sym_DQUOTE = 7,
|
||||
aux_sym_string_content_token1 = 8,
|
||||
sym_escape_sequence = 9,
|
||||
sym_number = 10,
|
||||
sym_true = 11,
|
||||
sym_false = 12,
|
||||
sym_null = 13,
|
||||
sym_document = 14,
|
||||
sym__value = 15,
|
||||
sym_object = 16,
|
||||
sym_pair = 17,
|
||||
sym_array = 18,
|
||||
sym_string = 19,
|
||||
sym_string_content = 20,
|
||||
aux_sym_object_repeat1 = 21,
|
||||
aux_sym_array_repeat1 = 22,
|
||||
aux_sym_string_content_repeat1 = 23,
|
||||
};
|
||||
|
||||
static const char *ts_symbol_names[] = {
|
||||
[ts_builtin_sym_end] = "end",
|
||||
[anon_sym_LBRACE] = "{",
|
||||
[anon_sym_COMMA] = ",",
|
||||
[anon_sym_RBRACE] = "}",
|
||||
[anon_sym_COLON] = ":",
|
||||
[anon_sym_LBRACK] = "[",
|
||||
[anon_sym_RBRACK] = "]",
|
||||
[anon_sym_DQUOTE] = "\"",
|
||||
[aux_sym_string_content_token1] = "string_content_token1",
|
||||
[sym_escape_sequence] = "escape_sequence",
|
||||
[sym_number] = "number",
|
||||
[sym_true] = "true",
|
||||
[sym_false] = "false",
|
||||
[sym_null] = "null",
|
||||
[sym_document] = "document",
|
||||
[sym__value] = "_value",
|
||||
[sym_object] = "object",
|
||||
[sym_pair] = "pair",
|
||||
[sym_array] = "array",
|
||||
[sym_string] = "string",
|
||||
[sym_string_content] = "string_content",
|
||||
[aux_sym_object_repeat1] = "object_repeat1",
|
||||
[aux_sym_array_repeat1] = "array_repeat1",
|
||||
[aux_sym_string_content_repeat1] = "string_content_repeat1",
|
||||
};
|
||||
|
||||
static TSSymbol ts_symbol_map[] = {
|
||||
[ts_builtin_sym_end] = ts_builtin_sym_end,
|
||||
[anon_sym_LBRACE] = anon_sym_LBRACE,
|
||||
[anon_sym_COMMA] = anon_sym_COMMA,
|
||||
[anon_sym_RBRACE] = anon_sym_RBRACE,
|
||||
[anon_sym_COLON] = anon_sym_COLON,
|
||||
[anon_sym_LBRACK] = anon_sym_LBRACK,
|
||||
[anon_sym_RBRACK] = anon_sym_RBRACK,
|
||||
[anon_sym_DQUOTE] = anon_sym_DQUOTE,
|
||||
[aux_sym_string_content_token1] = aux_sym_string_content_token1,
|
||||
[sym_escape_sequence] = sym_escape_sequence,
|
||||
[sym_number] = sym_number,
|
||||
[sym_true] = sym_true,
|
||||
[sym_false] = sym_false,
|
||||
[sym_null] = sym_null,
|
||||
[sym_document] = sym_document,
|
||||
[sym__value] = sym__value,
|
||||
[sym_object] = sym_object,
|
||||
[sym_pair] = sym_pair,
|
||||
[sym_array] = sym_array,
|
||||
[sym_string] = sym_string,
|
||||
[sym_string_content] = sym_string_content,
|
||||
[aux_sym_object_repeat1] = aux_sym_object_repeat1,
|
||||
[aux_sym_array_repeat1] = aux_sym_array_repeat1,
|
||||
[aux_sym_string_content_repeat1] = aux_sym_string_content_repeat1,
|
||||
};
|
||||
|
||||
static const TSSymbolMetadata ts_symbol_metadata[] = {
|
||||
[ts_builtin_sym_end] = {
|
||||
.visible = false,
|
||||
.named = true,
|
||||
},
|
||||
[anon_sym_LBRACE] = {
|
||||
.visible = true,
|
||||
.named = false,
|
||||
},
|
||||
[anon_sym_COMMA] = {
|
||||
.visible = true,
|
||||
.named = false,
|
||||
},
|
||||
[anon_sym_RBRACE] = {
|
||||
.visible = true,
|
||||
.named = false,
|
||||
},
|
||||
[anon_sym_COLON] = {
|
||||
.visible = true,
|
||||
.named = false,
|
||||
},
|
||||
[anon_sym_LBRACK] = {
|
||||
.visible = true,
|
||||
.named = false,
|
||||
},
|
||||
[anon_sym_RBRACK] = {
|
||||
.visible = true,
|
||||
.named = false,
|
||||
},
|
||||
[anon_sym_DQUOTE] = {
|
||||
.visible = true,
|
||||
.named = false,
|
||||
},
|
||||
[aux_sym_string_content_token1] = {
|
||||
.visible = false,
|
||||
.named = false,
|
||||
},
|
||||
[sym_escape_sequence] = {
|
||||
.visible = true,
|
||||
.named = true,
|
||||
},
|
||||
[sym_number] = {
|
||||
.visible = true,
|
||||
.named = true,
|
||||
},
|
||||
[sym_true] = {
|
||||
.visible = true,
|
||||
.named = true,
|
||||
},
|
||||
[sym_false] = {
|
||||
.visible = true,
|
||||
.named = true,
|
||||
},
|
||||
[sym_null] = {
|
||||
.visible = true,
|
||||
.named = true,
|
||||
},
|
||||
[sym_document] = {
|
||||
.visible = true,
|
||||
.named = true,
|
||||
},
|
||||
[sym__value] = {
|
||||
.visible = false,
|
||||
.named = true,
|
||||
.supertype = true,
|
||||
},
|
||||
[sym_object] = {
|
||||
.visible = true,
|
||||
.named = true,
|
||||
},
|
||||
[sym_pair] = {
|
||||
.visible = true,
|
||||
.named = true,
|
||||
},
|
||||
[sym_array] = {
|
||||
.visible = true,
|
||||
.named = true,
|
||||
},
|
||||
[sym_string] = {
|
||||
.visible = true,
|
||||
.named = true,
|
||||
},
|
||||
[sym_string_content] = {
|
||||
.visible = true,
|
||||
.named = true,
|
||||
},
|
||||
[aux_sym_object_repeat1] = {
|
||||
.visible = false,
|
||||
.named = false,
|
||||
},
|
||||
[aux_sym_array_repeat1] = {
|
||||
.visible = false,
|
||||
.named = false,
|
||||
},
|
||||
[aux_sym_string_content_repeat1] = {
|
||||
.visible = false,
|
||||
.named = false,
|
||||
},
|
||||
};
|
||||
|
||||
enum {
|
||||
field_key = 1,
|
||||
field_value = 2,
|
||||
};
|
||||
|
||||
static const char *ts_field_names[] = {
|
||||
[0] = NULL,
|
||||
[field_key] = "key",
|
||||
[field_value] = "value",
|
||||
};
|
||||
|
||||
static const TSFieldMapSlice ts_field_map_slices[PRODUCTION_ID_COUNT] = {
|
||||
[1] = {.index = 0, .length = 2},
|
||||
};
|
||||
|
||||
static const TSFieldMapEntry ts_field_map_entries[] = {
|
||||
[0] =
|
||||
{field_key, 0},
|
||||
{field_value, 2},
|
||||
};
|
||||
|
||||
static TSSymbol ts_alias_sequences[PRODUCTION_ID_COUNT][MAX_ALIAS_SEQUENCE_LENGTH] = {
|
||||
[0] = {0},
|
||||
};
|
||||
|
||||
static uint16_t ts_non_terminal_alias_map[] = {
|
||||
0,
|
||||
};
|
||||
|
||||
static bool ts_lex(TSLexer *lexer, TSStateId state) {
|
||||
START_LEXER();
|
||||
eof = lexer->eof(lexer);
|
||||
switch (state) {
|
||||
case 0:
|
||||
if (eof) ADVANCE(22);
|
||||
if (lookahead == '"') ADVANCE(29);
|
||||
if (lookahead == '+' ||
|
||||
lookahead == '-') ADVANCE(3);
|
||||
if (lookahead == ',') ADVANCE(24);
|
||||
if (lookahead == '.') ADVANCE(18);
|
||||
if (lookahead == '0') ADVANCE(33);
|
||||
if (lookahead == ':') ADVANCE(26);
|
||||
if (lookahead == '[') ADVANCE(27);
|
||||
if (lookahead == '\\') ADVANCE(16);
|
||||
if (lookahead == ']') ADVANCE(28);
|
||||
if (lookahead == 'f') ADVANCE(4);
|
||||
if (lookahead == 'n') ADVANCE(13);
|
||||
if (lookahead == 't') ADVANCE(10);
|
||||
if (lookahead == '{') ADVANCE(23);
|
||||
if (lookahead == '}') ADVANCE(25);
|
||||
if (lookahead == '\t' ||
|
||||
lookahead == '\n' ||
|
||||
lookahead == '\r' ||
|
||||
lookahead == ' ') SKIP(21)
|
||||
if (('1' <= lookahead && lookahead <= '9')) ADVANCE(35);
|
||||
END_STATE();
|
||||
case 1:
|
||||
if (lookahead == '\n') SKIP(2)
|
||||
if (lookahead == '"') ADVANCE(29);
|
||||
if (lookahead == '\\') ADVANCE(16);
|
||||
if (lookahead == '\t' ||
|
||||
lookahead == '\r' ||
|
||||
lookahead == ' ') ADVANCE(30);
|
||||
if (lookahead != 0) ADVANCE(31);
|
||||
END_STATE();
|
||||
case 2:
|
||||
if (lookahead == '"') ADVANCE(29);
|
||||
if (lookahead == '\t' ||
|
||||
lookahead == '\n' ||
|
||||
lookahead == '\r' ||
|
||||
lookahead == ' ') SKIP(2)
|
||||
END_STATE();
|
||||
case 3:
|
||||
if (lookahead == '0') ADVANCE(34);
|
||||
if (('1' <= lookahead && lookahead <= '9')) ADVANCE(35);
|
||||
END_STATE();
|
||||
case 4:
|
||||
if (lookahead == 'a') ADVANCE(7);
|
||||
END_STATE();
|
||||
case 5:
|
||||
if (lookahead == 'e') ADVANCE(41);
|
||||
END_STATE();
|
||||
case 6:
|
||||
if (lookahead == 'e') ADVANCE(42);
|
||||
END_STATE();
|
||||
case 7:
|
||||
if (lookahead == 'l') ADVANCE(11);
|
||||
END_STATE();
|
||||
case 8:
|
||||
if (lookahead == 'l') ADVANCE(43);
|
||||
END_STATE();
|
||||
case 9:
|
||||
if (lookahead == 'l') ADVANCE(8);
|
||||
END_STATE();
|
||||
case 10:
|
||||
if (lookahead == 'r') ADVANCE(12);
|
||||
END_STATE();
|
||||
case 11:
|
||||
if (lookahead == 's') ADVANCE(6);
|
||||
END_STATE();
|
||||
case 12:
|
||||
if (lookahead == 'u') ADVANCE(5);
|
||||
END_STATE();
|
||||
case 13:
|
||||
if (lookahead == 'u') ADVANCE(9);
|
||||
END_STATE();
|
||||
case 14:
|
||||
if (lookahead == '+' ||
|
||||
lookahead == '-') ADVANCE(19);
|
||||
if (('0' <= lookahead && lookahead <= '9')) ADVANCE(39);
|
||||
END_STATE();
|
||||
case 15:
|
||||
if (lookahead == '0' ||
|
||||
lookahead == '1') ADVANCE(37);
|
||||
END_STATE();
|
||||
case 16:
|
||||
if (lookahead == '"' ||
|
||||
lookahead == '/' ||
|
||||
lookahead == '\\' ||
|
||||
lookahead == 'b' ||
|
||||
lookahead == 'n' ||
|
||||
lookahead == 'r' ||
|
||||
lookahead == 't' ||
|
||||
lookahead == 'u') ADVANCE(32);
|
||||
END_STATE();
|
||||
case 17:
|
||||
if (('0' <= lookahead && lookahead <= '7')) ADVANCE(38);
|
||||
END_STATE();
|
||||
case 18:
|
||||
if (('0' <= lookahead && lookahead <= '9')) ADVANCE(36);
|
||||
END_STATE();
|
||||
case 19:
|
||||
if (('0' <= lookahead && lookahead <= '9')) ADVANCE(39);
|
||||
END_STATE();
|
||||
case 20:
|
||||
if (('0' <= lookahead && lookahead <= '9') ||
|
||||
('A' <= lookahead && lookahead <= 'F') ||
|
||||
('a' <= lookahead && lookahead <= 'f')) ADVANCE(40);
|
||||
END_STATE();
|
||||
case 21:
|
||||
if (eof) ADVANCE(22);
|
||||
if (lookahead == '"') ADVANCE(29);
|
||||
if (lookahead == '+' ||
|
||||
lookahead == '-') ADVANCE(3);
|
||||
if (lookahead == ',') ADVANCE(24);
|
||||
if (lookahead == '.') ADVANCE(18);
|
||||
if (lookahead == '0') ADVANCE(33);
|
||||
if (lookahead == ':') ADVANCE(26);
|
||||
if (lookahead == '[') ADVANCE(27);
|
||||
if (lookahead == ']') ADVANCE(28);
|
||||
if (lookahead == 'f') ADVANCE(4);
|
||||
if (lookahead == 'n') ADVANCE(13);
|
||||
if (lookahead == 't') ADVANCE(10);
|
||||
if (lookahead == '{') ADVANCE(23);
|
||||
if (lookahead == '}') ADVANCE(25);
|
||||
if (lookahead == '\t' ||
|
||||
lookahead == '\n' ||
|
||||
lookahead == '\r' ||
|
||||
lookahead == ' ') SKIP(21)
|
||||
if (('1' <= lookahead && lookahead <= '9')) ADVANCE(35);
|
||||
END_STATE();
|
||||
case 22:
|
||||
ACCEPT_TOKEN(ts_builtin_sym_end);
|
||||
END_STATE();
|
||||
case 23:
|
||||
ACCEPT_TOKEN(anon_sym_LBRACE);
|
||||
END_STATE();
|
||||
case 24:
|
||||
ACCEPT_TOKEN(anon_sym_COMMA);
|
||||
END_STATE();
|
||||
case 25:
|
||||
ACCEPT_TOKEN(anon_sym_RBRACE);
|
||||
END_STATE();
|
||||
case 26:
|
||||
ACCEPT_TOKEN(anon_sym_COLON);
|
||||
END_STATE();
|
||||
case 27:
|
||||
ACCEPT_TOKEN(anon_sym_LBRACK);
|
||||
END_STATE();
|
||||
case 28:
|
||||
ACCEPT_TOKEN(anon_sym_RBRACK);
|
||||
END_STATE();
|
||||
case 29:
|
||||
ACCEPT_TOKEN(anon_sym_DQUOTE);
|
||||
END_STATE();
|
||||
case 30:
|
||||
ACCEPT_TOKEN(aux_sym_string_content_token1);
|
||||
if (lookahead == '\t' ||
|
||||
lookahead == '\r' ||
|
||||
lookahead == ' ') ADVANCE(30);
|
||||
if (lookahead != 0 &&
|
||||
lookahead != '\n' &&
|
||||
lookahead != '"' &&
|
||||
lookahead != '\\') ADVANCE(31);
|
||||
END_STATE();
|
||||
case 31:
|
||||
ACCEPT_TOKEN(aux_sym_string_content_token1);
|
||||
if (lookahead != 0 &&
|
||||
lookahead != '\n' &&
|
||||
lookahead != '"' &&
|
||||
lookahead != '\\') ADVANCE(31);
|
||||
END_STATE();
|
||||
case 32:
|
||||
ACCEPT_TOKEN(sym_escape_sequence);
|
||||
END_STATE();
|
||||
case 33:
|
||||
ACCEPT_TOKEN(sym_number);
|
||||
if (lookahead == '.') ADVANCE(36);
|
||||
if (lookahead == 'B' ||
|
||||
lookahead == 'b') ADVANCE(15);
|
||||
if (lookahead == 'E' ||
|
||||
lookahead == 'e') ADVANCE(14);
|
||||
if (lookahead == 'O' ||
|
||||
lookahead == 'o') ADVANCE(17);
|
||||
if (lookahead == 'X' ||
|
||||
lookahead == 'x') ADVANCE(20);
|
||||
END_STATE();
|
||||
case 34:
|
||||
ACCEPT_TOKEN(sym_number);
|
||||
if (lookahead == '.') ADVANCE(36);
|
||||
if (lookahead == 'E' ||
|
||||
lookahead == 'e') ADVANCE(14);
|
||||
END_STATE();
|
||||
case 35:
|
||||
ACCEPT_TOKEN(sym_number);
|
||||
if (lookahead == '.') ADVANCE(36);
|
||||
if (lookahead == 'E' ||
|
||||
lookahead == 'e') ADVANCE(14);
|
||||
if (('0' <= lookahead && lookahead <= '9')) ADVANCE(35);
|
||||
END_STATE();
|
||||
case 36:
|
||||
ACCEPT_TOKEN(sym_number);
|
||||
if (lookahead == 'E' ||
|
||||
lookahead == 'e') ADVANCE(14);
|
||||
if (('0' <= lookahead && lookahead <= '9')) ADVANCE(36);
|
||||
END_STATE();
|
||||
case 37:
|
||||
ACCEPT_TOKEN(sym_number);
|
||||
if (lookahead == '0' ||
|
||||
lookahead == '1') ADVANCE(37);
|
||||
END_STATE();
|
||||
case 38:
|
||||
ACCEPT_TOKEN(sym_number);
|
||||
if (('0' <= lookahead && lookahead <= '7')) ADVANCE(38);
|
||||
END_STATE();
|
||||
case 39:
|
||||
ACCEPT_TOKEN(sym_number);
|
||||
if (('0' <= lookahead && lookahead <= '9')) ADVANCE(39);
|
||||
END_STATE();
|
||||
case 40:
|
||||
ACCEPT_TOKEN(sym_number);
|
||||
if (('0' <= lookahead && lookahead <= '9') ||
|
||||
('A' <= lookahead && lookahead <= 'F') ||
|
||||
('a' <= lookahead && lookahead <= 'f')) ADVANCE(40);
|
||||
END_STATE();
|
||||
case 41:
|
||||
ACCEPT_TOKEN(sym_true);
|
||||
END_STATE();
|
||||
case 42:
|
||||
ACCEPT_TOKEN(sym_false);
|
||||
END_STATE();
|
||||
case 43:
|
||||
ACCEPT_TOKEN(sym_null);
|
||||
END_STATE();
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static TSLexMode ts_lex_modes[STATE_COUNT] = {
|
||||
[0] = {.lex_state = 0},
|
||||
[1] = {.lex_state = 0},
|
||||
[2] = {.lex_state = 0},
|
||||
[3] = {.lex_state = 0},
|
||||
[4] = {.lex_state = 0},
|
||||
[5] = {.lex_state = 0},
|
||||
[6] = {.lex_state = 0},
|
||||
[7] = {.lex_state = 1},
|
||||
[8] = {.lex_state = 0},
|
||||
[9] = {.lex_state = 0},
|
||||
[10] = {.lex_state = 0},
|
||||
[11] = {.lex_state = 1},
|
||||
[12] = {.lex_state = 0},
|
||||
[13] = {.lex_state = 0},
|
||||
[14] = {.lex_state = 0},
|
||||
[15] = {.lex_state = 0},
|
||||
[16] = {.lex_state = 0},
|
||||
[17] = {.lex_state = 1},
|
||||
[18] = {.lex_state = 0},
|
||||
[19] = {.lex_state = 0},
|
||||
[20] = {.lex_state = 0},
|
||||
[21] = {.lex_state = 0},
|
||||
[22] = {.lex_state = 0},
|
||||
[23] = {.lex_state = 0},
|
||||
[24] = {.lex_state = 0},
|
||||
[25] = {.lex_state = 0},
|
||||
[26] = {.lex_state = 0},
|
||||
[27] = {.lex_state = 0},
|
||||
[28] = {.lex_state = 0},
|
||||
[29] = {.lex_state = 0},
|
||||
[30] = {.lex_state = 0},
|
||||
[31] = {.lex_state = 0},
|
||||
};
|
||||
|
||||
static uint16_t ts_parse_table[LARGE_STATE_COUNT][SYMBOL_COUNT] = {
|
||||
[0] = {
|
||||
[ts_builtin_sym_end] = ACTIONS(1),
|
||||
[anon_sym_LBRACE] = ACTIONS(1),
|
||||
[anon_sym_COMMA] = ACTIONS(1),
|
||||
[anon_sym_RBRACE] = ACTIONS(1),
|
||||
[anon_sym_COLON] = ACTIONS(1),
|
||||
[anon_sym_LBRACK] = ACTIONS(1),
|
||||
[anon_sym_RBRACK] = ACTIONS(1),
|
||||
[anon_sym_DQUOTE] = ACTIONS(1),
|
||||
[sym_escape_sequence] = ACTIONS(1),
|
||||
[sym_number] = ACTIONS(1),
|
||||
[sym_true] = ACTIONS(1),
|
||||
[sym_false] = ACTIONS(1),
|
||||
[sym_null] = ACTIONS(1),
|
||||
},
|
||||
[1] = {
|
||||
[sym_document] = STATE(28),
|
||||
[sym__value] = STATE(31),
|
||||
[sym_object] = STATE(12),
|
||||
[sym_array] = STATE(12),
|
||||
[sym_string] = STATE(12),
|
||||
[anon_sym_LBRACE] = ACTIONS(3),
|
||||
[anon_sym_LBRACK] = ACTIONS(5),
|
||||
[anon_sym_DQUOTE] = ACTIONS(7),
|
||||
[sym_number] = ACTIONS(9),
|
||||
[sym_true] = ACTIONS(9),
|
||||
[sym_false] = ACTIONS(9),
|
||||
[sym_null] = ACTIONS(9),
|
||||
},
|
||||
};
|
||||
|
||||
static uint16_t ts_small_parse_table[] = {
|
||||
[0] = 7,
|
||||
ACTIONS(3), 1,
|
||||
anon_sym_LBRACE,
|
||||
ACTIONS(5), 1,
|
||||
anon_sym_LBRACK,
|
||||
ACTIONS(7), 1,
|
||||
anon_sym_DQUOTE,
|
||||
ACTIONS(11), 1,
|
||||
anon_sym_RBRACK,
|
||||
STATE(21), 1,
|
||||
sym__value,
|
||||
STATE(12), 3,
|
||||
sym_object,
|
||||
sym_array,
|
||||
sym_string,
|
||||
ACTIONS(9), 4,
|
||||
sym_number,
|
||||
sym_true,
|
||||
sym_false,
|
||||
sym_null,
|
||||
[27] = 6,
|
||||
ACTIONS(3), 1,
|
||||
anon_sym_LBRACE,
|
||||
ACTIONS(5), 1,
|
||||
anon_sym_LBRACK,
|
||||
ACTIONS(7), 1,
|
||||
anon_sym_DQUOTE,
|
||||
STATE(27), 1,
|
||||
sym__value,
|
||||
STATE(12), 3,
|
||||
sym_object,
|
||||
sym_array,
|
||||
sym_string,
|
||||
ACTIONS(9), 4,
|
||||
sym_number,
|
||||
sym_true,
|
||||
sym_false,
|
||||
sym_null,
|
||||
[51] = 6,
|
||||
ACTIONS(3), 1,
|
||||
anon_sym_LBRACE,
|
||||
ACTIONS(5), 1,
|
||||
anon_sym_LBRACK,
|
||||
ACTIONS(7), 1,
|
||||
anon_sym_DQUOTE,
|
||||
STATE(25), 1,
|
||||
sym__value,
|
||||
STATE(12), 3,
|
||||
sym_object,
|
||||
sym_array,
|
||||
sym_string,
|
||||
ACTIONS(9), 4,
|
||||
sym_number,
|
||||
sym_true,
|
||||
sym_false,
|
||||
sym_null,
|
||||
[75] = 1,
|
||||
ACTIONS(13), 5,
|
||||
ts_builtin_sym_end,
|
||||
anon_sym_COMMA,
|
||||
anon_sym_RBRACE,
|
||||
anon_sym_COLON,
|
||||
anon_sym_RBRACK,
|
||||
[83] = 5,
|
||||
ACTIONS(7), 1,
|
||||
anon_sym_DQUOTE,
|
||||
ACTIONS(15), 1,
|
||||
anon_sym_RBRACE,
|
||||
ACTIONS(17), 1,
|
||||
sym_number,
|
||||
STATE(20), 1,
|
||||
sym_pair,
|
||||
STATE(29), 1,
|
||||
sym_string,
|
||||
[99] = 4,
|
||||
ACTIONS(19), 1,
|
||||
anon_sym_DQUOTE,
|
||||
STATE(11), 1,
|
||||
aux_sym_string_content_repeat1,
|
||||
STATE(30), 1,
|
||||
sym_string_content,
|
||||
ACTIONS(21), 2,
|
||||
aux_sym_string_content_token1,
|
||||
sym_escape_sequence,
|
||||
[113] = 1,
|
||||
ACTIONS(23), 5,
|
||||
ts_builtin_sym_end,
|
||||
anon_sym_COMMA,
|
||||
anon_sym_RBRACE,
|
||||
anon_sym_COLON,
|
||||
anon_sym_RBRACK,
|
||||
[121] = 1,
|
||||
ACTIONS(25), 4,
|
||||
ts_builtin_sym_end,
|
||||
anon_sym_COMMA,
|
||||
anon_sym_RBRACE,
|
||||
anon_sym_RBRACK,
|
||||
[128] = 1,
|
||||
ACTIONS(27), 4,
|
||||
ts_builtin_sym_end,
|
||||
anon_sym_COMMA,
|
||||
anon_sym_RBRACE,
|
||||
anon_sym_RBRACK,
|
||||
[135] = 3,
|
||||
ACTIONS(29), 1,
|
||||
anon_sym_DQUOTE,
|
||||
STATE(17), 1,
|
||||
aux_sym_string_content_repeat1,
|
||||
ACTIONS(31), 2,
|
||||
aux_sym_string_content_token1,
|
||||
sym_escape_sequence,
|
||||
[146] = 1,
|
||||
ACTIONS(33), 4,
|
||||
ts_builtin_sym_end,
|
||||
anon_sym_COMMA,
|
||||
anon_sym_RBRACE,
|
||||
anon_sym_RBRACK,
|
||||
[153] = 4,
|
||||
ACTIONS(7), 1,
|
||||
anon_sym_DQUOTE,
|
||||
ACTIONS(17), 1,
|
||||
sym_number,
|
||||
STATE(26), 1,
|
||||
sym_pair,
|
||||
STATE(29), 1,
|
||||
sym_string,
|
||||
[166] = 1,
|
||||
ACTIONS(35), 4,
|
||||
ts_builtin_sym_end,
|
||||
anon_sym_COMMA,
|
||||
anon_sym_RBRACE,
|
||||
anon_sym_RBRACK,
|
||||
[173] = 1,
|
||||
ACTIONS(37), 4,
|
||||
ts_builtin_sym_end,
|
||||
anon_sym_COMMA,
|
||||
anon_sym_RBRACE,
|
||||
anon_sym_RBRACK,
|
||||
[180] = 1,
|
||||
ACTIONS(39), 4,
|
||||
ts_builtin_sym_end,
|
||||
anon_sym_COMMA,
|
||||
anon_sym_RBRACE,
|
||||
anon_sym_RBRACK,
|
||||
[187] = 3,
|
||||
ACTIONS(41), 1,
|
||||
anon_sym_DQUOTE,
|
||||
STATE(17), 1,
|
||||
aux_sym_string_content_repeat1,
|
||||
ACTIONS(43), 2,
|
||||
aux_sym_string_content_token1,
|
||||
sym_escape_sequence,
|
||||
[198] = 1,
|
||||
ACTIONS(46), 4,
|
||||
ts_builtin_sym_end,
|
||||
anon_sym_COMMA,
|
||||
anon_sym_RBRACE,
|
||||
anon_sym_RBRACK,
|
||||
[205] = 3,
|
||||
ACTIONS(48), 1,
|
||||
anon_sym_COMMA,
|
||||
ACTIONS(51), 1,
|
||||
anon_sym_RBRACE,
|
||||
STATE(19), 1,
|
||||
aux_sym_object_repeat1,
|
||||
[215] = 3,
|
||||
ACTIONS(53), 1,
|
||||
anon_sym_COMMA,
|
||||
ACTIONS(55), 1,
|
||||
anon_sym_RBRACE,
|
||||
STATE(23), 1,
|
||||
aux_sym_object_repeat1,
|
||||
[225] = 3,
|
||||
ACTIONS(57), 1,
|
||||
anon_sym_COMMA,
|
||||
ACTIONS(59), 1,
|
||||
anon_sym_RBRACK,
|
||||
STATE(24), 1,
|
||||
aux_sym_array_repeat1,
|
||||
[235] = 3,
|
||||
ACTIONS(61), 1,
|
||||
anon_sym_COMMA,
|
||||
ACTIONS(64), 1,
|
||||
anon_sym_RBRACK,
|
||||
STATE(22), 1,
|
||||
aux_sym_array_repeat1,
|
||||
[245] = 3,
|
||||
ACTIONS(53), 1,
|
||||
anon_sym_COMMA,
|
||||
ACTIONS(66), 1,
|
||||
anon_sym_RBRACE,
|
||||
STATE(19), 1,
|
||||
aux_sym_object_repeat1,
|
||||
[255] = 3,
|
||||
ACTIONS(57), 1,
|
||||
anon_sym_COMMA,
|
||||
ACTIONS(68), 1,
|
||||
anon_sym_RBRACK,
|
||||
STATE(22), 1,
|
||||
aux_sym_array_repeat1,
|
||||
[265] = 1,
|
||||
ACTIONS(70), 2,
|
||||
anon_sym_COMMA,
|
||||
anon_sym_RBRACE,
|
||||
[270] = 1,
|
||||
ACTIONS(51), 2,
|
||||
anon_sym_COMMA,
|
||||
anon_sym_RBRACE,
|
||||
[275] = 1,
|
||||
ACTIONS(64), 2,
|
||||
anon_sym_COMMA,
|
||||
anon_sym_RBRACK,
|
||||
[280] = 1,
|
||||
ACTIONS(72), 1,
|
||||
ts_builtin_sym_end,
|
||||
[284] = 1,
|
||||
ACTIONS(74), 1,
|
||||
anon_sym_COLON,
|
||||
[288] = 1,
|
||||
ACTIONS(76), 1,
|
||||
anon_sym_DQUOTE,
|
||||
[292] = 1,
|
||||
ACTIONS(78), 1,
|
||||
ts_builtin_sym_end,
|
||||
};
|
||||
|
||||
static uint32_t ts_small_parse_table_map[] = {
|
||||
[SMALL_STATE(2)] = 0,
|
||||
[SMALL_STATE(3)] = 27,
|
||||
[SMALL_STATE(4)] = 51,
|
||||
[SMALL_STATE(5)] = 75,
|
||||
[SMALL_STATE(6)] = 83,
|
||||
[SMALL_STATE(7)] = 99,
|
||||
[SMALL_STATE(8)] = 113,
|
||||
[SMALL_STATE(9)] = 121,
|
||||
[SMALL_STATE(10)] = 128,
|
||||
[SMALL_STATE(11)] = 135,
|
||||
[SMALL_STATE(12)] = 146,
|
||||
[SMALL_STATE(13)] = 153,
|
||||
[SMALL_STATE(14)] = 166,
|
||||
[SMALL_STATE(15)] = 173,
|
||||
[SMALL_STATE(16)] = 180,
|
||||
[SMALL_STATE(17)] = 187,
|
||||
[SMALL_STATE(18)] = 198,
|
||||
[SMALL_STATE(19)] = 205,
|
||||
[SMALL_STATE(20)] = 215,
|
||||
[SMALL_STATE(21)] = 225,
|
||||
[SMALL_STATE(22)] = 235,
|
||||
[SMALL_STATE(23)] = 245,
|
||||
[SMALL_STATE(24)] = 255,
|
||||
[SMALL_STATE(25)] = 265,
|
||||
[SMALL_STATE(26)] = 270,
|
||||
[SMALL_STATE(27)] = 275,
|
||||
[SMALL_STATE(28)] = 280,
|
||||
[SMALL_STATE(29)] = 284,
|
||||
[SMALL_STATE(30)] = 288,
|
||||
[SMALL_STATE(31)] = 292,
|
||||
};
|
||||
|
||||
static TSParseActionEntry ts_parse_actions[] = {
|
||||
[0] = {.entry = {.count = 0, .reusable = false}},
|
||||
[1] = {.entry = {.count = 1, .reusable = false}}, RECOVER(),
|
||||
[3] = {.entry = {.count = 1, .reusable = true}}, SHIFT(6),
|
||||
[5] = {.entry = {.count = 1, .reusable = true}}, SHIFT(2),
|
||||
[7] = {.entry = {.count = 1, .reusable = true}}, SHIFT(7),
|
||||
[9] = {.entry = {.count = 1, .reusable = true}}, SHIFT(12),
|
||||
[11] = {.entry = {.count = 1, .reusable = true}}, SHIFT(10),
|
||||
[13] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_string, 2),
|
||||
[15] = {.entry = {.count = 1, .reusable = true}}, SHIFT(9),
|
||||
[17] = {.entry = {.count = 1, .reusable = true}}, SHIFT(29),
|
||||
[19] = {.entry = {.count = 1, .reusable = false}}, SHIFT(5),
|
||||
[21] = {.entry = {.count = 1, .reusable = true}}, SHIFT(11),
|
||||
[23] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_string, 3),
|
||||
[25] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_object, 2),
|
||||
[27] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_array, 2),
|
||||
[29] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_string_content, 1),
|
||||
[31] = {.entry = {.count = 1, .reusable = true}}, SHIFT(17),
|
||||
[33] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym__value, 1),
|
||||
[35] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_object, 3),
|
||||
[37] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_array, 4),
|
||||
[39] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_array, 3),
|
||||
[41] = {.entry = {.count = 1, .reusable = false}}, REDUCE(aux_sym_string_content_repeat1, 2),
|
||||
[43] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym_string_content_repeat1, 2), SHIFT_REPEAT(17),
|
||||
[46] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_object, 4),
|
||||
[48] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym_object_repeat1, 2), SHIFT_REPEAT(13),
|
||||
[51] = {.entry = {.count = 1, .reusable = true}}, REDUCE(aux_sym_object_repeat1, 2),
|
||||
[53] = {.entry = {.count = 1, .reusable = true}}, SHIFT(13),
|
||||
[55] = {.entry = {.count = 1, .reusable = true}}, SHIFT(14),
|
||||
[57] = {.entry = {.count = 1, .reusable = true}}, SHIFT(3),
|
||||
[59] = {.entry = {.count = 1, .reusable = true}}, SHIFT(16),
|
||||
[61] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym_array_repeat1, 2), SHIFT_REPEAT(3),
|
||||
[64] = {.entry = {.count = 1, .reusable = true}}, REDUCE(aux_sym_array_repeat1, 2),
|
||||
[66] = {.entry = {.count = 1, .reusable = true}}, SHIFT(18),
|
||||
[68] = {.entry = {.count = 1, .reusable = true}}, SHIFT(15),
|
||||
[70] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_pair, 3, .production_id = 1),
|
||||
[72] = {.entry = {.count = 1, .reusable = true}}, ACCEPT_INPUT(),
|
||||
[74] = {.entry = {.count = 1, .reusable = true}}, SHIFT(4),
|
||||
[76] = {.entry = {.count = 1, .reusable = true}}, SHIFT(8),
|
||||
[78] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_document, 1),
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#ifdef _WIN32
|
||||
#define extern __declspec(dllexport)
|
||||
#endif
|
||||
|
||||
extern const TSLanguage *tree_sitter_json(void) {
|
||||
static TSLanguage language = {
|
||||
.version = LANGUAGE_VERSION,
|
||||
.symbol_count = SYMBOL_COUNT,
|
||||
.alias_count = ALIAS_COUNT,
|
||||
.token_count = TOKEN_COUNT,
|
||||
.external_token_count = EXTERNAL_TOKEN_COUNT,
|
||||
.state_count = STATE_COUNT,
|
||||
.large_state_count = LARGE_STATE_COUNT,
|
||||
.production_id_count = PRODUCTION_ID_COUNT,
|
||||
.field_count = FIELD_COUNT,
|
||||
.max_alias_sequence_length = MAX_ALIAS_SEQUENCE_LENGTH,
|
||||
.parse_table = (const uint16_t *)ts_parse_table,
|
||||
.small_parse_table = (const uint16_t *)ts_small_parse_table,
|
||||
.small_parse_table_map = (const uint32_t *)ts_small_parse_table_map,
|
||||
.parse_actions = ts_parse_actions,
|
||||
.symbol_names = ts_symbol_names,
|
||||
.field_names = ts_field_names,
|
||||
.field_map_slices = (const TSFieldMapSlice *)ts_field_map_slices,
|
||||
.field_map_entries = (const TSFieldMapEntry *)ts_field_map_entries,
|
||||
.symbol_metadata = ts_symbol_metadata,
|
||||
.public_symbol_map = ts_symbol_map,
|
||||
.alias_map = ts_non_terminal_alias_map,
|
||||
.alias_sequences = (const TSSymbol *)ts_alias_sequences,
|
||||
.lex_modes = ts_lex_modes,
|
||||
.lex_fn = ts_lex,
|
||||
};
|
||||
return &language;
|
||||
}
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@ -0,0 +1,223 @@
|
||||
#ifndef TREE_SITTER_PARSER_H_
|
||||
#define TREE_SITTER_PARSER_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define ts_builtin_sym_error ((TSSymbol)-1)
|
||||
#define ts_builtin_sym_end 0
|
||||
#define TREE_SITTER_SERIALIZATION_BUFFER_SIZE 1024
|
||||
|
||||
typedef uint16_t TSStateId;
|
||||
|
||||
#ifndef TREE_SITTER_API_H_
|
||||
typedef uint16_t TSSymbol;
|
||||
typedef uint16_t TSFieldId;
|
||||
typedef struct TSLanguage TSLanguage;
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
TSFieldId field_id;
|
||||
uint8_t child_index;
|
||||
bool inherited;
|
||||
} TSFieldMapEntry;
|
||||
|
||||
typedef struct {
|
||||
uint16_t index;
|
||||
uint16_t length;
|
||||
} TSFieldMapSlice;
|
||||
|
||||
typedef struct {
|
||||
bool visible;
|
||||
bool named;
|
||||
bool supertype;
|
||||
} TSSymbolMetadata;
|
||||
|
||||
typedef struct TSLexer TSLexer;
|
||||
|
||||
struct TSLexer {
|
||||
int32_t lookahead;
|
||||
TSSymbol result_symbol;
|
||||
void (*advance)(TSLexer *, bool);
|
||||
void (*mark_end)(TSLexer *);
|
||||
uint32_t (*get_column)(TSLexer *);
|
||||
bool (*is_at_included_range_start)(const TSLexer *);
|
||||
bool (*eof)(const TSLexer *);
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
TSParseActionTypeShift,
|
||||
TSParseActionTypeReduce,
|
||||
TSParseActionTypeAccept,
|
||||
TSParseActionTypeRecover,
|
||||
} TSParseActionType;
|
||||
|
||||
typedef union {
|
||||
struct {
|
||||
uint8_t type;
|
||||
TSStateId state;
|
||||
bool extra;
|
||||
bool repetition;
|
||||
} shift;
|
||||
struct {
|
||||
uint8_t type;
|
||||
uint8_t child_count;
|
||||
TSSymbol symbol;
|
||||
int16_t dynamic_precedence;
|
||||
uint16_t production_id;
|
||||
} reduce;
|
||||
uint8_t type;
|
||||
} TSParseAction;
|
||||
|
||||
typedef struct {
|
||||
uint16_t lex_state;
|
||||
uint16_t external_lex_state;
|
||||
} TSLexMode;
|
||||
|
||||
typedef union {
|
||||
TSParseAction action;
|
||||
struct {
|
||||
uint8_t count;
|
||||
bool reusable;
|
||||
} entry;
|
||||
} TSParseActionEntry;
|
||||
|
||||
struct TSLanguage {
|
||||
uint32_t version;
|
||||
uint32_t symbol_count;
|
||||
uint32_t alias_count;
|
||||
uint32_t token_count;
|
||||
uint32_t external_token_count;
|
||||
uint32_t state_count;
|
||||
uint32_t large_state_count;
|
||||
uint32_t production_id_count;
|
||||
uint32_t field_count;
|
||||
uint16_t max_alias_sequence_length;
|
||||
const uint16_t *parse_table;
|
||||
const uint16_t *small_parse_table;
|
||||
const uint32_t *small_parse_table_map;
|
||||
const TSParseActionEntry *parse_actions;
|
||||
const char **symbol_names;
|
||||
const char **field_names;
|
||||
const TSFieldMapSlice *field_map_slices;
|
||||
const TSFieldMapEntry *field_map_entries;
|
||||
const TSSymbolMetadata *symbol_metadata;
|
||||
const TSSymbol *public_symbol_map;
|
||||
const uint16_t *alias_map;
|
||||
const TSSymbol *alias_sequences;
|
||||
const TSLexMode *lex_modes;
|
||||
bool (*lex_fn)(TSLexer *, TSStateId);
|
||||
bool (*keyword_lex_fn)(TSLexer *, TSStateId);
|
||||
TSSymbol keyword_capture_token;
|
||||
struct {
|
||||
const bool *states;
|
||||
const TSSymbol *symbol_map;
|
||||
void *(*create)(void);
|
||||
void (*destroy)(void *);
|
||||
bool (*scan)(void *, TSLexer *, const bool *symbol_whitelist);
|
||||
unsigned (*serialize)(void *, char *);
|
||||
void (*deserialize)(void *, const char *, unsigned);
|
||||
} external_scanner;
|
||||
};
|
||||
|
||||
/*
|
||||
* Lexer Macros
|
||||
*/
|
||||
|
||||
#define START_LEXER() \
|
||||
bool result = false; \
|
||||
bool skip = false; \
|
||||
bool eof = false; \
|
||||
int32_t lookahead; \
|
||||
goto start; \
|
||||
next_state: \
|
||||
lexer->advance(lexer, skip); \
|
||||
start: \
|
||||
skip = false; \
|
||||
lookahead = lexer->lookahead;
|
||||
|
||||
#define ADVANCE(state_value) \
|
||||
{ \
|
||||
state = state_value; \
|
||||
goto next_state; \
|
||||
}
|
||||
|
||||
#define SKIP(state_value) \
|
||||
{ \
|
||||
skip = true; \
|
||||
state = state_value; \
|
||||
goto next_state; \
|
||||
}
|
||||
|
||||
#define ACCEPT_TOKEN(symbol_value) \
|
||||
result = true; \
|
||||
lexer->result_symbol = symbol_value; \
|
||||
lexer->mark_end(lexer);
|
||||
|
||||
#define END_STATE() return result;
|
||||
|
||||
/*
|
||||
* Parse Table Macros
|
||||
*/
|
||||
|
||||
#define SMALL_STATE(id) id - LARGE_STATE_COUNT
|
||||
|
||||
#define STATE(id) id
|
||||
|
||||
#define ACTIONS(id) id
|
||||
|
||||
#define SHIFT(state_value) \
|
||||
{{ \
|
||||
.shift = { \
|
||||
.type = TSParseActionTypeShift, \
|
||||
.state = state_value \
|
||||
} \
|
||||
}}
|
||||
|
||||
#define SHIFT_REPEAT(state_value) \
|
||||
{{ \
|
||||
.shift = { \
|
||||
.type = TSParseActionTypeShift, \
|
||||
.state = state_value, \
|
||||
.repetition = true \
|
||||
} \
|
||||
}}
|
||||
|
||||
#define SHIFT_EXTRA() \
|
||||
{{ \
|
||||
.shift = { \
|
||||
.type = TSParseActionTypeShift, \
|
||||
.extra = true \
|
||||
} \
|
||||
}}
|
||||
|
||||
#define REDUCE(symbol_val, child_count_val, ...) \
|
||||
{{ \
|
||||
.reduce = { \
|
||||
.type = TSParseActionTypeReduce, \
|
||||
.symbol = symbol_val, \
|
||||
.child_count = child_count_val, \
|
||||
__VA_ARGS__ \
|
||||
}, \
|
||||
}}
|
||||
|
||||
#define RECOVER() \
|
||||
{{ \
|
||||
.type = TSParseActionTypeRecover \
|
||||
}}
|
||||
|
||||
#define ACCEPT_INPUT() \
|
||||
{{ \
|
||||
.type = TSParseActionTypeAccept \
|
||||
}}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // TREE_SITTER_PARSER_H_
|
||||
Loading…
Reference in New Issue