diff --git a/bindings/rust/build.rs b/bindings/rust/build.rs index 89242d3..015ae3c 100644 --- a/bindings/rust/build.rs +++ b/bindings/rust/build.rs @@ -4,6 +4,9 @@ fn main() { let mut c_config = cc::Build::new(); c_config.std("c11").include(src_dir); + #[cfg(target_env = "msvc")] + c_config.flag("-utf-8"); + let parser_path = src_dir.join("parser.c"); c_config.file(&parser_path); println!("cargo:rerun-if-changed={}", parser_path.to_str().unwrap()); diff --git a/grammar.js b/grammar.js index 4a7cfe6..62f1f43 100644 --- a/grammar.js +++ b/grammar.js @@ -49,14 +49,16 @@ module.exports = grammar({ string: $ => choice( seq('"', '"'), - seq('"', $.string_content, '"'), + seq('"', $._string_content, '"'), ), - string_content: $ => repeat1(choice( - token.immediate(prec(1, /[^\\"\n]+/)), + _string_content: $ => repeat1(choice( + $.string_content, $.escape_sequence, )), + string_content: _ => token.immediate(prec(1, /[^\\"\n]+/)), + escape_sequence: _ => token.immediate(seq( '\\', /(\"|\\|\/|b|f|n|r|t|u)/, diff --git a/package-lock.json b/package-lock.json index fe8a43e..ed0f8d5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -28,15 +28,6 @@ } } }, - "node_modules/@aashutoshrathi/word-wrap": { - "version": "1.2.6", - "resolved": "https://registry.npmjs.org/@aashutoshrathi/word-wrap/-/word-wrap-1.2.6.tgz", - "integrity": "sha512-1Yjs2SvM8TflER/OD3cOjhWWOZb58A2t7wpE2S9XfBYTiIl+XFhQG2bjy4Pu1I+EAlCNUzRDYDdFwFYUKvXcIA==", - "dev": true, - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/@eslint-community/eslint-utils": { "version": "4.4.0", "resolved": "https://registry.npmjs.org/@eslint-community/eslint-utils/-/eslint-utils-4.4.0.tgz", @@ -584,15 +575,6 @@ "node": ">=0.10.0" } }, - "node_modules/execspawn": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/execspawn/-/execspawn-1.0.1.tgz", - "integrity": "sha512-s2k06Jy9i8CUkYe0+DxRlvtkZoOkwwfhB+Xxo5HGUtrISVW2m98jO2tr67DGRFxZwkjQqloA3v/tNtjhBRBieg==", - "dev": true, - "dependencies": { - "util-extend": "^1.0.1" - } - }, "node_modules/fast-deep-equal": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", @@ -973,9 +955,9 @@ "dev": true }, "node_modules/node-abi": { - "version": "3.57.0", - "resolved": "https://registry.npmjs.org/node-abi/-/node-abi-3.57.0.tgz", - "integrity": "sha512-Dp+A9JWxRaKuHP35H77I4kCKesDy5HUDEmScia2FyncMTOXASMyg251F5PhFoDA5uqBrDDffiLpbqnrZmNXW+g==", + "version": "3.62.0", + "resolved": "https://registry.npmjs.org/node-abi/-/node-abi-3.62.0.tgz", + "integrity": "sha512-CPMcGa+y33xuL1E0TcNIu4YyaZCxnnvkVaEXrsosR3FxN+fV8xvb7Mzpb7IgKler10qeMkE6+Dp8qJhpzdq35g==", "dev": true, "dependencies": { "semver": "^7.3.5" @@ -993,9 +975,9 @@ } }, "node_modules/node-gyp-build": { - "version": "4.8.0", - "resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.8.0.tgz", - "integrity": "sha512-u6fs2AEUljNho3EYTJNBfImO5QTo/J/1Etd+NVdCj7qWKUSN/bSLkZwhDv7I+w/MSC6qJ4cknepkAYykDdK8og==", + "version": "4.8.1", + "resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.8.1.tgz", + "integrity": "sha512-OSs33Z9yWr148JZcbZd5WiAXhh/n9z8TxQcdMhIOlpN9AhWpLfvVFO73+m77bBABQMaY9XSvIa+qk0jlI7Gcaw==", "bin": { "node-gyp-build": "bin.js", "node-gyp-build-optional": "optional.js", @@ -1024,17 +1006,17 @@ } }, "node_modules/optionator": { - "version": "0.9.3", - "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.9.3.tgz", - "integrity": "sha512-JjCoypp+jKn1ttEFExxhetCKeJt9zhAgAve5FXHixTvFDW/5aEktX9bufBKLRRMdU7bNtpLfcGu94B3cdEJgjg==", + "version": "0.9.4", + "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.9.4.tgz", + "integrity": "sha512-6IpQ7mKUxRcZNLIObR0hz7lxsapSSIYNZJwXPGeF0mTVqGKFIXj1DQcMoT22S3ROcLyY/rz0PWaWZ9ayWmad9g==", "dev": true, "dependencies": { - "@aashutoshrathi/word-wrap": "^1.2.3", "deep-is": "^0.1.3", "fast-levenshtein": "^2.0.6", "levn": "^0.4.1", "prelude-ls": "^1.2.1", - "type-check": "^0.4.0" + "type-check": "^0.4.0", + "word-wrap": "^1.2.5" }, "engines": { "node": ">= 0.8.0" @@ -1110,12 +1092,11 @@ } }, "node_modules/prebuildify": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/prebuildify/-/prebuildify-6.0.0.tgz", - "integrity": "sha512-DEvK4C3tcimIp7Pzqbs036n9i6CTKGp1XVEpMnr4wV3enKU5sBogPP+lP3KZw7993i42bXnsd5eIxAXQ566Cqw==", + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/prebuildify/-/prebuildify-6.0.1.tgz", + "integrity": "sha512-8Y2oOOateom/s8dNBsGIcnm6AxPmLH4/nanQzL5lQMU+sC0CMhzARZHizwr36pUPLdvBnOkCNQzxg4djuFSgIw==", "dev": true, "dependencies": { - "execspawn": "^1.0.1", "minimist": "^1.2.5", "mkdirp-classic": "^0.5.3", "node-abi": "^3.3.0", @@ -1393,9 +1374,9 @@ } }, "node_modules/tree-sitter-cli": { - "version": "0.22.2", - "resolved": "https://registry.npmjs.org/tree-sitter-cli/-/tree-sitter-cli-0.22.2.tgz", - "integrity": "sha512-ecqccEp27XMFXgjLMEEU71vK9JCWAC7fqSTTxcs5P1tnEnaaf4GkHz/wfo4lJ9l3rfxcTDPxN84tHAoitIQqdA==", + "version": "0.22.6", + "resolved": "https://registry.npmjs.org/tree-sitter-cli/-/tree-sitter-cli-0.22.6.tgz", + "integrity": "sha512-s7mYOJXi8sIFkt/nLJSqlYZP96VmKTc3BAwIX0rrrlRxWjWuCwixFqwzxWZBQz4R8Hx01iP7z3cT3ih58BUmZQ==", "dev": true, "hasInstallScript": true, "bin": { @@ -1441,12 +1422,6 @@ "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==", "dev": true }, - "node_modules/util-extend": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/util-extend/-/util-extend-1.0.3.tgz", - "integrity": "sha512-mLs5zAK+ctllYBj+iAQvlDCwoxU/WDOUaJkcFudeiAX6OajC6BKXJUa9a+tbtkC11dz2Ufb7h0lyvIOVn4LADA==", - "dev": true - }, "node_modules/which": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", @@ -1462,6 +1437,15 @@ "node": ">= 8" } }, + "node_modules/word-wrap": { + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.5.tgz", + "integrity": "sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA==", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/wrappy": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", diff --git a/src/grammar.json b/src/grammar.json index 21c3cec..874864c 100644 --- a/src/grammar.json +++ b/src/grammar.json @@ -183,7 +183,7 @@ }, { "type": "SYMBOL", - "name": "string_content" + "name": "_string_content" }, { "type": "STRING", @@ -193,21 +193,14 @@ } ] }, - "string_content": { + "_string_content": { "type": "REPEAT1", "content": { "type": "CHOICE", "members": [ { - "type": "IMMEDIATE_TOKEN", - "content": { - "type": "PREC", - "value": 1, - "content": { - "type": "PATTERN", - "value": "[^\\\\\"\\n]+" - } - } + "type": "SYMBOL", + "name": "string_content" }, { "type": "SYMBOL", @@ -216,6 +209,17 @@ ] } }, + "string_content": { + "type": "IMMEDIATE_TOKEN", + "content": { + "type": "PREC", + "value": 1, + "content": { + "type": "PATTERN", + "value": "[^\\\\\"\\n]+" + } + } + }, "escape_sequence": { "type": "IMMEDIATE_TOKEN", "content": { diff --git a/src/node-types.json b/src/node-types.json index 9effd60..c2009e3 100644 --- a/src/node-types.json +++ b/src/node-types.json @@ -108,21 +108,6 @@ "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, @@ -130,6 +115,10 @@ { "type": "escape_sequence", "named": true + }, + { + "type": "string_content", + "named": true } ] } @@ -174,6 +163,10 @@ "type": "number", "named": true }, + { + "type": "string_content", + "named": true + }, { "type": "true", "named": true diff --git a/src/parser.c b/src/parser.c index 2369b0a..eb35875 100644 --- a/src/parser.c +++ b/src/parser.c @@ -5,9 +5,9 @@ #endif #define LANGUAGE_VERSION 14 -#define STATE_COUNT 33 -#define LARGE_STATE_COUNT 4 -#define SYMBOL_COUNT 26 +#define STATE_COUNT 32 +#define LARGE_STATE_COUNT 7 +#define SYMBOL_COUNT 25 #define ALIAS_COUNT 0 #define TOKEN_COUNT 15 #define EXTERNAL_TOKEN_COUNT 0 @@ -23,7 +23,7 @@ enum ts_symbol_identifiers { anon_sym_LBRACK = 5, anon_sym_RBRACK = 6, anon_sym_DQUOTE = 7, - aux_sym_string_content_token1 = 8, + sym_string_content = 8, sym_escape_sequence = 9, sym_number = 10, sym_true = 11, @@ -36,11 +36,10 @@ enum ts_symbol_identifiers { sym_pair = 18, sym_array = 19, sym_string = 20, - sym_string_content = 21, + aux_sym__string_content = 21, aux_sym_document_repeat1 = 22, aux_sym_object_repeat1 = 23, aux_sym_array_repeat1 = 24, - aux_sym_string_content_repeat1 = 25, }; static const char * const ts_symbol_names[] = { @@ -52,7 +51,7 @@ static const char * const ts_symbol_names[] = { [anon_sym_LBRACK] = "[", [anon_sym_RBRACK] = "]", [anon_sym_DQUOTE] = "\"", - [aux_sym_string_content_token1] = "string_content_token1", + [sym_string_content] = "string_content", [sym_escape_sequence] = "escape_sequence", [sym_number] = "number", [sym_true] = "true", @@ -65,11 +64,10 @@ static const char * const ts_symbol_names[] = { [sym_pair] = "pair", [sym_array] = "array", [sym_string] = "string", - [sym_string_content] = "string_content", + [aux_sym__string_content] = "_string_content", [aux_sym_document_repeat1] = "document_repeat1", [aux_sym_object_repeat1] = "object_repeat1", [aux_sym_array_repeat1] = "array_repeat1", - [aux_sym_string_content_repeat1] = "string_content_repeat1", }; static const TSSymbol ts_symbol_map[] = { @@ -81,7 +79,7 @@ static const TSSymbol ts_symbol_map[] = { [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_string_content] = sym_string_content, [sym_escape_sequence] = sym_escape_sequence, [sym_number] = sym_number, [sym_true] = sym_true, @@ -94,11 +92,10 @@ static const TSSymbol ts_symbol_map[] = { [sym_pair] = sym_pair, [sym_array] = sym_array, [sym_string] = sym_string, - [sym_string_content] = sym_string_content, + [aux_sym__string_content] = aux_sym__string_content, [aux_sym_document_repeat1] = aux_sym_document_repeat1, [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[] = { @@ -134,9 +131,9 @@ static const TSSymbolMetadata ts_symbol_metadata[] = { .visible = true, .named = false, }, - [aux_sym_string_content_token1] = { - .visible = false, - .named = false, + [sym_string_content] = { + .visible = true, + .named = true, }, [sym_escape_sequence] = { .visible = true, @@ -187,9 +184,9 @@ static const TSSymbolMetadata ts_symbol_metadata[] = { .visible = true, .named = true, }, - [sym_string_content] = { - .visible = true, - .named = true, + [aux_sym__string_content] = { + .visible = false, + .named = false, }, [aux_sym_document_repeat1] = { .visible = false, @@ -203,10 +200,6 @@ static const TSSymbolMetadata ts_symbol_metadata[] = { .visible = false, .named = false, }, - [aux_sym_string_content_repeat1] = { - .visible = false, - .named = false, - }, }; enum ts_field_identifiers { @@ -271,7 +264,6 @@ static const TSStateId ts_primary_state_ids[STATE_COUNT] = { [29] = 29, [30] = 30, [31] = 31, - [32] = 32, }; static bool ts_lex(TSLexer *lexer, TSStateId state) { @@ -280,26 +272,28 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { switch (state) { case 0: if (eof) ADVANCE(21); - if (lookahead == '"') ADVANCE(28); - if (lookahead == ',') ADVANCE(23); - if (lookahead == '-') ADVANCE(7); - if (lookahead == '/') ADVANCE(3); - if (lookahead == '0') ADVANCE(35); - if (lookahead == ':') ADVANCE(25); - if (lookahead == '[') ADVANCE(26); - if (lookahead == '\\') ADVANCE(18); - if (lookahead == ']') ADVANCE(27); - if (lookahead == 'f') ADVANCE(8); - if (lookahead == 'n') ADVANCE(17); - if (lookahead == 't') ADVANCE(14); - if (lookahead == '{') ADVANCE(22); - if (lookahead == '}') ADVANCE(24); + ADVANCE_MAP( + '"', 28, + ',', 23, + '-', 7, + '/', 3, + '0', 35, + ':', 25, + '[', 26, + '\\', 18, + ']', 27, + 'f', 8, + 'n', 17, + 't', 14, + '{', 22, + '}', 24, + ); if (('\t' <= lookahead && lookahead <= '\r') || - lookahead == ' ') SKIP(20) + lookahead == ' ') SKIP(20); if (('1' <= lookahead && lookahead <= '9')) ADVANCE(36); END_STATE(); case 1: - if (lookahead == '\n') SKIP(2) + if (lookahead == '\n') SKIP(2); if (lookahead == '"') ADVANCE(28); if (lookahead == '/') ADVANCE(29); if (lookahead == '\\') ADVANCE(18); @@ -311,7 +305,7 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { if (lookahead == '"') ADVANCE(28); if (lookahead == '/') ADVANCE(3); if (('\t' <= lookahead && lookahead <= '\r') || - lookahead == ' ') SKIP(2) + lookahead == ' ') SKIP(2); END_STATE(); case 3: if (lookahead == '*') ADVANCE(5); @@ -365,36 +359,40 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { if (lookahead == 'u') ADVANCE(13); END_STATE(); case 18: - if (lookahead == '"' || - lookahead == '/' || - lookahead == '\\' || - lookahead == 'b' || - lookahead == 'f' || - lookahead == 'n' || - lookahead == 'r' || - lookahead == 't' || - lookahead == 'u') ADVANCE(34); + ADVANCE_MAP( + '"', 34, + '/', 34, + '\\', 34, + 'b', 34, + 'f', 34, + 'n', 34, + 'r', 34, + 't', 34, + 'u', 34, + ); END_STATE(); case 19: if (('0' <= lookahead && lookahead <= '9')) ADVANCE(38); END_STATE(); case 20: if (eof) ADVANCE(21); - if (lookahead == '"') ADVANCE(28); - if (lookahead == ',') ADVANCE(23); - if (lookahead == '-') ADVANCE(7); - if (lookahead == '/') ADVANCE(3); - if (lookahead == '0') ADVANCE(35); - if (lookahead == ':') ADVANCE(25); - if (lookahead == '[') ADVANCE(26); - if (lookahead == ']') ADVANCE(27); - if (lookahead == 'f') ADVANCE(8); - if (lookahead == 'n') ADVANCE(17); - if (lookahead == 't') ADVANCE(14); - if (lookahead == '{') ADVANCE(22); - if (lookahead == '}') ADVANCE(24); + ADVANCE_MAP( + '"', 28, + ',', 23, + '-', 7, + '/', 3, + '0', 35, + ':', 25, + '[', 26, + ']', 27, + 'f', 8, + 'n', 17, + 't', 14, + '{', 22, + '}', 24, + ); if (('\t' <= lookahead && lookahead <= '\r') || - lookahead == ' ') SKIP(20) + lookahead == ' ') SKIP(20); if (('1' <= lookahead && lookahead <= '9')) ADVANCE(36); END_STATE(); case 21: @@ -422,7 +420,7 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { ACCEPT_TOKEN(anon_sym_DQUOTE); END_STATE(); case 29: - ACCEPT_TOKEN(aux_sym_string_content_token1); + ACCEPT_TOKEN(sym_string_content); if (lookahead == '*') ADVANCE(31); if (lookahead == '/') ADVANCE(33); if (lookahead != 0 && @@ -431,7 +429,7 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { lookahead != '\\') ADVANCE(33); END_STATE(); case 30: - ACCEPT_TOKEN(aux_sym_string_content_token1); + ACCEPT_TOKEN(sym_string_content); if (lookahead == '*') ADVANCE(30); if (lookahead == '/') ADVANCE(33); if (lookahead != 0 && @@ -440,7 +438,7 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { lookahead != '\\') ADVANCE(31); END_STATE(); case 31: - ACCEPT_TOKEN(aux_sym_string_content_token1); + ACCEPT_TOKEN(sym_string_content); if (lookahead == '*') ADVANCE(30); if (lookahead != 0 && lookahead != '\n' && @@ -448,18 +446,18 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { lookahead != '\\') ADVANCE(31); END_STATE(); case 32: - ACCEPT_TOKEN(aux_sym_string_content_token1); + ACCEPT_TOKEN(sym_string_content); if (lookahead == '/') ADVANCE(29); if (lookahead == '\t' || - (11 <= lookahead && lookahead <= '\r') || + (0x0b <= lookahead && lookahead <= '\r') || lookahead == ' ') ADVANCE(32); if (lookahead != 0 && - lookahead != '\n' && + (lookahead < '\t' || '\r' < lookahead) && lookahead != '"' && lookahead != '\\') ADVANCE(33); END_STATE(); case 33: - ACCEPT_TOKEN(aux_sym_string_content_token1); + ACCEPT_TOKEN(sym_string_content); if (lookahead != 0 && lookahead != '\n' && lookahead != '"' && @@ -531,9 +529,9 @@ static const TSLexMode ts_lex_modes[STATE_COUNT] = { [14] = {.lex_state = 0}, [15] = {.lex_state = 0}, [16] = {.lex_state = 1}, - [17] = {.lex_state = 1}, + [17] = {.lex_state = 0}, [18] = {.lex_state = 1}, - [19] = {.lex_state = 0}, + [19] = {.lex_state = 1}, [20] = {.lex_state = 0}, [21] = {.lex_state = 0}, [22] = {.lex_state = 0}, @@ -546,7 +544,6 @@ static const TSLexMode ts_lex_modes[STATE_COUNT] = { [29] = {.lex_state = 0}, [30] = {.lex_state = 0}, [31] = {.lex_state = 0}, - [32] = {.lex_state = 0}, }; static const uint16_t ts_parse_table[LARGE_STATE_COUNT][SYMBOL_COUNT] = { @@ -567,11 +564,11 @@ static const uint16_t ts_parse_table[LARGE_STATE_COUNT][SYMBOL_COUNT] = { [sym_comment] = ACTIONS(3), }, [1] = { - [sym_document] = STATE(30), + [sym_document] = STATE(31), [sym__value] = STATE(2), - [sym_object] = STATE(8), - [sym_array] = STATE(8), - [sym_string] = STATE(8), + [sym_object] = STATE(10), + [sym_array] = STATE(10), + [sym_string] = STATE(10), [aux_sym_document_repeat1] = STATE(2), [ts_builtin_sym_end] = ACTIONS(5), [anon_sym_LBRACE] = ACTIONS(7), @@ -585,9 +582,9 @@ static const uint16_t ts_parse_table[LARGE_STATE_COUNT][SYMBOL_COUNT] = { }, [2] = { [sym__value] = STATE(3), - [sym_object] = STATE(8), - [sym_array] = STATE(8), - [sym_string] = STATE(8), + [sym_object] = STATE(10), + [sym_array] = STATE(10), + [sym_string] = STATE(10), [aux_sym_document_repeat1] = STATE(3), [ts_builtin_sym_end] = ACTIONS(15), [anon_sym_LBRACE] = ACTIONS(7), @@ -601,9 +598,9 @@ static const uint16_t ts_parse_table[LARGE_STATE_COUNT][SYMBOL_COUNT] = { }, [3] = { [sym__value] = STATE(3), - [sym_object] = STATE(8), - [sym_array] = STATE(8), - [sym_string] = STATE(8), + [sym_object] = STATE(10), + [sym_array] = STATE(10), + [sym_string] = STATE(10), [aux_sym_document_repeat1] = STATE(3), [ts_builtin_sym_end] = ACTIONS(17), [anon_sym_LBRACE] = ACTIONS(19), @@ -615,56 +612,62 @@ static const uint16_t ts_parse_table[LARGE_STATE_COUNT][SYMBOL_COUNT] = { [sym_null] = ACTIONS(28), [sym_comment] = ACTIONS(3), }, + [4] = { + [sym__value] = STATE(22), + [sym_object] = STATE(10), + [sym_array] = STATE(10), + [sym_string] = STATE(10), + [anon_sym_LBRACE] = ACTIONS(7), + [anon_sym_LBRACK] = ACTIONS(9), + [anon_sym_RBRACK] = ACTIONS(31), + [anon_sym_DQUOTE] = ACTIONS(11), + [sym_number] = ACTIONS(13), + [sym_true] = ACTIONS(13), + [sym_false] = ACTIONS(13), + [sym_null] = ACTIONS(13), + [sym_comment] = ACTIONS(3), + }, + [5] = { + [ts_builtin_sym_end] = ACTIONS(33), + [anon_sym_LBRACE] = ACTIONS(33), + [anon_sym_COMMA] = ACTIONS(33), + [anon_sym_RBRACE] = ACTIONS(33), + [anon_sym_COLON] = ACTIONS(33), + [anon_sym_LBRACK] = ACTIONS(33), + [anon_sym_RBRACK] = ACTIONS(33), + [anon_sym_DQUOTE] = ACTIONS(33), + [sym_number] = ACTIONS(33), + [sym_true] = ACTIONS(33), + [sym_false] = ACTIONS(33), + [sym_null] = ACTIONS(33), + [sym_comment] = ACTIONS(3), + }, + [6] = { + [ts_builtin_sym_end] = ACTIONS(35), + [anon_sym_LBRACE] = ACTIONS(35), + [anon_sym_COMMA] = ACTIONS(35), + [anon_sym_RBRACE] = ACTIONS(35), + [anon_sym_COLON] = ACTIONS(35), + [anon_sym_LBRACK] = ACTIONS(35), + [anon_sym_RBRACK] = ACTIONS(35), + [anon_sym_DQUOTE] = ACTIONS(35), + [sym_number] = ACTIONS(35), + [sym_true] = ACTIONS(35), + [sym_false] = ACTIONS(35), + [sym_null] = ACTIONS(35), + [sym_comment] = ACTIONS(3), + }, }; static const uint16_t ts_small_parse_table[] = { [0] = 2, ACTIONS(3), 1, sym_comment, - ACTIONS(31), 12, - ts_builtin_sym_end, - anon_sym_LBRACE, - anon_sym_COMMA, - anon_sym_RBRACE, - anon_sym_COLON, - anon_sym_LBRACK, - anon_sym_RBRACK, - anon_sym_DQUOTE, - sym_number, - sym_true, - sym_false, - sym_null, - [18] = 8, - ACTIONS(3), 1, - sym_comment, - ACTIONS(7), 1, - anon_sym_LBRACE, - ACTIONS(9), 1, - anon_sym_LBRACK, - ACTIONS(11), 1, - anon_sym_DQUOTE, - ACTIONS(33), 1, - anon_sym_RBRACK, - STATE(23), 1, - sym__value, - STATE(8), 3, - sym_object, - sym_array, - sym_string, - ACTIONS(13), 4, - sym_number, - sym_true, - sym_false, - sym_null, - [48] = 2, - ACTIONS(3), 1, - sym_comment, - ACTIONS(35), 12, + ACTIONS(37), 11, ts_builtin_sym_end, anon_sym_LBRACE, anon_sym_COMMA, anon_sym_RBRACE, - anon_sym_COLON, anon_sym_LBRACK, anon_sym_RBRACK, anon_sym_DQUOTE, @@ -672,30 +675,10 @@ static const uint16_t ts_small_parse_table[] = { sym_true, sym_false, sym_null, - [66] = 7, + [17] = 2, ACTIONS(3), 1, sym_comment, - ACTIONS(7), 1, - anon_sym_LBRACE, - ACTIONS(9), 1, - anon_sym_LBRACK, - ACTIONS(11), 1, - anon_sym_DQUOTE, - STATE(28), 1, - sym__value, - STATE(8), 3, - sym_object, - sym_array, - sym_string, - ACTIONS(13), 4, - sym_number, - sym_true, - sym_false, - sym_null, - [93] = 2, - ACTIONS(3), 1, - sym_comment, - ACTIONS(37), 11, + ACTIONS(39), 11, ts_builtin_sym_end, anon_sym_LBRACE, anon_sym_COMMA, @@ -707,10 +690,10 @@ static const uint16_t ts_small_parse_table[] = { sym_true, sym_false, sym_null, - [110] = 2, + [34] = 2, ACTIONS(3), 1, sym_comment, - ACTIONS(39), 11, + ACTIONS(41), 11, ts_builtin_sym_end, anon_sym_LBRACE, anon_sym_COMMA, @@ -722,10 +705,10 @@ static const uint16_t ts_small_parse_table[] = { sym_true, sym_false, sym_null, - [127] = 2, + [51] = 2, ACTIONS(3), 1, sym_comment, - ACTIONS(41), 11, + ACTIONS(43), 11, ts_builtin_sym_end, anon_sym_LBRACE, anon_sym_COMMA, @@ -737,10 +720,10 @@ static const uint16_t ts_small_parse_table[] = { sym_true, sym_false, sym_null, - [144] = 2, + [68] = 2, ACTIONS(3), 1, sym_comment, - ACTIONS(43), 11, + ACTIONS(45), 11, ts_builtin_sym_end, anon_sym_LBRACE, anon_sym_COMMA, @@ -752,10 +735,10 @@ static const uint16_t ts_small_parse_table[] = { sym_true, sym_false, sym_null, - [161] = 2, + [85] = 2, ACTIONS(3), 1, sym_comment, - ACTIONS(45), 11, + ACTIONS(47), 11, ts_builtin_sym_end, anon_sym_LBRACE, anon_sym_COMMA, @@ -767,10 +750,10 @@ static const uint16_t ts_small_parse_table[] = { sym_true, sym_false, sym_null, - [178] = 2, + [102] = 2, ACTIONS(3), 1, sym_comment, - ACTIONS(47), 11, + ACTIONS(49), 11, ts_builtin_sym_end, anon_sym_LBRACE, anon_sym_COMMA, @@ -782,7 +765,7 @@ static const uint16_t ts_small_parse_table[] = { sym_true, sym_false, sym_null, - [195] = 7, + [119] = 7, ACTIONS(3), 1, sym_comment, ACTIONS(7), 1, @@ -793,7 +776,7 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_DQUOTE, STATE(29), 1, sym__value, - STATE(8), 3, + STATE(10), 3, sym_object, sym_array, sym_string, @@ -802,119 +785,122 @@ static const uint16_t ts_small_parse_table[] = { sym_true, sym_false, sym_null, - [222] = 2, + [146] = 7, ACTIONS(3), 1, sym_comment, - ACTIONS(49), 11, - ts_builtin_sym_end, + ACTIONS(7), 1, anon_sym_LBRACE, - anon_sym_COMMA, - anon_sym_RBRACE, + ACTIONS(9), 1, anon_sym_LBRACK, - anon_sym_RBRACK, + ACTIONS(11), 1, anon_sym_DQUOTE, + STATE(28), 1, + sym__value, + STATE(10), 3, + sym_object, + sym_array, + sym_string, + ACTIONS(13), 4, sym_number, sym_true, sym_false, sym_null, - [239] = 5, + [173] = 4, ACTIONS(51), 1, anon_sym_DQUOTE, - ACTIONS(55), 1, + ACTIONS(56), 1, sym_comment, - STATE(18), 1, - aux_sym_string_content_repeat1, - STATE(31), 1, - sym_string_content, + STATE(16), 1, + aux_sym__string_content, ACTIONS(53), 2, - aux_sym_string_content_token1, + sym_string_content, sym_escape_sequence, - [256] = 4, - ACTIONS(55), 1, + [187] = 5, + ACTIONS(3), 1, sym_comment, - ACTIONS(57), 1, + ACTIONS(11), 1, + anon_sym_DQUOTE, + ACTIONS(58), 1, + anon_sym_RBRACE, + STATE(24), 1, + sym_pair, + STATE(30), 1, + sym_string, + [203] = 4, + ACTIONS(56), 1, + sym_comment, + ACTIONS(60), 1, anon_sym_DQUOTE, - STATE(17), 1, - aux_sym_string_content_repeat1, - ACTIONS(59), 2, - aux_sym_string_content_token1, + STATE(16), 1, + aux_sym__string_content, + ACTIONS(62), 2, + sym_string_content, sym_escape_sequence, - [270] = 4, - ACTIONS(55), 1, + [217] = 4, + ACTIONS(56), 1, sym_comment, - ACTIONS(62), 1, + ACTIONS(64), 1, anon_sym_DQUOTE, - STATE(17), 1, - aux_sym_string_content_repeat1, - ACTIONS(64), 2, - aux_sym_string_content_token1, + STATE(18), 1, + aux_sym__string_content, + ACTIONS(66), 2, + sym_string_content, sym_escape_sequence, - [284] = 5, + [231] = 4, ACTIONS(3), 1, sym_comment, ACTIONS(11), 1, anon_sym_DQUOTE, - ACTIONS(66), 1, - anon_sym_RBRACE, - STATE(25), 1, + STATE(27), 1, sym_pair, - STATE(32), 1, + STATE(30), 1, sym_string, - [300] = 4, + [244] = 4, ACTIONS(3), 1, sym_comment, ACTIONS(68), 1, anon_sym_COMMA, ACTIONS(70), 1, anon_sym_RBRACE, - STATE(24), 1, + STATE(25), 1, aux_sym_object_repeat1, - [313] = 4, - ACTIONS(3), 1, - sym_comment, - ACTIONS(11), 1, - anon_sym_DQUOTE, - STATE(27), 1, - sym_pair, - STATE(32), 1, - sym_string, - [326] = 4, + [257] = 4, ACTIONS(3), 1, sym_comment, ACTIONS(72), 1, anon_sym_COMMA, ACTIONS(74), 1, anon_sym_RBRACK, - STATE(26), 1, + STATE(23), 1, aux_sym_array_repeat1, - [339] = 4, + [270] = 4, ACTIONS(3), 1, sym_comment, ACTIONS(72), 1, anon_sym_COMMA, ACTIONS(76), 1, anon_sym_RBRACK, - STATE(22), 1, + STATE(26), 1, aux_sym_array_repeat1, - [352] = 4, + [283] = 4, ACTIONS(3), 1, sym_comment, - ACTIONS(78), 1, + ACTIONS(68), 1, anon_sym_COMMA, - ACTIONS(81), 1, + ACTIONS(78), 1, anon_sym_RBRACE, - STATE(24), 1, + STATE(21), 1, aux_sym_object_repeat1, - [365] = 4, + [296] = 4, ACTIONS(3), 1, sym_comment, - ACTIONS(68), 1, + ACTIONS(80), 1, anon_sym_COMMA, ACTIONS(83), 1, anon_sym_RBRACE, - STATE(20), 1, + STATE(25), 1, aux_sym_object_repeat1, - [378] = 4, + [309] = 4, ACTIONS(3), 1, sym_comment, ACTIONS(85), 1, @@ -923,120 +909,110 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_RBRACK, STATE(26), 1, aux_sym_array_repeat1, - [391] = 2, + [322] = 2, ACTIONS(3), 1, sym_comment, - ACTIONS(81), 2, + ACTIONS(83), 2, anon_sym_COMMA, anon_sym_RBRACE, - [399] = 2, + [330] = 2, ACTIONS(3), 1, sym_comment, ACTIONS(90), 2, anon_sym_COMMA, anon_sym_RBRACE, - [407] = 2, + [338] = 2, ACTIONS(3), 1, sym_comment, ACTIONS(88), 2, anon_sym_COMMA, anon_sym_RBRACK, - [415] = 2, + [346] = 2, ACTIONS(3), 1, sym_comment, ACTIONS(92), 1, - ts_builtin_sym_end, - [422] = 2, + anon_sym_COLON, + [353] = 2, ACTIONS(3), 1, sym_comment, ACTIONS(94), 1, - anon_sym_DQUOTE, - [429] = 2, - ACTIONS(3), 1, - sym_comment, - ACTIONS(96), 1, - anon_sym_COLON, + ts_builtin_sym_end, }; static const uint32_t ts_small_parse_table_map[] = { - [SMALL_STATE(4)] = 0, - [SMALL_STATE(5)] = 18, - [SMALL_STATE(6)] = 48, - [SMALL_STATE(7)] = 66, - [SMALL_STATE(8)] = 93, - [SMALL_STATE(9)] = 110, - [SMALL_STATE(10)] = 127, - [SMALL_STATE(11)] = 144, - [SMALL_STATE(12)] = 161, - [SMALL_STATE(13)] = 178, - [SMALL_STATE(14)] = 195, - [SMALL_STATE(15)] = 222, - [SMALL_STATE(16)] = 239, - [SMALL_STATE(17)] = 256, - [SMALL_STATE(18)] = 270, - [SMALL_STATE(19)] = 284, - [SMALL_STATE(20)] = 300, - [SMALL_STATE(21)] = 313, - [SMALL_STATE(22)] = 326, - [SMALL_STATE(23)] = 339, - [SMALL_STATE(24)] = 352, - [SMALL_STATE(25)] = 365, - [SMALL_STATE(26)] = 378, - [SMALL_STATE(27)] = 391, - [SMALL_STATE(28)] = 399, - [SMALL_STATE(29)] = 407, - [SMALL_STATE(30)] = 415, - [SMALL_STATE(31)] = 422, - [SMALL_STATE(32)] = 429, + [SMALL_STATE(7)] = 0, + [SMALL_STATE(8)] = 17, + [SMALL_STATE(9)] = 34, + [SMALL_STATE(10)] = 51, + [SMALL_STATE(11)] = 68, + [SMALL_STATE(12)] = 85, + [SMALL_STATE(13)] = 102, + [SMALL_STATE(14)] = 119, + [SMALL_STATE(15)] = 146, + [SMALL_STATE(16)] = 173, + [SMALL_STATE(17)] = 187, + [SMALL_STATE(18)] = 203, + [SMALL_STATE(19)] = 217, + [SMALL_STATE(20)] = 231, + [SMALL_STATE(21)] = 244, + [SMALL_STATE(22)] = 257, + [SMALL_STATE(23)] = 270, + [SMALL_STATE(24)] = 283, + [SMALL_STATE(25)] = 296, + [SMALL_STATE(26)] = 309, + [SMALL_STATE(27)] = 322, + [SMALL_STATE(28)] = 330, + [SMALL_STATE(29)] = 338, + [SMALL_STATE(30)] = 346, + [SMALL_STATE(31)] = 353, }; static const TSParseActionEntry ts_parse_actions[] = { [0] = {.entry = {.count = 0, .reusable = false}}, [1] = {.entry = {.count = 1, .reusable = false}}, RECOVER(), [3] = {.entry = {.count = 1, .reusable = true}}, SHIFT_EXTRA(), - [5] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_document, 0), - [7] = {.entry = {.count = 1, .reusable = true}}, SHIFT(19), - [9] = {.entry = {.count = 1, .reusable = true}}, SHIFT(5), - [11] = {.entry = {.count = 1, .reusable = true}}, SHIFT(16), - [13] = {.entry = {.count = 1, .reusable = true}}, SHIFT(8), - [15] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_document, 1), - [17] = {.entry = {.count = 1, .reusable = true}}, REDUCE(aux_sym_document_repeat1, 2), - [19] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym_document_repeat1, 2), SHIFT_REPEAT(19), - [22] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym_document_repeat1, 2), SHIFT_REPEAT(5), - [25] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym_document_repeat1, 2), SHIFT_REPEAT(16), - [28] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym_document_repeat1, 2), SHIFT_REPEAT(8), - [31] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_string, 3), - [33] = {.entry = {.count = 1, .reusable = true}}, SHIFT(12), - [35] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_string, 2), - [37] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym__value, 1), - [39] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_array, 4), - [41] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_object, 2), - [43] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_object, 4), - [45] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_array, 2), - [47] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_array, 3), - [49] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_object, 3), - [51] = {.entry = {.count = 1, .reusable = false}}, SHIFT(6), - [53] = {.entry = {.count = 1, .reusable = true}}, SHIFT(18), - [55] = {.entry = {.count = 1, .reusable = false}}, SHIFT_EXTRA(), - [57] = {.entry = {.count = 1, .reusable = false}}, REDUCE(aux_sym_string_content_repeat1, 2), - [59] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym_string_content_repeat1, 2), SHIFT_REPEAT(17), - [62] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_string_content, 1), - [64] = {.entry = {.count = 1, .reusable = true}}, SHIFT(17), - [66] = {.entry = {.count = 1, .reusable = true}}, SHIFT(10), - [68] = {.entry = {.count = 1, .reusable = true}}, SHIFT(21), - [70] = {.entry = {.count = 1, .reusable = true}}, SHIFT(11), + [5] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_document, 0, 0, 0), + [7] = {.entry = {.count = 1, .reusable = true}}, SHIFT(17), + [9] = {.entry = {.count = 1, .reusable = true}}, SHIFT(4), + [11] = {.entry = {.count = 1, .reusable = true}}, SHIFT(19), + [13] = {.entry = {.count = 1, .reusable = true}}, SHIFT(10), + [15] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_document, 1, 0, 0), + [17] = {.entry = {.count = 1, .reusable = true}}, REDUCE(aux_sym_document_repeat1, 2, 0, 0), + [19] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym_document_repeat1, 2, 0, 0), SHIFT_REPEAT(17), + [22] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym_document_repeat1, 2, 0, 0), SHIFT_REPEAT(4), + [25] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym_document_repeat1, 2, 0, 0), SHIFT_REPEAT(19), + [28] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym_document_repeat1, 2, 0, 0), SHIFT_REPEAT(10), + [31] = {.entry = {.count = 1, .reusable = true}}, SHIFT(13), + [33] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_string, 3, 0, 0), + [35] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_string, 2, 0, 0), + [37] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_object, 3, 0, 0), + [39] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_array, 4, 0, 0), + [41] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_object, 4, 0, 0), + [43] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym__value, 1, 0, 0), + [45] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_object, 2, 0, 0), + [47] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_array, 3, 0, 0), + [49] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_array, 2, 0, 0), + [51] = {.entry = {.count = 1, .reusable = false}}, REDUCE(aux_sym__string_content, 2, 0, 0), + [53] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym__string_content, 2, 0, 0), SHIFT_REPEAT(16), + [56] = {.entry = {.count = 1, .reusable = false}}, SHIFT_EXTRA(), + [58] = {.entry = {.count = 1, .reusable = true}}, SHIFT(11), + [60] = {.entry = {.count = 1, .reusable = false}}, SHIFT(5), + [62] = {.entry = {.count = 1, .reusable = true}}, SHIFT(16), + [64] = {.entry = {.count = 1, .reusable = false}}, SHIFT(6), + [66] = {.entry = {.count = 1, .reusable = true}}, SHIFT(18), + [68] = {.entry = {.count = 1, .reusable = true}}, SHIFT(20), + [70] = {.entry = {.count = 1, .reusable = true}}, SHIFT(9), [72] = {.entry = {.count = 1, .reusable = true}}, SHIFT(14), - [74] = {.entry = {.count = 1, .reusable = true}}, SHIFT(9), - [76] = {.entry = {.count = 1, .reusable = true}}, SHIFT(13), - [78] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym_object_repeat1, 2), SHIFT_REPEAT(21), - [81] = {.entry = {.count = 1, .reusable = true}}, REDUCE(aux_sym_object_repeat1, 2), - [83] = {.entry = {.count = 1, .reusable = true}}, SHIFT(15), - [85] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym_array_repeat1, 2), SHIFT_REPEAT(14), - [88] = {.entry = {.count = 1, .reusable = true}}, REDUCE(aux_sym_array_repeat1, 2), - [90] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_pair, 3, .production_id = 1), - [92] = {.entry = {.count = 1, .reusable = true}}, ACCEPT_INPUT(), - [94] = {.entry = {.count = 1, .reusable = true}}, SHIFT(4), - [96] = {.entry = {.count = 1, .reusable = true}}, SHIFT(7), + [74] = {.entry = {.count = 1, .reusable = true}}, SHIFT(12), + [76] = {.entry = {.count = 1, .reusable = true}}, SHIFT(8), + [78] = {.entry = {.count = 1, .reusable = true}}, SHIFT(7), + [80] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym_object_repeat1, 2, 0, 0), SHIFT_REPEAT(20), + [83] = {.entry = {.count = 1, .reusable = true}}, REDUCE(aux_sym_object_repeat1, 2, 0, 0), + [85] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym_array_repeat1, 2, 0, 0), SHIFT_REPEAT(14), + [88] = {.entry = {.count = 1, .reusable = true}}, REDUCE(aux_sym_array_repeat1, 2, 0, 0), + [90] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_pair, 3, 0, 1), + [92] = {.entry = {.count = 1, .reusable = true}}, SHIFT(15), + [94] = {.entry = {.count = 1, .reusable = true}}, ACCEPT_INPUT(), }; #ifdef __cplusplus @@ -1050,7 +1026,7 @@ extern "C" { #define TS_PUBLIC __attribute__((visibility("default"))) #endif -TS_PUBLIC const TSLanguage *tree_sitter_json() { +TS_PUBLIC const TSLanguage *tree_sitter_json(void) { static const TSLanguage language = { .version = LANGUAGE_VERSION, .symbol_count = SYMBOL_COUNT, diff --git a/src/tree_sitter/parser.h b/src/tree_sitter/parser.h index 17b4fde..17f0e94 100644 --- a/src/tree_sitter/parser.h +++ b/src/tree_sitter/parser.h @@ -86,6 +86,11 @@ typedef union { } entry; } TSParseActionEntry; +typedef struct { + int32_t start; + int32_t end; +} TSCharacterRange; + struct TSLanguage { uint32_t version; uint32_t symbol_count; @@ -125,6 +130,24 @@ struct TSLanguage { const TSStateId *primary_state_ids; }; +static inline bool set_contains(TSCharacterRange *ranges, uint32_t len, int32_t lookahead) { + uint32_t index = 0; + uint32_t size = len - index; + while (size > 1) { + uint32_t half_size = size / 2; + uint32_t mid_index = index + half_size; + TSCharacterRange *range = &ranges[mid_index]; + if (lookahead >= range->start && lookahead <= range->end) { + return true; + } else if (lookahead > range->end) { + index = mid_index; + } + size -= half_size; + } + TSCharacterRange *range = &ranges[index]; + return (lookahead >= range->start && lookahead <= range->end); +} + /* * Lexer Macros */ @@ -154,6 +177,17 @@ struct TSLanguage { goto next_state; \ } +#define ADVANCE_MAP(...) \ + { \ + static const uint16_t map[] = { __VA_ARGS__ }; \ + for (uint32_t i = 0; i < sizeof(map) / sizeof(map[0]); i += 2) { \ + if (map[i] == lookahead) { \ + state = map[i + 1]; \ + goto next_state; \ + } \ + } \ + } + #define SKIP(state_value) \ { \ skip = true; \ @@ -203,14 +237,15 @@ struct TSLanguage { } \ }} -#define REDUCE(symbol_val, child_count_val, ...) \ - {{ \ - .reduce = { \ - .type = TSParseActionTypeReduce, \ - .symbol = symbol_val, \ - .child_count = child_count_val, \ - __VA_ARGS__ \ - }, \ +#define REDUCE(symbol_name, children, precedence, prod_id) \ + {{ \ + .reduce = { \ + .type = TSParseActionTypeReduce, \ + .symbol = symbol_name, \ + .child_count = children, \ + .dynamic_precedence = precedence, \ + .production_id = prod_id \ + }, \ }} #define RECOVER() \ diff --git a/test/corpus/main.txt b/test/corpus/main.txt index ec3c52f..45da5cc 100644 --- a/test/corpus/main.txt +++ b/test/corpus/main.txt @@ -53,14 +53,14 @@ String content (string (string_content)) (string - (string_content - (escape_sequence))) + (string_content) + (escape_sequence)) (string - (string_content - (escape_sequence))) + (string_content) + (escape_sequence)) (string - (string_content - (escape_sequence))) + (string_content) + (escape_sequence)) (string (string_content)) (string @@ -130,7 +130,7 @@ Comments =========================================== Multiple top-level objects -========================================== +=========================================== {} {}