From 0879cdbbb6415333be1dc192767e0873f689d3f7 Mon Sep 17 00:00:00 2001 From: Elias Aebi Date: Sat, 7 Oct 2023 12:11:09 +0200 Subject: [PATCH] language-json --- CMakeLists.txt | 1 + language-json/CMakeLists.txt | 17 + language-json/grammars/tree-sitter-json.cc | 80 ++ language-json/grammars/tree-sitter-json.cson | 76 ++ language-json/meson.build | 14 + language-json/vendor/tree-sitter-json/LICENSE | 21 + .../vendor/tree-sitter-json/src/parser.c | 731 ++++++++++++++++++ .../tree-sitter-json/src/tree_sitter/parser.h | 217 ++++++ meson.build | 1 + 9 files changed, 1158 insertions(+) create mode 100644 language-json/CMakeLists.txt create mode 100644 language-json/grammars/tree-sitter-json.cc create mode 100644 language-json/grammars/tree-sitter-json.cson create mode 100644 language-json/meson.build create mode 100644 language-json/vendor/tree-sitter-json/LICENSE create mode 100644 language-json/vendor/tree-sitter-json/src/parser.c create mode 100644 language-json/vendor/tree-sitter-json/src/tree_sitter/parser.h diff --git a/CMakeLists.txt b/CMakeLists.txt index da6d756..7411790 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,5 +11,6 @@ add_subdirectory(language-css) add_subdirectory(language-go) add_subdirectory(language-html) add_subdirectory(language-javascript) +add_subdirectory(language-json) add_subdirectory(language-python) add_subdirectory(language-rust) diff --git a/language-json/CMakeLists.txt b/language-json/CMakeLists.txt new file mode 100644 index 0000000..d4b3ca6 --- /dev/null +++ b/language-json/CMakeLists.txt @@ -0,0 +1,17 @@ +cmake_minimum_required(VERSION 3.13) +project(language-json) + +add_library(tree-sitter-json STATIC) +target_compile_features(tree-sitter-json PRIVATE c_std_99) +target_sources(tree-sitter-json PRIVATE + vendor/tree-sitter-json/src/parser.c +) +target_include_directories(tree-sitter-json PRIVATE + vendor/tree-sitter-json/src +) + +add_library(language-json STATIC) +target_link_libraries(language-json atom tree-sitter-json) +target_sources(language-json PRIVATE + grammars/tree-sitter-json.cc +) diff --git a/language-json/grammars/tree-sitter-json.cc b/language-json/grammars/tree-sitter-json.cc new file mode 100644 index 0000000..f3d4b59 --- /dev/null +++ b/language-json/grammars/tree-sitter-json.cc @@ -0,0 +1,80 @@ +#include + +extern "C" const TSLanguage *tree_sitter_json(); + +using namespace TreeSitterGrammarDSL; + +extern "C" TreeSitterGrammar *atom_language_json() { + TreeSitterGrammar *grammar = new TreeSitterGrammar( + "JSON", + "source.json", + tree_sitter_json() + ); + + grammar->setFileTypes( + "avsc", + "babelrc", + "bowerrc", + "composer.lock", + "geojson", + "gltf", + "htmlhintrc", + "ipynb", + "jscsrc", + "jshintrc", + "jslintrc", + "json", + "jsonl", + "jsonld", + "languagebabel", + "ldj", + "ldjson", + "Pipfile.lock", + "schema", + "stylintrc", + "template", + "tern-config", + "tern-project", + "tfstate", + "tfstate.backup", + "topojson", + "webapp", + "webmanifest" + ); + + grammar->setIncreaseIndentPattern(u"^.*(\\{[^}]*|\\[[^\\]]*)$"); + grammar->setDecreaseIndentPattern(u"^\\s*[}\\]],?\\s*$"); + + grammar->setScopes( + scope("value", "source.json"), + + scope("object", "meta.structure.dictionary.json"), + + scope("string", "string.quoted.double"), + + scope("string_content", array( + match(u"^http:\\/\\/", "markup.underline.link.http.hyperlink"), + match(u"^https:\\/\\/","markup.underline.link.https.hyperlink") + )), + + scope("pair > string:nth-child(0)", "string.quoted.double.dictionary.key.json"), + + scope("escape_sequence", "constant.character.escape"), + + scope("number", "constant.numeric"), + scope("true", "constant.language"), + scope("false", "constant.language"), + scope("null", "constant.language"), + + scope("\"{\"", "punctuation.definition.dictionary.begin"), + scope("\"}\"", "punctuation.definition.dictionary.end"), + scope("\":\"", "punctuation.separator.dictionary.key-value"), + scope("object > \",\"", "punctuation.separator.dictionary.pair"), + scope("array > \",\"", "punctuation.separator.array"), + scope("\"[\"", "punctuation.definition.array.begin"), + scope("\"]\"", "punctuation.definition.array.end"), + scope("\"\\\"\"", "punctuation.definition.string.json") + ); + + return grammar; +} diff --git a/language-json/grammars/tree-sitter-json.cson b/language-json/grammars/tree-sitter-json.cson new file mode 100644 index 0000000..7381c84 --- /dev/null +++ b/language-json/grammars/tree-sitter-json.cson @@ -0,0 +1,76 @@ +name: 'JSON' +scopeName: 'source.json' +type: 'tree-sitter' +parser: 'tree-sitter-json' + +fileTypes: [ + 'avsc' + 'babelrc' + 'bowerrc' + 'composer.lock' + 'geojson' + 'gltf' + 'htmlhintrc' + 'ipynb' + 'jscsrc' + 'jshintrc' + 'jslintrc' + 'json' + 'jsonl' + 'jsonld' + 'languagebabel' + 'ldj' + 'ldjson' + 'Pipfile.lock' + 'schema' + 'stylintrc' + 'template' + 'tern-config' + 'tern-project' + 'tfstate' + 'tfstate.backup' + 'topojson' + 'webapp' + 'webmanifest' +] + +folds: [ + { + start: {index: 0, type: '{'} + end: {index: -1, type: '}'} + } + { + start: {index: 0, type: '['} + end: {index: -1, type: ']'} + } +] + +scopes: + 'value': 'source.json' + + 'object': 'meta.structure.dictionary.json' + + 'string': 'string.quoted.double' + + 'string_content': [ + { match: "^http:\/\/", scopes: 'markup.underline.link.http.hyperlink' } + { match: "^https:\/\/", scopes: 'markup.underline.link.https.hyperlink' } + ] + + 'pair > string:nth-child(0)': 'string.quoted.double.dictionary.key.json' + + 'escape_sequence': 'constant.character.escape' + + 'number': 'constant.numeric' + 'true': 'constant.language' + 'false': 'constant.language' + 'null': 'constant.language' + + '"{"': 'punctuation.definition.dictionary.begin' + '"}"': 'punctuation.definition.dictionary.end' + '":"': 'punctuation.separator.dictionary.key-value' + 'object > ","': 'punctuation.separator.dictionary.pair' + 'array > ","': 'punctuation.separator.array' + '"["': 'punctuation.definition.array.begin' + '"]"': 'punctuation.definition.array.end' + '"\\""': 'punctuation.definition.string.json' diff --git a/language-json/meson.build b/language-json/meson.build new file mode 100644 index 0000000..120344a --- /dev/null +++ b/language-json/meson.build @@ -0,0 +1,14 @@ +language_json = declare_dependency( + link_with: static_library( + 'language-json', + 'grammars/tree-sitter-json.cc', + link_with: static_library( + 'tree-sitter-json', + 'vendor/tree-sitter-json/src/parser.c', + include_directories: include_directories( + 'vendor/tree-sitter-json/src', + ), + ), + dependencies: [atom], + ) +) diff --git a/language-json/vendor/tree-sitter-json/LICENSE b/language-json/vendor/tree-sitter-json/LICENSE new file mode 100644 index 0000000..4b52d19 --- /dev/null +++ b/language-json/vendor/tree-sitter-json/LICENSE @@ -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. diff --git a/language-json/vendor/tree-sitter-json/src/parser.c b/language-json/vendor/tree-sitter-json/src/parser.c new file mode 100644 index 0000000..eb0e893 --- /dev/null +++ b/language-json/vendor/tree-sitter-json/src/parser.c @@ -0,0 +1,731 @@ +#include + +#if defined(__GNUC__) || defined(__clang__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wmissing-field-initializers" +#endif + +#define LANGUAGE_VERSION 10 +#define STATE_COUNT 31 +#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 + +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 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, + }, + [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[] = { + [1] = {.index = 0, .length = 2}, +}; + +static const TSFieldMapEntry ts_field_map_entries[] = { + [0] = + {field_key, 0}, + {field_value, 2}, +}; + +static TSSymbol ts_alias_sequences[2][MAX_ALIAS_SEQUENCE_LENGTH] = { + [0] = {0}, +}; + +static bool ts_lex(TSLexer *lexer, TSStateId state) { + START_LEXER(); + eof = lookahead == 0; + 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(32); + 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(34); + 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(30); + 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(33); + if (('1' <= lookahead && lookahead <= '9')) ADVANCE(34); + END_STATE(); + case 4: + if (lookahead == 'a') ADVANCE(7); + END_STATE(); + case 5: + if (lookahead == 'e') ADVANCE(40); + END_STATE(); + case 6: + if (lookahead == 'e') ADVANCE(41); + END_STATE(); + case 7: + if (lookahead == 'l') ADVANCE(11); + END_STATE(); + case 8: + if (lookahead == 'l') ADVANCE(42); + 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(38); + END_STATE(); + case 15: + if (lookahead == '0' || + lookahead == '1') ADVANCE(35); + END_STATE(); + case 16: + if (lookahead == '"' || + lookahead == '/' || + lookahead == '\\' || + lookahead == 'b' || + lookahead == 'n' || + lookahead == 'r' || + lookahead == 't' || + lookahead == 'u') ADVANCE(31); + END_STATE(); + case 17: + if (('0' <= lookahead && lookahead <= '7')) ADVANCE(37); + END_STATE(); + case 18: + if (('0' <= lookahead && lookahead <= '9')) ADVANCE(36); + END_STATE(); + case 19: + if (('0' <= lookahead && lookahead <= '9')) ADVANCE(38); + END_STATE(); + case 20: + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'F') || + ('a' <= lookahead && lookahead <= 'f')) ADVANCE(39); + 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(32); + 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(34); + 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); + END_STATE(); + case 31: + ACCEPT_TOKEN(sym_escape_sequence); + END_STATE(); + case 32: + 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 33: + ACCEPT_TOKEN(sym_number); + if (lookahead == '.') ADVANCE(36); + if (lookahead == 'E' || + lookahead == 'e') ADVANCE(14); + END_STATE(); + case 34: + ACCEPT_TOKEN(sym_number); + if (lookahead == '.') ADVANCE(36); + if (lookahead == 'E' || + lookahead == 'e') ADVANCE(14); + if (('0' <= lookahead && lookahead <= '9')) ADVANCE(34); + END_STATE(); + case 35: + ACCEPT_TOKEN(sym_number); + if (lookahead == '0' || + lookahead == '1') 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 (('0' <= lookahead && lookahead <= '7')) ADVANCE(37); + END_STATE(); + case 38: + ACCEPT_TOKEN(sym_number); + if (('0' <= lookahead && lookahead <= '9')) ADVANCE(38); + END_STATE(); + case 39: + ACCEPT_TOKEN(sym_number); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'F') || + ('a' <= lookahead && lookahead <= 'f')) ADVANCE(39); + END_STATE(); + case 40: + ACCEPT_TOKEN(sym_true); + END_STATE(); + case 41: + ACCEPT_TOKEN(sym_false); + END_STATE(); + case 42: + 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 = 1}, + [10] = {.lex_state = 0}, + [11] = {.lex_state = 0}, + [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}, +}; + +static uint16_t ts_parse_table[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(30), + [sym__value] = STATE(27), + [sym_object] = STATE(27), + [sym_array] = STATE(27), + [sym_string] = STATE(27), + [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), + }, + [2] = { + [sym__value] = STATE(18), + [sym_object] = STATE(18), + [sym_array] = STATE(18), + [sym_string] = STATE(18), + [anon_sym_LBRACE] = ACTIONS(3), + [anon_sym_LBRACK] = ACTIONS(5), + [anon_sym_RBRACK] = ACTIONS(11), + [anon_sym_DQUOTE] = ACTIONS(7), + [sym_number] = ACTIONS(13), + [sym_true] = ACTIONS(13), + [sym_false] = ACTIONS(13), + [sym_null] = ACTIONS(13), + }, + [3] = { + [sym__value] = STATE(26), + [sym_object] = STATE(26), + [sym_array] = STATE(26), + [sym_string] = STATE(26), + [anon_sym_LBRACE] = ACTIONS(3), + [anon_sym_LBRACK] = ACTIONS(5), + [anon_sym_DQUOTE] = ACTIONS(7), + [sym_number] = ACTIONS(15), + [sym_true] = ACTIONS(15), + [sym_false] = ACTIONS(15), + [sym_null] = ACTIONS(15), + }, + [4] = { + [sym__value] = STATE(25), + [sym_object] = STATE(25), + [sym_array] = STATE(25), + [sym_string] = STATE(25), + [anon_sym_LBRACE] = ACTIONS(3), + [anon_sym_LBRACK] = ACTIONS(5), + [anon_sym_DQUOTE] = ACTIONS(7), + [sym_number] = ACTIONS(17), + [sym_true] = ACTIONS(17), + [sym_false] = ACTIONS(17), + [sym_null] = ACTIONS(17), + }, + [5] = { + [ts_builtin_sym_end] = ACTIONS(19), + [anon_sym_COMMA] = ACTIONS(19), + [anon_sym_RBRACE] = ACTIONS(19), + [anon_sym_COLON] = ACTIONS(19), + [anon_sym_RBRACK] = ACTIONS(19), + }, + [6] = { + [sym_pair] = STATE(23), + [sym_string] = STATE(29), + [anon_sym_RBRACE] = ACTIONS(21), + [anon_sym_DQUOTE] = ACTIONS(7), + [sym_number] = ACTIONS(23), + }, + [7] = { + [sym_string_content] = STATE(28), + [aux_sym_string_content_repeat1] = STATE(9), + [anon_sym_DQUOTE] = ACTIONS(25), + [aux_sym_string_content_token1] = ACTIONS(27), + [sym_escape_sequence] = ACTIONS(27), + }, + [8] = { + [ts_builtin_sym_end] = ACTIONS(29), + [anon_sym_COMMA] = ACTIONS(29), + [anon_sym_RBRACE] = ACTIONS(29), + [anon_sym_COLON] = ACTIONS(29), + [anon_sym_RBRACK] = ACTIONS(29), + }, + [9] = { + [aux_sym_string_content_repeat1] = STATE(17), + [anon_sym_DQUOTE] = ACTIONS(31), + [aux_sym_string_content_token1] = ACTIONS(33), + [sym_escape_sequence] = ACTIONS(33), + }, + [10] = { + [ts_builtin_sym_end] = ACTIONS(35), + [anon_sym_COMMA] = ACTIONS(35), + [anon_sym_RBRACE] = ACTIONS(35), + [anon_sym_RBRACK] = ACTIONS(35), + }, + [11] = { + [ts_builtin_sym_end] = ACTIONS(37), + [anon_sym_COMMA] = ACTIONS(37), + [anon_sym_RBRACE] = ACTIONS(37), + [anon_sym_RBRACK] = ACTIONS(37), + }, + [12] = { + [ts_builtin_sym_end] = ACTIONS(39), + [anon_sym_COMMA] = ACTIONS(39), + [anon_sym_RBRACE] = ACTIONS(39), + [anon_sym_RBRACK] = ACTIONS(39), + }, + [13] = { + [sym_pair] = STATE(24), + [sym_string] = STATE(29), + [anon_sym_DQUOTE] = ACTIONS(7), + [sym_number] = ACTIONS(23), + }, + [14] = { + [ts_builtin_sym_end] = ACTIONS(41), + [anon_sym_COMMA] = ACTIONS(41), + [anon_sym_RBRACE] = ACTIONS(41), + [anon_sym_RBRACK] = ACTIONS(41), + }, + [15] = { + [ts_builtin_sym_end] = ACTIONS(43), + [anon_sym_COMMA] = ACTIONS(43), + [anon_sym_RBRACE] = ACTIONS(43), + [anon_sym_RBRACK] = ACTIONS(43), + }, + [16] = { + [ts_builtin_sym_end] = ACTIONS(45), + [anon_sym_COMMA] = ACTIONS(45), + [anon_sym_RBRACE] = ACTIONS(45), + [anon_sym_RBRACK] = ACTIONS(45), + }, + [17] = { + [aux_sym_string_content_repeat1] = STATE(17), + [anon_sym_DQUOTE] = ACTIONS(47), + [aux_sym_string_content_token1] = ACTIONS(49), + [sym_escape_sequence] = ACTIONS(49), + }, + [18] = { + [aux_sym_array_repeat1] = STATE(22), + [anon_sym_COMMA] = ACTIONS(52), + [anon_sym_RBRACK] = ACTIONS(54), + }, + [19] = { + [aux_sym_array_repeat1] = STATE(19), + [anon_sym_COMMA] = ACTIONS(56), + [anon_sym_RBRACK] = ACTIONS(59), + }, + [20] = { + [aux_sym_object_repeat1] = STATE(20), + [anon_sym_COMMA] = ACTIONS(61), + [anon_sym_RBRACE] = ACTIONS(64), + }, + [21] = { + [aux_sym_object_repeat1] = STATE(20), + [anon_sym_COMMA] = ACTIONS(66), + [anon_sym_RBRACE] = ACTIONS(68), + }, + [22] = { + [aux_sym_array_repeat1] = STATE(19), + [anon_sym_COMMA] = ACTIONS(52), + [anon_sym_RBRACK] = ACTIONS(70), + }, + [23] = { + [aux_sym_object_repeat1] = STATE(21), + [anon_sym_COMMA] = ACTIONS(66), + [anon_sym_RBRACE] = ACTIONS(72), + }, + [24] = { + [anon_sym_COMMA] = ACTIONS(64), + [anon_sym_RBRACE] = ACTIONS(64), + }, + [25] = { + [anon_sym_COMMA] = ACTIONS(74), + [anon_sym_RBRACE] = ACTIONS(74), + }, + [26] = { + [anon_sym_COMMA] = ACTIONS(59), + [anon_sym_RBRACK] = ACTIONS(59), + }, + [27] = { + [ts_builtin_sym_end] = ACTIONS(76), + }, + [28] = { + [anon_sym_DQUOTE] = ACTIONS(78), + }, + [29] = { + [anon_sym_COLON] = ACTIONS(80), + }, + [30] = { + [ts_builtin_sym_end] = ACTIONS(82), + }, +}; + +static TSParseActionEntry ts_parse_actions[] = { + [0] = {.count = 0, .reusable = false}, + [1] = {.count = 1, .reusable = false}, RECOVER(), + [3] = {.count = 1, .reusable = true}, SHIFT(6), + [5] = {.count = 1, .reusable = true}, SHIFT(2), + [7] = {.count = 1, .reusable = true}, SHIFT(7), + [9] = {.count = 1, .reusable = true}, SHIFT(27), + [11] = {.count = 1, .reusable = true}, SHIFT(11), + [13] = {.count = 1, .reusable = true}, SHIFT(18), + [15] = {.count = 1, .reusable = true}, SHIFT(26), + [17] = {.count = 1, .reusable = true}, SHIFT(25), + [19] = {.count = 1, .reusable = true}, REDUCE(sym_string, 2), + [21] = {.count = 1, .reusable = true}, SHIFT(15), + [23] = {.count = 1, .reusable = true}, SHIFT(29), + [25] = {.count = 1, .reusable = false}, SHIFT(5), + [27] = {.count = 1, .reusable = true}, SHIFT(9), + [29] = {.count = 1, .reusable = true}, REDUCE(sym_string, 3), + [31] = {.count = 1, .reusable = false}, REDUCE(sym_string_content, 1), + [33] = {.count = 1, .reusable = true}, SHIFT(17), + [35] = {.count = 1, .reusable = true}, REDUCE(sym_object, 4), + [37] = {.count = 1, .reusable = true}, REDUCE(sym_array, 2), + [39] = {.count = 1, .reusable = true}, REDUCE(sym_array, 4), + [41] = {.count = 1, .reusable = true}, REDUCE(sym_object, 3), + [43] = {.count = 1, .reusable = true}, REDUCE(sym_object, 2), + [45] = {.count = 1, .reusable = true}, REDUCE(sym_array, 3), + [47] = {.count = 1, .reusable = false}, REDUCE(aux_sym_string_content_repeat1, 2), + [49] = {.count = 2, .reusable = true}, REDUCE(aux_sym_string_content_repeat1, 2), SHIFT_REPEAT(17), + [52] = {.count = 1, .reusable = true}, SHIFT(3), + [54] = {.count = 1, .reusable = true}, SHIFT(16), + [56] = {.count = 2, .reusable = true}, REDUCE(aux_sym_array_repeat1, 2), SHIFT_REPEAT(3), + [59] = {.count = 1, .reusable = true}, REDUCE(aux_sym_array_repeat1, 2), + [61] = {.count = 2, .reusable = true}, REDUCE(aux_sym_object_repeat1, 2), SHIFT_REPEAT(13), + [64] = {.count = 1, .reusable = true}, REDUCE(aux_sym_object_repeat1, 2), + [66] = {.count = 1, .reusable = true}, SHIFT(13), + [68] = {.count = 1, .reusable = true}, SHIFT(10), + [70] = {.count = 1, .reusable = true}, SHIFT(12), + [72] = {.count = 1, .reusable = true}, SHIFT(14), + [74] = {.count = 1, .reusable = true}, REDUCE(sym_pair, 3, .production_id = 1), + [76] = {.count = 1, .reusable = true}, REDUCE(sym_document, 1), + [78] = {.count = 1, .reusable = true}, SHIFT(8), + [80] = {.count = 1, .reusable = true}, SHIFT(4), + [82] = {.count = 1, .reusable = true}, ACCEPT_INPUT(), +}; + +#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, + .symbol_metadata = ts_symbol_metadata, + .parse_table = (const unsigned short *)ts_parse_table, + .parse_actions = ts_parse_actions, + .lex_modes = ts_lex_modes, + .symbol_names = ts_symbol_names, + .alias_sequences = (const TSSymbol *)ts_alias_sequences, + .field_count = FIELD_COUNT, + .field_names = ts_field_names, + .field_map_slices = (const TSFieldMapSlice *)ts_field_map_slices, + .field_map_entries = (const TSFieldMapEntry *)ts_field_map_entries, + .max_alias_sequence_length = MAX_ALIAS_SEQUENCE_LENGTH, + .lex_fn = ts_lex, + .external_token_count = EXTERNAL_TOKEN_COUNT, + }; + return &language; +} diff --git a/language-json/vendor/tree-sitter-json/src/tree_sitter/parser.h b/language-json/vendor/tree-sitter-json/src/tree_sitter/parser.h new file mode 100644 index 0000000..ab7d6e3 --- /dev/null +++ b/language-json/vendor/tree-sitter-json/src/tree_sitter/parser.h @@ -0,0 +1,217 @@ +#ifndef TREE_SITTER_PARSER_H_ +#define TREE_SITTER_PARSER_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include + +#define ts_builtin_sym_error ((TSSymbol)-1) +#define ts_builtin_sym_end 0 +#define TREE_SITTER_SERIALIZATION_BUFFER_SIZE 1024 + +#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 uint16_t TSStateId; + +typedef struct { + bool visible : 1; + bool named : 1; +} 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 struct { + union { + struct { + TSStateId state; + bool extra : 1; + bool repetition : 1; + }; + struct { + TSSymbol symbol; + int16_t dynamic_precedence; + uint8_t child_count; + uint8_t production_id; + }; + } params; + TSParseActionType type : 4; +} TSParseAction; + +typedef struct { + uint16_t lex_state; + uint16_t external_lex_state; +} TSLexMode; + +typedef union { + TSParseAction action; + struct { + uint8_t count; + bool reusable : 1; + }; +} TSParseActionEntry; + +struct TSLanguage { + uint32_t version; + uint32_t symbol_count; + uint32_t alias_count; + uint32_t token_count; + uint32_t external_token_count; + const char **symbol_names; + const TSSymbolMetadata *symbol_metadata; + const uint16_t *parse_table; + const TSParseActionEntry *parse_actions; + const TSLexMode *lex_modes; + const TSSymbol *alias_sequences; + uint16_t max_alias_sequence_length; + 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; + uint32_t field_count; + const TSFieldMapSlice *field_map_slices; + const TSFieldMapEntry *field_map_entries; + const char **field_names; +}; + +/* + * 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 STATE(id) id + +#define ACTIONS(id) id + +#define SHIFT(state_value) \ + { \ + { \ + .type = TSParseActionTypeShift, \ + .params = {.state = state_value}, \ + } \ + } + +#define SHIFT_REPEAT(state_value) \ + { \ + { \ + .type = TSParseActionTypeShift, \ + .params = { \ + .state = state_value, \ + .repetition = true \ + }, \ + } \ + } + +#define RECOVER() \ + { \ + { .type = TSParseActionTypeRecover } \ + } + +#define SHIFT_EXTRA() \ + { \ + { \ + .type = TSParseActionTypeShift, \ + .params = {.extra = true} \ + } \ + } + +#define REDUCE(symbol_val, child_count_val, ...) \ + { \ + { \ + .type = TSParseActionTypeReduce, \ + .params = { \ + .symbol = symbol_val, \ + .child_count = child_count_val, \ + __VA_ARGS__ \ + } \ + } \ + } + +#define ACCEPT_INPUT() \ + { \ + { .type = TSParseActionTypeAccept } \ + } + +#ifdef __cplusplus +} +#endif + +#endif // TREE_SITTER_PARSER_H_ diff --git a/meson.build b/meson.build index d699a6f..e857a71 100644 --- a/meson.build +++ b/meson.build @@ -9,6 +9,7 @@ subdir('language-css') subdir('language-go') subdir('language-html') subdir('language-javascript') +subdir('language-json') subdir('language-python') subdir('language-rust')