commit 69a6f0444e0c52384d8b252e1c226565eec72c4f Author: Fabian Stamm Date: Tue Oct 1 23:48:00 2024 +0200 First Commit diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..f363cc5 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,39 @@ +root = true + +[*] +charset = utf-8 + +[*.{json,toml,yml,gyp}] +indent_style = space +indent_size = 2 + +[*.js] +indent_style = space +indent_size = 2 + +[*.{c,cc,h}] +indent_style = space +indent_size = 4 + +[*.rs] +indent_style = space +indent_size = 4 + +[*.{py,pyi}] +indent_style = space +indent_size = 4 + +[*.swift] +indent_style = space +indent_size = 4 + +[*.go] +indent_style = tab +indent_size = 8 + +[Makefile] +indent_style = tab +indent_size = 8 + +[parser.c] +indent_size = 2 diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..4cb1058 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,11 @@ +* text=auto eol=lf + +src/*.json linguist-generated +src/parser.c linguist-generated +src/tree_sitter/* linguist-generated + +bindings/** linguist-generated +binding.gyp linguist-generated +setup.py linguist-generated +Makefile linguist-generated +Package.swift linguist-generated diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..dd5cc84 --- /dev/null +++ b/.gitignore @@ -0,0 +1,39 @@ +# Rust artifacts +Cargo.lock +target/ + +# Node artifacts +build/ +prebuilds/ +node_modules/ +*.tgz + +# Swift artifacts +.build/ +Package.resolved + +# Go artifacts +go.sum +_obj/ + +# Python artifacts +.venv/ +dist/ +*.egg-info +*.whl + +# C artifacts +*.a +*.so +*.so.* +*.dylib +*.dll +*.pc + +# Example dirs +/examples/*/ + +# Grammar volatiles +*.wasm +*.obj +*.o diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..f053e39 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,26 @@ +[package] +name = "tree-sitter-jrpc" +description = "Jrpc grammar for tree-sitter" +version = "0.0.1" +license = "MIT" +readme = "README.md" +keywords = ["incremental", "parsing", "tree-sitter", "jrpc"] +categories = ["parsing", "text-editors"] +repository = "https://git.hibas.dev/hibas123/tree-sitter-jrpc" +edition = "2021" +autoexamples = false + +build = "bindings/rust/build.rs" +include = ["bindings/rust/*", "grammar.js", "queries/*", "src/*"] + +[lib] +path = "bindings/rust/lib.rs" + +[dependencies] +tree-sitter-language = "0.1" + +[dev-dependencies] +tree-sitter = { version = "0.22" } + +[build-dependencies] +cc = "1.0.87" diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..88f520d --- /dev/null +++ b/Makefile @@ -0,0 +1,114 @@ +ifeq ($(OS),Windows_NT) +$(error Windows is not supported) +endif + +VERSION := 0.0.1 + +LANGUAGE_NAME := tree-sitter-jrpc + +# repository +SRC_DIR := src + +PARSER_REPO_URL := $(shell git -C $(SRC_DIR) remote get-url origin 2>/dev/null) + +ifeq ($(PARSER_URL),) + PARSER_URL := $(subst .git,,$(PARSER_REPO_URL)) +ifeq ($(shell echo $(PARSER_URL) | grep '^[a-z][-+.0-9a-z]*://'),) + PARSER_URL := $(subst :,/,$(PARSER_URL)) + PARSER_URL := $(subst git@,https://,$(PARSER_URL)) +endif +endif + +TS ?= tree-sitter + +# install directory layout +PREFIX ?= /usr/local +INCLUDEDIR ?= $(PREFIX)/include +LIBDIR ?= $(PREFIX)/lib +PCLIBDIR ?= $(LIBDIR)/pkgconfig + +# source/object files +PARSER := $(SRC_DIR)/parser.c +EXTRAS := $(filter-out $(PARSER),$(wildcard $(SRC_DIR)/*.c)) +OBJS := $(patsubst %.c,%.o,$(PARSER) $(EXTRAS)) + +# flags +ARFLAGS ?= rcs +override CFLAGS += -I$(SRC_DIR) -std=c11 -fPIC + +# ABI versioning +SONAME_MAJOR := $(word 1,$(subst ., ,$(VERSION))) +SONAME_MINOR := $(shell sed -n 's/#define LANGUAGE_VERSION //p' $(PARSER)) + +# OS-specific bits +ifeq ($(shell uname),Darwin) + SOEXT = dylib + SOEXTVER_MAJOR = $(SONAME_MAJOR).$(SOEXT) + SOEXTVER = $(SONAME_MAJOR).$(SONAME_MINOR).$(SOEXT) + LINKSHARED := $(LINKSHARED)-dynamiclib -Wl, + ifneq ($(ADDITIONAL_LIBS),) + LINKSHARED := $(LINKSHARED)$(ADDITIONAL_LIBS), + endif + LINKSHARED := $(LINKSHARED)-install_name,$(LIBDIR)/lib$(LANGUAGE_NAME).$(SOEXTVER),-rpath,@executable_path/../Frameworks +else + SOEXT = so + SOEXTVER_MAJOR = $(SOEXT).$(SONAME_MAJOR) + SOEXTVER = $(SOEXT).$(SONAME_MAJOR).$(SONAME_MINOR) + LINKSHARED := $(LINKSHARED)-shared -Wl, + ifneq ($(ADDITIONAL_LIBS),) + LINKSHARED := $(LINKSHARED)$(ADDITIONAL_LIBS) + endif + LINKSHARED := $(LINKSHARED)-soname,lib$(LANGUAGE_NAME).$(SOEXTVER) +endif +ifneq ($(filter $(shell uname),FreeBSD NetBSD DragonFly),) + PCLIBDIR := $(PREFIX)/libdata/pkgconfig +endif + +all: lib$(LANGUAGE_NAME).a lib$(LANGUAGE_NAME).$(SOEXT) $(LANGUAGE_NAME).pc + +lib$(LANGUAGE_NAME).a: $(OBJS) + $(AR) $(ARFLAGS) $@ $^ + +lib$(LANGUAGE_NAME).$(SOEXT): $(OBJS) + $(CC) $(LDFLAGS) $(LINKSHARED) $^ $(LDLIBS) -o $@ +ifneq ($(STRIP),) + $(STRIP) $@ +endif + +$(LANGUAGE_NAME).pc: bindings/c/$(LANGUAGE_NAME).pc.in + sed -e 's|@URL@|$(PARSER_URL)|' \ + -e 's|@VERSION@|$(VERSION)|' \ + -e 's|@LIBDIR@|$(LIBDIR)|' \ + -e 's|@INCLUDEDIR@|$(INCLUDEDIR)|' \ + -e 's|@REQUIRES@|$(REQUIRES)|' \ + -e 's|@ADDITIONAL_LIBS@|$(ADDITIONAL_LIBS)|' \ + -e 's|=$(PREFIX)|=$${prefix}|' \ + -e 's|@PREFIX@|$(PREFIX)|' $< > $@ + +$(PARSER): $(SRC_DIR)/grammar.json + $(TS) generate --no-bindings $^ + +install: all + install -d '$(DESTDIR)$(INCLUDEDIR)'/tree_sitter '$(DESTDIR)$(PCLIBDIR)' '$(DESTDIR)$(LIBDIR)' + install -m644 bindings/c/$(LANGUAGE_NAME).h '$(DESTDIR)$(INCLUDEDIR)'/tree_sitter/$(LANGUAGE_NAME).h + install -m644 $(LANGUAGE_NAME).pc '$(DESTDIR)$(PCLIBDIR)'/$(LANGUAGE_NAME).pc + install -m644 lib$(LANGUAGE_NAME).a '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).a + install -m755 lib$(LANGUAGE_NAME).$(SOEXT) '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXTVER) + ln -sf lib$(LANGUAGE_NAME).$(SOEXTVER) '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXTVER_MAJOR) + ln -sf lib$(LANGUAGE_NAME).$(SOEXTVER_MAJOR) '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXT) + +uninstall: + $(RM) '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).a \ + '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXTVER) \ + '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXTVER_MAJOR) \ + '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXT) \ + '$(DESTDIR)$(INCLUDEDIR)'/tree_sitter/$(LANGUAGE_NAME).h \ + '$(DESTDIR)$(PCLIBDIR)'/$(LANGUAGE_NAME).pc + +clean: + $(RM) $(OBJS) $(LANGUAGE_NAME).pc lib$(LANGUAGE_NAME).a lib$(LANGUAGE_NAME).$(SOEXT) + +test: + $(TS) test + +.PHONY: all install uninstall clean test diff --git a/Package.swift b/Package.swift new file mode 100644 index 0000000..9c21577 --- /dev/null +++ b/Package.swift @@ -0,0 +1,60 @@ +// swift-tools-version:5.3 +import PackageDescription + +let package = Package( + name: "TreeSitterJrpc", + products: [ + .library(name: "TreeSitterJrpc", targets: ["TreeSitterJrpc"]), + ], + dependencies: [ + .package(url: "https://github.com/ChimeHQ/SwiftTreeSitter", from: "0.8.0"), + ], + targets: [ + .target( + name: "TreeSitterJrpc", + dependencies: [], + path: ".", + exclude: [ + "Cargo.toml", + "Makefile", + "binding.gyp", + "bindings/c", + "bindings/go", + "bindings/node", + "bindings/python", + "bindings/rust", + "prebuilds", + "grammar.js", + "package.json", + "package-lock.json", + "pyproject.toml", + "setup.py", + "test", + "examples", + ".editorconfig", + ".github", + ".gitignore", + ".gitattributes", + ".gitmodules", + ], + sources: [ + "src/parser.c", + // NOTE: if your language has an external scanner, add it here. + ], + resources: [ + .copy("queries") + ], + publicHeadersPath: "bindings/swift", + cSettings: [.headerSearchPath("src")] + ), + .testTarget( + name: "TreeSitterJrpcTests", + dependencies: [ + "SwiftTreeSitter", + "TreeSitterJrpc", + ], + path: "bindings/swift/TreeSitterJrpcTests" + ) + ], + cLanguageStandard: .c11 +) diff --git a/binding.gyp b/binding.gyp new file mode 100644 index 0000000..be1e04c --- /dev/null +++ b/binding.gyp @@ -0,0 +1,30 @@ +{ + "targets": [ + { + "target_name": "tree_sitter_jrpc_binding", + "dependencies": [ + " + +typedef struct TSLanguage TSLanguage; + +extern "C" TSLanguage *tree_sitter_jrpc(); + +// "tree-sitter", "language" hashed with BLAKE2 +const napi_type_tag LANGUAGE_TYPE_TAG = { + 0x8AF2E5212AD58ABF, 0xD5006CAD83ABBA16 +}; + +Napi::Object Init(Napi::Env env, Napi::Object exports) { + exports["name"] = Napi::String::New(env, "jrpc"); + auto language = Napi::External::New(env, tree_sitter_jrpc()); + language.TypeTag(&LANGUAGE_TYPE_TAG); + exports["language"] = language; + return exports; +} + +NODE_API_MODULE(tree_sitter_jrpc_binding, Init) diff --git a/bindings/node/binding_test.js b/bindings/node/binding_test.js new file mode 100644 index 0000000..afede30 --- /dev/null +++ b/bindings/node/binding_test.js @@ -0,0 +1,9 @@ +/// + +const assert = require("node:assert"); +const { test } = require("node:test"); + +test("can load grammar", () => { + const parser = new (require("tree-sitter"))(); + assert.doesNotThrow(() => parser.setLanguage(require("."))); +}); diff --git a/bindings/node/index.d.ts b/bindings/node/index.d.ts new file mode 100644 index 0000000..efe259e --- /dev/null +++ b/bindings/node/index.d.ts @@ -0,0 +1,28 @@ +type BaseNode = { + type: string; + named: boolean; +}; + +type ChildNode = { + multiple: boolean; + required: boolean; + types: BaseNode[]; +}; + +type NodeInfo = + | (BaseNode & { + subtypes: BaseNode[]; + }) + | (BaseNode & { + fields: { [name: string]: ChildNode }; + children: ChildNode[]; + }); + +type Language = { + name: string; + language: unknown; + nodeTypeInfo: NodeInfo[]; +}; + +declare const language: Language; +export = language; diff --git a/bindings/node/index.js b/bindings/node/index.js new file mode 100644 index 0000000..6657bcf --- /dev/null +++ b/bindings/node/index.js @@ -0,0 +1,7 @@ +const root = require("path").join(__dirname, "..", ".."); + +module.exports = require("node-gyp-build")(root); + +try { + module.exports.nodeTypeInfo = require("../../src/node-types.json"); +} catch (_) {} diff --git a/bindings/python/tests/test_binding.py b/bindings/python/tests/test_binding.py new file mode 100644 index 0000000..29ee2c1 --- /dev/null +++ b/bindings/python/tests/test_binding.py @@ -0,0 +1,11 @@ +from unittest import TestCase + +import tree_sitter, tree_sitter_jrpc + + +class TestLanguage(TestCase): + def test_can_load_grammar(self): + try: + tree_sitter.Language(tree_sitter_jrpc.language()) + except Exception: + self.fail("Error loading Jrpc grammar") diff --git a/bindings/python/tree_sitter_jrpc/__init__.py b/bindings/python/tree_sitter_jrpc/__init__.py new file mode 100644 index 0000000..d0a32e4 --- /dev/null +++ b/bindings/python/tree_sitter_jrpc/__init__.py @@ -0,0 +1,42 @@ +"""Jrpc grammar for tree-sitter""" + +from importlib.resources import files as _files + +from ._binding import language + + +def _get_query(name, file): + query = _files(f"{__package__}.queries") / file + globals()[name] = query.read_text() + return globals()[name] + + +def __getattr__(name): + # NOTE: uncomment these to include any queries that this grammar contains: + + # if name == "HIGHLIGHTS_QUERY": + # return _get_query("HIGHLIGHTS_QUERY", "highlights.scm") + # if name == "INJECTIONS_QUERY": + # return _get_query("INJECTIONS_QUERY", "injections.scm") + # if name == "LOCALS_QUERY": + # return _get_query("LOCALS_QUERY", "locals.scm") + # if name == "TAGS_QUERY": + # return _get_query("TAGS_QUERY", "tags.scm") + + raise AttributeError(f"module {__name__!r} has no attribute {name!r}") + + +__all__ = [ + "language", + # "HIGHLIGHTS_QUERY", + # "INJECTIONS_QUERY", + # "LOCALS_QUERY", + # "TAGS_QUERY", +] + + +def __dir__(): + return sorted(__all__ + [ + "__all__", "__builtins__", "__cached__", "__doc__", "__file__", + "__loader__", "__name__", "__package__", "__path__", "__spec__", + ]) diff --git a/bindings/python/tree_sitter_jrpc/__init__.pyi b/bindings/python/tree_sitter_jrpc/__init__.pyi new file mode 100644 index 0000000..abf6633 --- /dev/null +++ b/bindings/python/tree_sitter_jrpc/__init__.pyi @@ -0,0 +1,10 @@ +from typing import Final + +# NOTE: uncomment these to include any queries that this grammar contains: + +# HIGHLIGHTS_QUERY: Final[str] +# INJECTIONS_QUERY: Final[str] +# LOCALS_QUERY: Final[str] +# TAGS_QUERY: Final[str] + +def language() -> object: ... diff --git a/bindings/python/tree_sitter_jrpc/binding.c b/bindings/python/tree_sitter_jrpc/binding.c new file mode 100644 index 0000000..8ac4222 --- /dev/null +++ b/bindings/python/tree_sitter_jrpc/binding.c @@ -0,0 +1,27 @@ +#include + +typedef struct TSLanguage TSLanguage; + +TSLanguage *tree_sitter_jrpc(void); + +static PyObject* _binding_language(PyObject *Py_UNUSED(self), PyObject *Py_UNUSED(args)) { + return PyCapsule_New(tree_sitter_jrpc(), "tree_sitter.Language", NULL); +} + +static PyMethodDef methods[] = { + {"language", _binding_language, METH_NOARGS, + "Get the tree-sitter language for this grammar."}, + {NULL, NULL, 0, NULL} +}; + +static struct PyModuleDef module = { + .m_base = PyModuleDef_HEAD_INIT, + .m_name = "_binding", + .m_doc = NULL, + .m_size = -1, + .m_methods = methods +}; + +PyMODINIT_FUNC PyInit__binding(void) { + return PyModule_Create(&module); +} diff --git a/bindings/python/tree_sitter_jrpc/py.typed b/bindings/python/tree_sitter_jrpc/py.typed new file mode 100644 index 0000000..e69de29 diff --git a/bindings/rust/build.rs b/bindings/rust/build.rs new file mode 100644 index 0000000..860e3b6 --- /dev/null +++ b/bindings/rust/build.rs @@ -0,0 +1,22 @@ +fn main() { + let src_dir = std::path::Path::new("src"); + + 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()); + + // NOTE: if your language uses an external scanner, uncomment this block: + /* + 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("tree-sitter-jrpc"); +} diff --git a/bindings/rust/lib.rs b/bindings/rust/lib.rs new file mode 100644 index 0000000..ddcc633 --- /dev/null +++ b/bindings/rust/lib.rs @@ -0,0 +1,53 @@ +//! This crate provides Jrpc 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 = r#" +//! "#; +//! let mut parser = tree_sitter::Parser::new(); +//! let language = tree_sitter_jrpc::LANGUAGE; +//! parser +//! .set_language(&language.into()) +//! .expect("Error loading Jrpc parser"); +//! let tree = parser.parse(code, None).unwrap(); +//! assert!(!tree.root_node().has_error()); +//! ``` +//! +//! [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::LanguageFn; + +extern "C" { + fn tree_sitter_jrpc() -> *const (); +} + +/// The tree-sitter [`LanguageFn`] for this grammar. +pub const LANGUAGE: LanguageFn = unsafe { LanguageFn::from_raw(tree_sitter_jrpc) }; + +/// 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: &str = include_str!("../../src/node-types.json"); + +// NOTE: uncomment these to include any queries that this grammar contains: + +// pub const HIGHLIGHTS_QUERY: &str = include_str!("../../queries/highlights.scm"); +// pub const INJECTIONS_QUERY: &str = include_str!("../../queries/injections.scm"); +// pub const LOCALS_QUERY: &str = include_str!("../../queries/locals.scm"); +// pub const TAGS_QUERY: &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.into()) + .expect("Error loading Jrpc parser"); + } +} diff --git a/bindings/swift/TreeSitterJrpc/jrpc.h b/bindings/swift/TreeSitterJrpc/jrpc.h new file mode 100644 index 0000000..12da07d --- /dev/null +++ b/bindings/swift/TreeSitterJrpc/jrpc.h @@ -0,0 +1,16 @@ +#ifndef TREE_SITTER_JRPC_H_ +#define TREE_SITTER_JRPC_H_ + +typedef struct TSLanguage TSLanguage; + +#ifdef __cplusplus +extern "C" { +#endif + +const TSLanguage *tree_sitter_jrpc(void); + +#ifdef __cplusplus +} +#endif + +#endif // TREE_SITTER_JRPC_H_ diff --git a/bindings/swift/TreeSitterJrpcTests/TreeSitterJrpcTests.swift b/bindings/swift/TreeSitterJrpcTests/TreeSitterJrpcTests.swift new file mode 100644 index 0000000..2aeeefa --- /dev/null +++ b/bindings/swift/TreeSitterJrpcTests/TreeSitterJrpcTests.swift @@ -0,0 +1,12 @@ +import XCTest +import SwiftTreeSitter +import TreeSitterJrpc + +final class TreeSitterJrpcTests: XCTestCase { + func testCanLoadGrammar() throws { + let parser = Parser() + let language = Language(language: tree_sitter_jrpc()) + XCTAssertNoThrow(try parser.setLanguage(language), + "Error loading Jrpc grammar") + } +} diff --git a/example-file b/example-file new file mode 100644 index 0000000..a156746 --- /dev/null +++ b/example-file @@ -0,0 +1,74 @@ +import "./import"; + +define csharp_namespace Example; +define rust_crate example; +define dart_library_name example; + +enum TestEnum { + VAL1, + VAL2, + VAL10 = 10, + VAL11, + VAL12 +} + +type Test { + atom: TestAtom; + array: TestAtom[]; + enumValue: TestEnum; + map: {int, TestAtom}; +} + + +type AddValueRequest { + value1: float; + value2: float; +} + +type AddValueResponse { + value: float; +} + +service TestService { + @Description("Add two numbers") + @Param("request", "Parameter containing the two numbers") + @Returns("") + AddValuesSingleParam(request: AddValueRequest): AddValueResponse; + + @Description("Add two numbers") + @Param("value1", "The first value") + @Param("value2", "The second value") + AddValuesMultipleParams(value1: float, value2: float): float; + + @Description("Does literaly nothing") + @Param("param1", "Some number") + ReturningVoid(param1: float): void; + + @Description("Just sends an Event with a String") + @Param("param1", "Parameter with some string for event") + notification OnEvent(param1: string); + + ThrowingError(): void; + + + FunctionWithArrayAsParamAndReturn(values1: float[], values2: float[]): float[]; + + FunctionWithKeywords(type: float, static: float, event: float): float; +} + +type Test2 { + name: string; + age: int; +} + +type TestKeywords { + type: float; + static: float; + event: float; +} + +service SimpleTestService { + @Description("asdasdasd") + GetTest(name: string, age: int): Test2; + notification TestNot(); +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..4c916df --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module github.com/tree-sitter/tree-sitter-jrpc + +go 1.23 + +require github.com/tree-sitter/go-tree-sitter v0.23 diff --git a/grammar.js b/grammar.js new file mode 100644 index 0000000..ec04996 --- /dev/null +++ b/grammar.js @@ -0,0 +1,115 @@ +/// +// @ts-check + +module.exports = grammar({ + name: "jrpc", + + rules: { + // TODO: add the actual grammar rules + document: ($) => repeat($._statement), + _statement: ($) => + choice( + $.type_declaration, + $.define_declaration, + $.import_declaration, + $.service_declaration, + $.enum_declaration, + ), + type_declaration: ($) => seq("type", $.identifier, optional($.attributes)), + attributes: ($) => + seq("{", optional(seq($.attribute, repeat($.attribute))), "}"), + attribute: ($) => seq($.pair, ";"), + + enum_declaration: ($) => seq("enum", $.identifier, $.enum_values), + enum_values: ($) => + seq( + "{", + optional(seq($.enum_value, repeat(seq(",", $.enum_value)))), + "}", + ), + enum_value: ($) => + choice($.enum_value_declaration, $.enum_value_assignment), + enum_value_assignment: ($) => seq($.identifier, "=", $.number), + enum_value_declaration: ($) => seq($.identifier), + + define_declaration: ($) => + seq("define", $.identifier, choice($.string, $.identifier), ";"), + + import_declaration: ($) => seq("import", $.string, ";"), + + service_declaration: ($) => + seq("service", $.identifier, $.service_functions), + + service_functions: ($) => + seq( + "{", + optional( + repeat( + seq( + repeat($.function_decorator), + choice($.service_function, $.service_notification), + ), + ), + ), + "}", + ), + + function_decorator: ($) => seq("@", $.identifier, $.decorator_arguments), + decorator_arguments: ($) => + seq( + "(", + optional(seq($.string, optional(repeat(seq(",", $.string))))), + ")", + ), + service_notification: ($) => + seq( + "notification", + field("name", $.identifier), + field("parameters", $.function_arguments), + ";", + ), + service_function: ($) => + seq( + field("name", $.identifier), + field("parameters", $.function_arguments), + ":", + field("return_type", $.type), + ";", + ), + function_arguments: ($) => + seq( + "(", + optional( + seq($.function_argument, repeat(seq(",", $.function_argument))), + ), + ")", + ), + function_argument: ($) => seq($.identifier, ":", $.type), + + pair: ($) => + seq( + field("key", $.identifier), + optional("?"), + ":", + field("value", $.type), + ), + + type: ($) => + choice($.map_type, $.array_type, $.primitive_type, $.identifier), + primitive_type: ($) => choice("int", "string", "float", "boolean", "void"), + array_type: ($) => seq(choice($.primitive_type, $.identifier), "[]"), + map_type: ($) => seq("{", $.map_key_type, ",", $.type, "}"), + map_key_type: ($) => choice("int", "string"), + + identifier: ($) => /[a-zA-Z_][a-zA-Z_0-9]*/, + + string: ($) => choice(seq('"', '"'), seq('"', $._string_content, '"')), + _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)/)), + + number: ($) => /[0-9]+/, + }, +}); diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..3219f6b --- /dev/null +++ b/package-lock.json @@ -0,0 +1,369 @@ +{ + "name": "tree-sitter-jrpc", + "version": "0.0.1", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "tree-sitter-jrpc", + "version": "0.0.1", + "hasInstallScript": true, + "license": "MIT", + "dependencies": { + "node-addon-api": "^8.0.0", + "node-gyp-build": "^4.8.1" + }, + "devDependencies": { + "prebuildify": "^6.0.1", + "tree-sitter-cli": "^0.23.0" + }, + "peerDependencies": { + "tree-sitter": "^0.21.1" + }, + "peerDependenciesMeta": { + "tree-sitter": { + "optional": true + } + } + }, + "node_modules/base64-js": { + "version": "1.5.1", + "resolved": "https://npm.hibas123.de/base64-js/-/base64-js-1.5.1.tgz", + "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "license": "MIT" + }, + "node_modules/bl": { + "version": "4.1.0", + "resolved": "https://npm.hibas123.de/bl/-/bl-4.1.0.tgz", + "integrity": "sha512-1W07cM9gS6DcLperZfFSj+bWLtaPGSOHWhPiGzXmvVJbRLdG82sH/Kn8EtW1VqWVA54AKf2h5k5BbnIbwF3h6w==", + "dev": true, + "license": "MIT", + "dependencies": { + "buffer": "^5.5.0", + "inherits": "^2.0.4", + "readable-stream": "^3.4.0" + } + }, + "node_modules/buffer": { + "version": "5.7.1", + "resolved": "https://npm.hibas123.de/buffer/-/buffer-5.7.1.tgz", + "integrity": "sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "license": "MIT", + "dependencies": { + "base64-js": "^1.3.1", + "ieee754": "^1.1.13" + } + }, + "node_modules/chownr": { + "version": "1.1.4", + "resolved": "https://npm.hibas123.de/chownr/-/chownr-1.1.4.tgz", + "integrity": "sha512-jJ0bqzaylmJtVnNgzTeSOs8DPavpbYgEr/b0YL8/2GO3xJEhInFmhKMUnEJQjZumK7KXGFhUy89PrsJWlakBVg==", + "dev": true, + "license": "ISC" + }, + "node_modules/end-of-stream": { + "version": "1.4.4", + "resolved": "https://npm.hibas123.de/end-of-stream/-/end-of-stream-1.4.4.tgz", + "integrity": "sha512-+uw1inIHVPQoaVuHzRyXd21icM+cnt4CzD5rW+NC1wjOUSTOs+Te7FOv7AhN7vS9x/oIyhLP5PR1H+phQAHu5Q==", + "dev": true, + "license": "MIT", + "dependencies": { + "once": "^1.4.0" + } + }, + "node_modules/fs-constants": { + "version": "1.0.0", + "resolved": "https://npm.hibas123.de/fs-constants/-/fs-constants-1.0.0.tgz", + "integrity": "sha512-y6OAwoSIf7FyjMIv94u+b5rdheZEjzR63GTyZJm5qh4Bi+2YgwLCcI/fPFZkL5PSixOt6ZNKm+w+Hfp/Bciwow==", + "dev": true, + "license": "MIT" + }, + "node_modules/ieee754": { + "version": "1.2.1", + "resolved": "https://npm.hibas123.de/ieee754/-/ieee754-1.2.1.tgz", + "integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "license": "BSD-3-Clause" + }, + "node_modules/inherits": { + "version": "2.0.4", + "resolved": "https://npm.hibas123.de/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", + "dev": true, + "license": "ISC" + }, + "node_modules/minimist": { + "version": "1.2.8", + "resolved": "https://npm.hibas123.de/minimist/-/minimist-1.2.8.tgz", + "integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==", + "dev": true, + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/mkdirp-classic": { + "version": "0.5.3", + "resolved": "https://npm.hibas123.de/mkdirp-classic/-/mkdirp-classic-0.5.3.tgz", + "integrity": "sha512-gKLcREMhtuZRwRAfqP3RFW+TK4JqApVBtOIftVgjuABpAtpxhPGaDcfvbhNvD0B8iD1oUr/txX35NjcaY6Ns/A==", + "dev": true, + "license": "MIT" + }, + "node_modules/node-abi": { + "version": "3.68.0", + "resolved": "https://npm.hibas123.de/node-abi/-/node-abi-3.68.0.tgz", + "integrity": "sha512-7vbj10trelExNjFSBm5kTvZXXa7pZyKWx9RCKIyqe6I9Ev3IzGpQoqBP3a+cOdxY+pWj6VkP28n/2wWysBHD/A==", + "dev": true, + "license": "MIT", + "dependencies": { + "semver": "^7.3.5" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/node-addon-api": { + "version": "8.2.0", + "resolved": "https://npm.hibas123.de/node-addon-api/-/node-addon-api-8.2.0.tgz", + "integrity": "sha512-qnyuI2ROiCkye42n9Tj5aX1ns7rzj6n7zW1XReSnLSL9v/vbLeR6fJq6PU27YU/ICfYw6W7Ouk/N7cysWu/hlw==", + "license": "MIT", + "engines": { + "node": "^18 || ^20 || >= 21" + } + }, + "node_modules/node-gyp-build": { + "version": "4.8.2", + "resolved": "https://npm.hibas123.de/node-gyp-build/-/node-gyp-build-4.8.2.tgz", + "integrity": "sha512-IRUxE4BVsHWXkV/SFOut4qTlagw2aM8T5/vnTsmrHJvVoKueJHRc/JaFND7QDDc61kLYUJ6qlZM3sqTSyx2dTw==", + "license": "MIT", + "bin": { + "node-gyp-build": "bin.js", + "node-gyp-build-optional": "optional.js", + "node-gyp-build-test": "build-test.js" + } + }, + "node_modules/npm-run-path": { + "version": "3.1.0", + "resolved": "https://npm.hibas123.de/npm-run-path/-/npm-run-path-3.1.0.tgz", + "integrity": "sha512-Dbl4A/VfiVGLgQv29URL9xshU8XDY1GeLy+fsaZ1AA8JDSfjvr5P5+pzRbWqRSBxk6/DW7MIh8lTM/PaGnP2kg==", + "dev": true, + "license": "MIT", + "dependencies": { + "path-key": "^3.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/once": { + "version": "1.4.0", + "resolved": "https://npm.hibas123.de/once/-/once-1.4.0.tgz", + "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", + "dev": true, + "license": "ISC", + "dependencies": { + "wrappy": "1" + } + }, + "node_modules/path-key": { + "version": "3.1.1", + "resolved": "https://npm.hibas123.de/path-key/-/path-key-3.1.1.tgz", + "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/prebuildify": { + "version": "6.0.1", + "resolved": "https://npm.hibas123.de/prebuildify/-/prebuildify-6.0.1.tgz", + "integrity": "sha512-8Y2oOOateom/s8dNBsGIcnm6AxPmLH4/nanQzL5lQMU+sC0CMhzARZHizwr36pUPLdvBnOkCNQzxg4djuFSgIw==", + "dev": true, + "license": "MIT", + "dependencies": { + "minimist": "^1.2.5", + "mkdirp-classic": "^0.5.3", + "node-abi": "^3.3.0", + "npm-run-path": "^3.1.0", + "pump": "^3.0.0", + "tar-fs": "^2.1.0" + }, + "bin": { + "prebuildify": "bin.js" + } + }, + "node_modules/pump": { + "version": "3.0.2", + "resolved": "https://npm.hibas123.de/pump/-/pump-3.0.2.tgz", + "integrity": "sha512-tUPXtzlGM8FE3P0ZL6DVs/3P58k9nk8/jZeQCurTJylQA8qFYzHFfhBJkuqyE0FifOsQ0uKWekiZ5g8wtr28cw==", + "dev": true, + "license": "MIT", + "dependencies": { + "end-of-stream": "^1.1.0", + "once": "^1.3.1" + } + }, + "node_modules/readable-stream": { + "version": "3.6.2", + "resolved": "https://npm.hibas123.de/readable-stream/-/readable-stream-3.6.2.tgz", + "integrity": "sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==", + "dev": true, + "license": "MIT", + "dependencies": { + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/safe-buffer": { + "version": "5.2.1", + "resolved": "https://npm.hibas123.de/safe-buffer/-/safe-buffer-5.2.1.tgz", + "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "license": "MIT" + }, + "node_modules/semver": { + "version": "7.6.3", + "resolved": "https://npm.hibas123.de/semver/-/semver-7.6.3.tgz", + "integrity": "sha512-oVekP1cKtI+CTDvHWYFUcMtsK/00wmAEfyqKfNdARm8u1wNVhSgaX7A8d4UuIlUI5e84iEwOhs7ZPYRmzU9U6A==", + "dev": true, + "license": "ISC", + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/string_decoder": { + "version": "1.3.0", + "resolved": "https://npm.hibas123.de/string_decoder/-/string_decoder-1.3.0.tgz", + "integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==", + "dev": true, + "license": "MIT", + "dependencies": { + "safe-buffer": "~5.2.0" + } + }, + "node_modules/tar-fs": { + "version": "2.1.1", + "resolved": "https://npm.hibas123.de/tar-fs/-/tar-fs-2.1.1.tgz", + "integrity": "sha512-V0r2Y9scmbDRLCNex/+hYzvp/zyYjvFbHPNgVTKfQvVrb6guiE/fxP+XblDNR011utopbkex2nM4dHNV6GDsng==", + "dev": true, + "license": "MIT", + "dependencies": { + "chownr": "^1.1.1", + "mkdirp-classic": "^0.5.2", + "pump": "^3.0.0", + "tar-stream": "^2.1.4" + } + }, + "node_modules/tar-stream": { + "version": "2.2.0", + "resolved": "https://npm.hibas123.de/tar-stream/-/tar-stream-2.2.0.tgz", + "integrity": "sha512-ujeqbceABgwMZxEJnk2HDY2DlnUZ+9oEcb1KzTVfYHio0UE6dG71n60d8D2I4qNvleWrrXpmjpt7vZeF1LnMZQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "bl": "^4.0.3", + "end-of-stream": "^1.4.1", + "fs-constants": "^1.0.0", + "inherits": "^2.0.3", + "readable-stream": "^3.1.1" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/tree-sitter-cli": { + "version": "0.23.2", + "resolved": "https://npm.hibas123.de/tree-sitter-cli/-/tree-sitter-cli-0.23.2.tgz", + "integrity": "sha512-kPPXprOqREX+C/FgUp2Qpt9jd0vSwn+hOgjzVv/7hapdoWpa+VeWId53rf4oNNd29ikheF12BYtGD/W90feMbA==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "bin": { + "tree-sitter": "cli.js" + }, + "engines": { + "node": ">=12.0.0" + } + }, + "node_modules/util-deprecate": { + "version": "1.0.2", + "resolved": "https://npm.hibas123.de/util-deprecate/-/util-deprecate-1.0.2.tgz", + "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=", + "dev": true, + "license": "MIT" + }, + "node_modules/wrappy": { + "version": "1.0.2", + "resolved": "https://npm.hibas123.de/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", + "dev": true, + "license": "ISC" + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..bbeb755 --- /dev/null +++ b/package.json @@ -0,0 +1,52 @@ +{ + "name": "tree-sitter-jrpc", + "version": "0.0.1", + "description": "Jrpc grammar for tree-sitter", + "repository": "https://git.hibas.dev/hibas123/tree-sitter-jrpc", + "license": "MIT", + "main": "bindings/node", + "types": "bindings/node", + "keywords": [ + "incremental", + "parsing", + "tree-sitter", + "jrpc" + ], + "files": [ + "grammar.js", + "binding.gyp", + "prebuilds/**", + "bindings/node/*", + "queries/*", + "src/**", + "*.wasm" + ], + "dependencies": { + "node-addon-api": "^8.0.0", + "node-gyp-build": "^4.8.1" + }, + "devDependencies": { + "prebuildify": "^6.0.1", + "tree-sitter-cli": "^0.23.0" + }, + "peerDependencies": { + "tree-sitter": "^0.21.1" + }, + "peerDependenciesMeta": { + "tree-sitter": { + "optional": true + } + }, + "scripts": { + "install": "node-gyp-build", + "prestart": "tree-sitter build --wasm", + "start": "tree-sitter playground", + "test": "node --test bindings/node/*_test.js" + }, + "tree-sitter": [ + { + "scope": "source.jrpc", + "injection-regex": "^jrpc$" + } + ] +} diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..aed792b --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,29 @@ +[build-system] +requires = ["setuptools>=42", "wheel"] +build-backend = "setuptools.build_meta" + +[project] +name = "tree-sitter-jrpc" +description = "Jrpc grammar for tree-sitter" +version = "0.0.1" +keywords = ["incremental", "parsing", "tree-sitter", "jrpc"] +classifiers = [ + "Intended Audience :: Developers", + "License :: OSI Approved :: MIT License", + "Topic :: Software Development :: Compilers", + "Topic :: Text Processing :: Linguistic", + "Typing :: Typed", +] +requires-python = ">=3.9" +license.text = "MIT" +readme = "README.md" + +[project.urls] +Homepage = "https://git.hibas.dev/hibas123/tree-sitter-jrpc" + +[project.optional-dependencies] +core = ["tree-sitter~=0.22"] + +[tool.cibuildwheel] +build = "cp39-*" +build-frontend = "build" diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..18683b8 --- /dev/null +++ b/setup.py @@ -0,0 +1,62 @@ +from os.path import isdir, join +from platform import system + +from setuptools import Extension, find_packages, setup +from setuptools.command.build import build +from wheel.bdist_wheel import bdist_wheel + + +class Build(build): + def run(self): + if isdir("queries"): + dest = join(self.build_lib, "tree_sitter_jrpc", "queries") + self.copy_tree("queries", dest) + super().run() + + +class BdistWheel(bdist_wheel): + def get_tag(self): + python, abi, platform = super().get_tag() + if python.startswith("cp"): + python, abi = "cp39", "abi3" + return python, abi, platform + + +setup( + packages=find_packages("bindings/python"), + package_dir={"": "bindings/python"}, + package_data={ + "tree_sitter_jrpc": ["*.pyi", "py.typed"], + "tree_sitter_jrpc.queries": ["*.scm"], + }, + ext_package="tree_sitter_jrpc", + ext_modules=[ + Extension( + name="_binding", + sources=[ + "bindings/python/tree_sitter_jrpc/binding.c", + "src/parser.c", + # NOTE: if your language uses an external scanner, add it here. + ], + extra_compile_args=[ + "-std=c11", + "-fvisibility=hidden", + ] if system() != "Windows" else [ + "/std:c11", + "/utf-8", + ], + define_macros=[ + ("Py_LIMITED_API", "0x03090000"), + ("PY_SSIZE_T_CLEAN", None), + ("TREE_SITTER_HIDE_SYMBOLS", None), + ], + include_dirs=["src"], + py_limited_api=True, + ) + ], + cmdclass={ + "build": Build, + "bdist_wheel": BdistWheel + }, + zip_safe=False +) diff --git a/src/grammar.json b/src/grammar.json new file mode 100644 index 0000000..871aa0e --- /dev/null +++ b/src/grammar.json @@ -0,0 +1,767 @@ +{ + "name": "jrpc", + "rules": { + "document": { + "type": "REPEAT", + "content": { + "type": "SYMBOL", + "name": "_statement" + } + }, + "_statement": { + "type": "CHOICE", + "members": [ + { + "type": "SYMBOL", + "name": "type_declaration" + }, + { + "type": "SYMBOL", + "name": "define_declaration" + }, + { + "type": "SYMBOL", + "name": "import_declaration" + }, + { + "type": "SYMBOL", + "name": "service_declaration" + }, + { + "type": "SYMBOL", + "name": "enum_declaration" + } + ] + }, + "type_declaration": { + "type": "SEQ", + "members": [ + { + "type": "STRING", + "value": "type" + }, + { + "type": "SYMBOL", + "name": "identifier" + }, + { + "type": "CHOICE", + "members": [ + { + "type": "SYMBOL", + "name": "attributes" + }, + { + "type": "BLANK" + } + ] + } + ] + }, + "attributes": { + "type": "SEQ", + "members": [ + { + "type": "STRING", + "value": "{" + }, + { + "type": "CHOICE", + "members": [ + { + "type": "SEQ", + "members": [ + { + "type": "SYMBOL", + "name": "attribute" + }, + { + "type": "REPEAT", + "content": { + "type": "SYMBOL", + "name": "attribute" + } + } + ] + }, + { + "type": "BLANK" + } + ] + }, + { + "type": "STRING", + "value": "}" + } + ] + }, + "attribute": { + "type": "SEQ", + "members": [ + { + "type": "SYMBOL", + "name": "pair" + }, + { + "type": "STRING", + "value": ";" + } + ] + }, + "enum_declaration": { + "type": "SEQ", + "members": [ + { + "type": "STRING", + "value": "enum" + }, + { + "type": "SYMBOL", + "name": "identifier" + }, + { + "type": "SYMBOL", + "name": "enum_values" + } + ] + }, + "enum_values": { + "type": "SEQ", + "members": [ + { + "type": "STRING", + "value": "{" + }, + { + "type": "CHOICE", + "members": [ + { + "type": "SEQ", + "members": [ + { + "type": "SYMBOL", + "name": "enum_value" + }, + { + "type": "REPEAT", + "content": { + "type": "SEQ", + "members": [ + { + "type": "STRING", + "value": "," + }, + { + "type": "SYMBOL", + "name": "enum_value" + } + ] + } + } + ] + }, + { + "type": "BLANK" + } + ] + }, + { + "type": "STRING", + "value": "}" + } + ] + }, + "enum_value": { + "type": "CHOICE", + "members": [ + { + "type": "SYMBOL", + "name": "enum_value_declaration" + }, + { + "type": "SYMBOL", + "name": "enum_value_assignment" + } + ] + }, + "enum_value_assignment": { + "type": "SEQ", + "members": [ + { + "type": "SYMBOL", + "name": "identifier" + }, + { + "type": "STRING", + "value": "=" + }, + { + "type": "SYMBOL", + "name": "number" + } + ] + }, + "enum_value_declaration": { + "type": "SEQ", + "members": [ + { + "type": "SYMBOL", + "name": "identifier" + } + ] + }, + "define_declaration": { + "type": "SEQ", + "members": [ + { + "type": "STRING", + "value": "define" + }, + { + "type": "SYMBOL", + "name": "identifier" + }, + { + "type": "CHOICE", + "members": [ + { + "type": "SYMBOL", + "name": "string" + }, + { + "type": "SYMBOL", + "name": "identifier" + } + ] + }, + { + "type": "STRING", + "value": ";" + } + ] + }, + "import_declaration": { + "type": "SEQ", + "members": [ + { + "type": "STRING", + "value": "import" + }, + { + "type": "SYMBOL", + "name": "string" + }, + { + "type": "STRING", + "value": ";" + } + ] + }, + "service_declaration": { + "type": "SEQ", + "members": [ + { + "type": "STRING", + "value": "service" + }, + { + "type": "SYMBOL", + "name": "identifier" + }, + { + "type": "SYMBOL", + "name": "service_functions" + } + ] + }, + "service_functions": { + "type": "SEQ", + "members": [ + { + "type": "STRING", + "value": "{" + }, + { + "type": "CHOICE", + "members": [ + { + "type": "REPEAT", + "content": { + "type": "SEQ", + "members": [ + { + "type": "REPEAT", + "content": { + "type": "SYMBOL", + "name": "function_decorator" + } + }, + { + "type": "CHOICE", + "members": [ + { + "type": "SYMBOL", + "name": "service_function" + }, + { + "type": "SYMBOL", + "name": "service_notification" + } + ] + } + ] + } + }, + { + "type": "BLANK" + } + ] + }, + { + "type": "STRING", + "value": "}" + } + ] + }, + "function_decorator": { + "type": "SEQ", + "members": [ + { + "type": "STRING", + "value": "@" + }, + { + "type": "SYMBOL", + "name": "identifier" + }, + { + "type": "SYMBOL", + "name": "decorator_arguments" + } + ] + }, + "decorator_arguments": { + "type": "SEQ", + "members": [ + { + "type": "STRING", + "value": "(" + }, + { + "type": "CHOICE", + "members": [ + { + "type": "SEQ", + "members": [ + { + "type": "SYMBOL", + "name": "string" + }, + { + "type": "CHOICE", + "members": [ + { + "type": "REPEAT", + "content": { + "type": "SEQ", + "members": [ + { + "type": "STRING", + "value": "," + }, + { + "type": "SYMBOL", + "name": "string" + } + ] + } + }, + { + "type": "BLANK" + } + ] + } + ] + }, + { + "type": "BLANK" + } + ] + }, + { + "type": "STRING", + "value": ")" + } + ] + }, + "service_notification": { + "type": "SEQ", + "members": [ + { + "type": "STRING", + "value": "notification" + }, + { + "type": "FIELD", + "name": "name", + "content": { + "type": "SYMBOL", + "name": "identifier" + } + }, + { + "type": "FIELD", + "name": "parameters", + "content": { + "type": "SYMBOL", + "name": "function_arguments" + } + }, + { + "type": "STRING", + "value": ";" + } + ] + }, + "service_function": { + "type": "SEQ", + "members": [ + { + "type": "FIELD", + "name": "name", + "content": { + "type": "SYMBOL", + "name": "identifier" + } + }, + { + "type": "FIELD", + "name": "parameters", + "content": { + "type": "SYMBOL", + "name": "function_arguments" + } + }, + { + "type": "STRING", + "value": ":" + }, + { + "type": "FIELD", + "name": "return_type", + "content": { + "type": "SYMBOL", + "name": "type" + } + }, + { + "type": "STRING", + "value": ";" + } + ] + }, + "function_arguments": { + "type": "SEQ", + "members": [ + { + "type": "STRING", + "value": "(" + }, + { + "type": "CHOICE", + "members": [ + { + "type": "SEQ", + "members": [ + { + "type": "SYMBOL", + "name": "function_argument" + }, + { + "type": "REPEAT", + "content": { + "type": "SEQ", + "members": [ + { + "type": "STRING", + "value": "," + }, + { + "type": "SYMBOL", + "name": "function_argument" + } + ] + } + } + ] + }, + { + "type": "BLANK" + } + ] + }, + { + "type": "STRING", + "value": ")" + } + ] + }, + "function_argument": { + "type": "SEQ", + "members": [ + { + "type": "SYMBOL", + "name": "identifier" + }, + { + "type": "STRING", + "value": ":" + }, + { + "type": "SYMBOL", + "name": "type" + } + ] + }, + "pair": { + "type": "SEQ", + "members": [ + { + "type": "FIELD", + "name": "key", + "content": { + "type": "SYMBOL", + "name": "identifier" + } + }, + { + "type": "CHOICE", + "members": [ + { + "type": "STRING", + "value": "?" + }, + { + "type": "BLANK" + } + ] + }, + { + "type": "STRING", + "value": ":" + }, + { + "type": "FIELD", + "name": "value", + "content": { + "type": "SYMBOL", + "name": "type" + } + } + ] + }, + "type": { + "type": "CHOICE", + "members": [ + { + "type": "SYMBOL", + "name": "map_type" + }, + { + "type": "SYMBOL", + "name": "array_type" + }, + { + "type": "SYMBOL", + "name": "primitive_type" + }, + { + "type": "SYMBOL", + "name": "identifier" + } + ] + }, + "primitive_type": { + "type": "CHOICE", + "members": [ + { + "type": "STRING", + "value": "int" + }, + { + "type": "STRING", + "value": "string" + }, + { + "type": "STRING", + "value": "float" + }, + { + "type": "STRING", + "value": "boolean" + }, + { + "type": "STRING", + "value": "void" + } + ] + }, + "array_type": { + "type": "SEQ", + "members": [ + { + "type": "CHOICE", + "members": [ + { + "type": "SYMBOL", + "name": "primitive_type" + }, + { + "type": "SYMBOL", + "name": "identifier" + } + ] + }, + { + "type": "STRING", + "value": "[]" + } + ] + }, + "map_type": { + "type": "SEQ", + "members": [ + { + "type": "STRING", + "value": "{" + }, + { + "type": "SYMBOL", + "name": "map_key_type" + }, + { + "type": "STRING", + "value": "," + }, + { + "type": "SYMBOL", + "name": "type" + }, + { + "type": "STRING", + "value": "}" + } + ] + }, + "map_key_type": { + "type": "CHOICE", + "members": [ + { + "type": "STRING", + "value": "int" + }, + { + "type": "STRING", + "value": "string" + } + ] + }, + "identifier": { + "type": "PATTERN", + "value": "[a-zA-Z_][a-zA-Z_0-9]*" + }, + "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": "SYMBOL", + "name": "string_content" + }, + { + "type": "SYMBOL", + "name": "escape_sequence" + } + ] + } + }, + "string_content": { + "type": "IMMEDIATE_TOKEN", + "content": { + "type": "PREC", + "value": 1, + "content": { + "type": "PATTERN", + "value": "[^\\\\\"\\n]+" + } + } + }, + "escape_sequence": { + "type": "IMMEDIATE_TOKEN", + "content": { + "type": "SEQ", + "members": [ + { + "type": "STRING", + "value": "\\" + }, + { + "type": "PATTERN", + "value": "(\\\"|\\\\|\\/|b|f|n|r|t|u)" + } + ] + } + }, + "number": { + "type": "PATTERN", + "value": "[0-9]+" + } + }, + "extras": [ + { + "type": "PATTERN", + "value": "\\s" + } + ], + "conflicts": [], + "precedences": [], + "externals": [], + "inline": [], + "supertypes": [] +} diff --git a/src/node-types.json b/src/node-types.json new file mode 100644 index 0000000..13829cf --- /dev/null +++ b/src/node-types.json @@ -0,0 +1,603 @@ +[ + { + "type": "array_type", + "named": true, + "fields": {}, + "children": { + "multiple": false, + "required": true, + "types": [ + { + "type": "identifier", + "named": true + }, + { + "type": "primitive_type", + "named": true + } + ] + } + }, + { + "type": "attribute", + "named": true, + "fields": {}, + "children": { + "multiple": false, + "required": true, + "types": [ + { + "type": "pair", + "named": true + } + ] + } + }, + { + "type": "attributes", + "named": true, + "fields": {}, + "children": { + "multiple": true, + "required": false, + "types": [ + { + "type": "attribute", + "named": true + } + ] + } + }, + { + "type": "decorator_arguments", + "named": true, + "fields": {}, + "children": { + "multiple": true, + "required": false, + "types": [ + { + "type": "string", + "named": true + } + ] + } + }, + { + "type": "define_declaration", + "named": true, + "fields": {}, + "children": { + "multiple": true, + "required": true, + "types": [ + { + "type": "identifier", + "named": true + }, + { + "type": "string", + "named": true + } + ] + } + }, + { + "type": "document", + "named": true, + "fields": {}, + "children": { + "multiple": true, + "required": false, + "types": [ + { + "type": "define_declaration", + "named": true + }, + { + "type": "enum_declaration", + "named": true + }, + { + "type": "import_declaration", + "named": true + }, + { + "type": "service_declaration", + "named": true + }, + { + "type": "type_declaration", + "named": true + } + ] + } + }, + { + "type": "enum_declaration", + "named": true, + "fields": {}, + "children": { + "multiple": true, + "required": true, + "types": [ + { + "type": "enum_values", + "named": true + }, + { + "type": "identifier", + "named": true + } + ] + } + }, + { + "type": "enum_value", + "named": true, + "fields": {}, + "children": { + "multiple": false, + "required": true, + "types": [ + { + "type": "enum_value_assignment", + "named": true + }, + { + "type": "enum_value_declaration", + "named": true + } + ] + } + }, + { + "type": "enum_value_assignment", + "named": true, + "fields": {}, + "children": { + "multiple": true, + "required": true, + "types": [ + { + "type": "identifier", + "named": true + }, + { + "type": "number", + "named": true + } + ] + } + }, + { + "type": "enum_value_declaration", + "named": true, + "fields": {}, + "children": { + "multiple": false, + "required": true, + "types": [ + { + "type": "identifier", + "named": true + } + ] + } + }, + { + "type": "enum_values", + "named": true, + "fields": {}, + "children": { + "multiple": true, + "required": false, + "types": [ + { + "type": "enum_value", + "named": true + } + ] + } + }, + { + "type": "function_argument", + "named": true, + "fields": {}, + "children": { + "multiple": true, + "required": true, + "types": [ + { + "type": "identifier", + "named": true + }, + { + "type": "type", + "named": true + } + ] + } + }, + { + "type": "function_arguments", + "named": true, + "fields": {}, + "children": { + "multiple": true, + "required": false, + "types": [ + { + "type": "function_argument", + "named": true + } + ] + } + }, + { + "type": "function_decorator", + "named": true, + "fields": {}, + "children": { + "multiple": true, + "required": true, + "types": [ + { + "type": "decorator_arguments", + "named": true + }, + { + "type": "identifier", + "named": true + } + ] + } + }, + { + "type": "import_declaration", + "named": true, + "fields": {}, + "children": { + "multiple": false, + "required": true, + "types": [ + { + "type": "string", + "named": true + } + ] + } + }, + { + "type": "map_key_type", + "named": true, + "fields": {} + }, + { + "type": "map_type", + "named": true, + "fields": {}, + "children": { + "multiple": true, + "required": true, + "types": [ + { + "type": "map_key_type", + "named": true + }, + { + "type": "type", + "named": true + } + ] + } + }, + { + "type": "pair", + "named": true, + "fields": { + "key": { + "multiple": false, + "required": true, + "types": [ + { + "type": "identifier", + "named": true + } + ] + }, + "value": { + "multiple": false, + "required": true, + "types": [ + { + "type": "type", + "named": true + } + ] + } + } + }, + { + "type": "primitive_type", + "named": true, + "fields": {} + }, + { + "type": "service_declaration", + "named": true, + "fields": {}, + "children": { + "multiple": true, + "required": true, + "types": [ + { + "type": "identifier", + "named": true + }, + { + "type": "service_functions", + "named": true + } + ] + } + }, + { + "type": "service_function", + "named": true, + "fields": { + "name": { + "multiple": false, + "required": true, + "types": [ + { + "type": "identifier", + "named": true + } + ] + }, + "parameters": { + "multiple": false, + "required": true, + "types": [ + { + "type": "function_arguments", + "named": true + } + ] + }, + "return_type": { + "multiple": false, + "required": true, + "types": [ + { + "type": "type", + "named": true + } + ] + } + } + }, + { + "type": "service_functions", + "named": true, + "fields": {}, + "children": { + "multiple": true, + "required": false, + "types": [ + { + "type": "function_decorator", + "named": true + }, + { + "type": "service_function", + "named": true + }, + { + "type": "service_notification", + "named": true + } + ] + } + }, + { + "type": "service_notification", + "named": true, + "fields": { + "name": { + "multiple": false, + "required": true, + "types": [ + { + "type": "identifier", + "named": true + } + ] + }, + "parameters": { + "multiple": false, + "required": true, + "types": [ + { + "type": "function_arguments", + "named": true + } + ] + } + } + }, + { + "type": "string", + "named": true, + "fields": {}, + "children": { + "multiple": true, + "required": false, + "types": [ + { + "type": "escape_sequence", + "named": true + }, + { + "type": "string_content", + "named": true + } + ] + } + }, + { + "type": "type", + "named": true, + "fields": {}, + "children": { + "multiple": false, + "required": true, + "types": [ + { + "type": "array_type", + "named": true + }, + { + "type": "identifier", + "named": true + }, + { + "type": "map_type", + "named": true + }, + { + "type": "primitive_type", + "named": true + } + ] + } + }, + { + "type": "type_declaration", + "named": true, + "fields": {}, + "children": { + "multiple": true, + "required": true, + "types": [ + { + "type": "attributes", + "named": true + }, + { + "type": "identifier", + "named": true + } + ] + } + }, + { + "type": "\"", + "named": false + }, + { + "type": "(", + "named": false + }, + { + "type": ")", + "named": false + }, + { + "type": ",", + "named": false + }, + { + "type": ":", + "named": false + }, + { + "type": ";", + "named": false + }, + { + "type": "=", + "named": false + }, + { + "type": "?", + "named": false + }, + { + "type": "@", + "named": false + }, + { + "type": "[]", + "named": false + }, + { + "type": "boolean", + "named": false + }, + { + "type": "define", + "named": false + }, + { + "type": "enum", + "named": false + }, + { + "type": "escape_sequence", + "named": true + }, + { + "type": "float", + "named": false + }, + { + "type": "identifier", + "named": true + }, + { + "type": "import", + "named": false + }, + { + "type": "int", + "named": false + }, + { + "type": "notification", + "named": false + }, + { + "type": "number", + "named": true + }, + { + "type": "service", + "named": false + }, + { + "type": "string", + "named": false + }, + { + "type": "string_content", + "named": true + }, + { + "type": "type", + "named": false + }, + { + "type": "void", + "named": false + }, + { + "type": "{", + "named": false + }, + { + "type": "}", + "named": false + } +] \ No newline at end of file diff --git a/src/parser.c b/src/parser.c new file mode 100644 index 0000000..c8fe4a2 --- /dev/null +++ b/src/parser.c @@ -0,0 +1,2480 @@ +#include "tree_sitter/parser.h" + +#if defined(__GNUC__) || defined(__clang__) +#pragma GCC diagnostic ignored "-Wmissing-field-initializers" +#endif + +#define LANGUAGE_VERSION 14 +#define STATE_COUNT 105 +#define LARGE_STATE_COUNT 2 +#define SYMBOL_COUNT 63 +#define ALIAS_COUNT 0 +#define TOKEN_COUNT 28 +#define EXTERNAL_TOKEN_COUNT 0 +#define FIELD_COUNT 5 +#define MAX_ALIAS_SEQUENCE_LENGTH 5 +#define PRODUCTION_ID_COUNT 5 + +enum ts_symbol_identifiers { + anon_sym_type = 1, + anon_sym_LBRACE = 2, + anon_sym_RBRACE = 3, + anon_sym_SEMI = 4, + anon_sym_enum = 5, + anon_sym_COMMA = 6, + anon_sym_EQ = 7, + anon_sym_define = 8, + anon_sym_import = 9, + anon_sym_service = 10, + anon_sym_AT = 11, + anon_sym_LPAREN = 12, + anon_sym_RPAREN = 13, + anon_sym_notification = 14, + anon_sym_COLON = 15, + anon_sym_QMARK = 16, + anon_sym_int = 17, + anon_sym_string = 18, + anon_sym_float = 19, + anon_sym_boolean = 20, + anon_sym_void = 21, + anon_sym_LBRACK_RBRACK = 22, + sym_identifier = 23, + anon_sym_DQUOTE = 24, + sym_string_content = 25, + sym_escape_sequence = 26, + sym_number = 27, + sym_document = 28, + sym__statement = 29, + sym_type_declaration = 30, + sym_attributes = 31, + sym_attribute = 32, + sym_enum_declaration = 33, + sym_enum_values = 34, + sym_enum_value = 35, + sym_enum_value_assignment = 36, + sym_enum_value_declaration = 37, + sym_define_declaration = 38, + sym_import_declaration = 39, + sym_service_declaration = 40, + sym_service_functions = 41, + sym_function_decorator = 42, + sym_decorator_arguments = 43, + sym_service_notification = 44, + sym_service_function = 45, + sym_function_arguments = 46, + sym_function_argument = 47, + sym_pair = 48, + sym_type = 49, + sym_primitive_type = 50, + sym_array_type = 51, + sym_map_type = 52, + sym_map_key_type = 53, + sym_string = 54, + aux_sym__string_content = 55, + aux_sym_document_repeat1 = 56, + aux_sym_attributes_repeat1 = 57, + aux_sym_enum_values_repeat1 = 58, + aux_sym_service_functions_repeat1 = 59, + aux_sym_service_functions_repeat2 = 60, + aux_sym_decorator_arguments_repeat1 = 61, + aux_sym_function_arguments_repeat1 = 62, +}; + +static const char * const ts_symbol_names[] = { + [ts_builtin_sym_end] = "end", + [anon_sym_type] = "type", + [anon_sym_LBRACE] = "{", + [anon_sym_RBRACE] = "}", + [anon_sym_SEMI] = ";", + [anon_sym_enum] = "enum", + [anon_sym_COMMA] = ",", + [anon_sym_EQ] = "=", + [anon_sym_define] = "define", + [anon_sym_import] = "import", + [anon_sym_service] = "service", + [anon_sym_AT] = "@", + [anon_sym_LPAREN] = "(", + [anon_sym_RPAREN] = ")", + [anon_sym_notification] = "notification", + [anon_sym_COLON] = ":", + [anon_sym_QMARK] = "\?", + [anon_sym_int] = "int", + [anon_sym_string] = "string", + [anon_sym_float] = "float", + [anon_sym_boolean] = "boolean", + [anon_sym_void] = "void", + [anon_sym_LBRACK_RBRACK] = "[]", + [sym_identifier] = "identifier", + [anon_sym_DQUOTE] = "\"", + [sym_string_content] = "string_content", + [sym_escape_sequence] = "escape_sequence", + [sym_number] = "number", + [sym_document] = "document", + [sym__statement] = "_statement", + [sym_type_declaration] = "type_declaration", + [sym_attributes] = "attributes", + [sym_attribute] = "attribute", + [sym_enum_declaration] = "enum_declaration", + [sym_enum_values] = "enum_values", + [sym_enum_value] = "enum_value", + [sym_enum_value_assignment] = "enum_value_assignment", + [sym_enum_value_declaration] = "enum_value_declaration", + [sym_define_declaration] = "define_declaration", + [sym_import_declaration] = "import_declaration", + [sym_service_declaration] = "service_declaration", + [sym_service_functions] = "service_functions", + [sym_function_decorator] = "function_decorator", + [sym_decorator_arguments] = "decorator_arguments", + [sym_service_notification] = "service_notification", + [sym_service_function] = "service_function", + [sym_function_arguments] = "function_arguments", + [sym_function_argument] = "function_argument", + [sym_pair] = "pair", + [sym_type] = "type", + [sym_primitive_type] = "primitive_type", + [sym_array_type] = "array_type", + [sym_map_type] = "map_type", + [sym_map_key_type] = "map_key_type", + [sym_string] = "string", + [aux_sym__string_content] = "_string_content", + [aux_sym_document_repeat1] = "document_repeat1", + [aux_sym_attributes_repeat1] = "attributes_repeat1", + [aux_sym_enum_values_repeat1] = "enum_values_repeat1", + [aux_sym_service_functions_repeat1] = "service_functions_repeat1", + [aux_sym_service_functions_repeat2] = "service_functions_repeat2", + [aux_sym_decorator_arguments_repeat1] = "decorator_arguments_repeat1", + [aux_sym_function_arguments_repeat1] = "function_arguments_repeat1", +}; + +static const TSSymbol ts_symbol_map[] = { + [ts_builtin_sym_end] = ts_builtin_sym_end, + [anon_sym_type] = anon_sym_type, + [anon_sym_LBRACE] = anon_sym_LBRACE, + [anon_sym_RBRACE] = anon_sym_RBRACE, + [anon_sym_SEMI] = anon_sym_SEMI, + [anon_sym_enum] = anon_sym_enum, + [anon_sym_COMMA] = anon_sym_COMMA, + [anon_sym_EQ] = anon_sym_EQ, + [anon_sym_define] = anon_sym_define, + [anon_sym_import] = anon_sym_import, + [anon_sym_service] = anon_sym_service, + [anon_sym_AT] = anon_sym_AT, + [anon_sym_LPAREN] = anon_sym_LPAREN, + [anon_sym_RPAREN] = anon_sym_RPAREN, + [anon_sym_notification] = anon_sym_notification, + [anon_sym_COLON] = anon_sym_COLON, + [anon_sym_QMARK] = anon_sym_QMARK, + [anon_sym_int] = anon_sym_int, + [anon_sym_string] = anon_sym_string, + [anon_sym_float] = anon_sym_float, + [anon_sym_boolean] = anon_sym_boolean, + [anon_sym_void] = anon_sym_void, + [anon_sym_LBRACK_RBRACK] = anon_sym_LBRACK_RBRACK, + [sym_identifier] = sym_identifier, + [anon_sym_DQUOTE] = anon_sym_DQUOTE, + [sym_string_content] = sym_string_content, + [sym_escape_sequence] = sym_escape_sequence, + [sym_number] = sym_number, + [sym_document] = sym_document, + [sym__statement] = sym__statement, + [sym_type_declaration] = sym_type_declaration, + [sym_attributes] = sym_attributes, + [sym_attribute] = sym_attribute, + [sym_enum_declaration] = sym_enum_declaration, + [sym_enum_values] = sym_enum_values, + [sym_enum_value] = sym_enum_value, + [sym_enum_value_assignment] = sym_enum_value_assignment, + [sym_enum_value_declaration] = sym_enum_value_declaration, + [sym_define_declaration] = sym_define_declaration, + [sym_import_declaration] = sym_import_declaration, + [sym_service_declaration] = sym_service_declaration, + [sym_service_functions] = sym_service_functions, + [sym_function_decorator] = sym_function_decorator, + [sym_decorator_arguments] = sym_decorator_arguments, + [sym_service_notification] = sym_service_notification, + [sym_service_function] = sym_service_function, + [sym_function_arguments] = sym_function_arguments, + [sym_function_argument] = sym_function_argument, + [sym_pair] = sym_pair, + [sym_type] = sym_type, + [sym_primitive_type] = sym_primitive_type, + [sym_array_type] = sym_array_type, + [sym_map_type] = sym_map_type, + [sym_map_key_type] = sym_map_key_type, + [sym_string] = sym_string, + [aux_sym__string_content] = aux_sym__string_content, + [aux_sym_document_repeat1] = aux_sym_document_repeat1, + [aux_sym_attributes_repeat1] = aux_sym_attributes_repeat1, + [aux_sym_enum_values_repeat1] = aux_sym_enum_values_repeat1, + [aux_sym_service_functions_repeat1] = aux_sym_service_functions_repeat1, + [aux_sym_service_functions_repeat2] = aux_sym_service_functions_repeat2, + [aux_sym_decorator_arguments_repeat1] = aux_sym_decorator_arguments_repeat1, + [aux_sym_function_arguments_repeat1] = aux_sym_function_arguments_repeat1, +}; + +static const TSSymbolMetadata ts_symbol_metadata[] = { + [ts_builtin_sym_end] = { + .visible = false, + .named = true, + }, + [anon_sym_type] = { + .visible = true, + .named = false, + }, + [anon_sym_LBRACE] = { + .visible = true, + .named = false, + }, + [anon_sym_RBRACE] = { + .visible = true, + .named = false, + }, + [anon_sym_SEMI] = { + .visible = true, + .named = false, + }, + [anon_sym_enum] = { + .visible = true, + .named = false, + }, + [anon_sym_COMMA] = { + .visible = true, + .named = false, + }, + [anon_sym_EQ] = { + .visible = true, + .named = false, + }, + [anon_sym_define] = { + .visible = true, + .named = false, + }, + [anon_sym_import] = { + .visible = true, + .named = false, + }, + [anon_sym_service] = { + .visible = true, + .named = false, + }, + [anon_sym_AT] = { + .visible = true, + .named = false, + }, + [anon_sym_LPAREN] = { + .visible = true, + .named = false, + }, + [anon_sym_RPAREN] = { + .visible = true, + .named = false, + }, + [anon_sym_notification] = { + .visible = true, + .named = false, + }, + [anon_sym_COLON] = { + .visible = true, + .named = false, + }, + [anon_sym_QMARK] = { + .visible = true, + .named = false, + }, + [anon_sym_int] = { + .visible = true, + .named = false, + }, + [anon_sym_string] = { + .visible = true, + .named = false, + }, + [anon_sym_float] = { + .visible = true, + .named = false, + }, + [anon_sym_boolean] = { + .visible = true, + .named = false, + }, + [anon_sym_void] = { + .visible = true, + .named = false, + }, + [anon_sym_LBRACK_RBRACK] = { + .visible = true, + .named = false, + }, + [sym_identifier] = { + .visible = true, + .named = true, + }, + [anon_sym_DQUOTE] = { + .visible = true, + .named = false, + }, + [sym_string_content] = { + .visible = true, + .named = true, + }, + [sym_escape_sequence] = { + .visible = true, + .named = true, + }, + [sym_number] = { + .visible = true, + .named = true, + }, + [sym_document] = { + .visible = true, + .named = true, + }, + [sym__statement] = { + .visible = false, + .named = true, + }, + [sym_type_declaration] = { + .visible = true, + .named = true, + }, + [sym_attributes] = { + .visible = true, + .named = true, + }, + [sym_attribute] = { + .visible = true, + .named = true, + }, + [sym_enum_declaration] = { + .visible = true, + .named = true, + }, + [sym_enum_values] = { + .visible = true, + .named = true, + }, + [sym_enum_value] = { + .visible = true, + .named = true, + }, + [sym_enum_value_assignment] = { + .visible = true, + .named = true, + }, + [sym_enum_value_declaration] = { + .visible = true, + .named = true, + }, + [sym_define_declaration] = { + .visible = true, + .named = true, + }, + [sym_import_declaration] = { + .visible = true, + .named = true, + }, + [sym_service_declaration] = { + .visible = true, + .named = true, + }, + [sym_service_functions] = { + .visible = true, + .named = true, + }, + [sym_function_decorator] = { + .visible = true, + .named = true, + }, + [sym_decorator_arguments] = { + .visible = true, + .named = true, + }, + [sym_service_notification] = { + .visible = true, + .named = true, + }, + [sym_service_function] = { + .visible = true, + .named = true, + }, + [sym_function_arguments] = { + .visible = true, + .named = true, + }, + [sym_function_argument] = { + .visible = true, + .named = true, + }, + [sym_pair] = { + .visible = true, + .named = true, + }, + [sym_type] = { + .visible = true, + .named = true, + }, + [sym_primitive_type] = { + .visible = true, + .named = true, + }, + [sym_array_type] = { + .visible = true, + .named = true, + }, + [sym_map_type] = { + .visible = true, + .named = true, + }, + [sym_map_key_type] = { + .visible = true, + .named = true, + }, + [sym_string] = { + .visible = true, + .named = true, + }, + [aux_sym__string_content] = { + .visible = false, + .named = false, + }, + [aux_sym_document_repeat1] = { + .visible = false, + .named = false, + }, + [aux_sym_attributes_repeat1] = { + .visible = false, + .named = false, + }, + [aux_sym_enum_values_repeat1] = { + .visible = false, + .named = false, + }, + [aux_sym_service_functions_repeat1] = { + .visible = false, + .named = false, + }, + [aux_sym_service_functions_repeat2] = { + .visible = false, + .named = false, + }, + [aux_sym_decorator_arguments_repeat1] = { + .visible = false, + .named = false, + }, + [aux_sym_function_arguments_repeat1] = { + .visible = false, + .named = false, + }, +}; + +enum ts_field_identifiers { + field_key = 1, + field_name = 2, + field_parameters = 3, + field_return_type = 4, + field_value = 5, +}; + +static const char * const ts_field_names[] = { + [0] = NULL, + [field_key] = "key", + [field_name] = "name", + [field_parameters] = "parameters", + [field_return_type] = "return_type", + [field_value] = "value", +}; + +static const TSFieldMapSlice ts_field_map_slices[PRODUCTION_ID_COUNT] = { + [1] = {.index = 0, .length = 2}, + [2] = {.index = 2, .length = 2}, + [3] = {.index = 4, .length = 2}, + [4] = {.index = 6, .length = 3}, +}; + +static const TSFieldMapEntry ts_field_map_entries[] = { + [0] = + {field_key, 0}, + {field_value, 2}, + [2] = + {field_key, 0}, + {field_value, 3}, + [4] = + {field_name, 1}, + {field_parameters, 2}, + [6] = + {field_name, 0}, + {field_parameters, 1}, + {field_return_type, 3}, +}; + +static const TSSymbol ts_alias_sequences[PRODUCTION_ID_COUNT][MAX_ALIAS_SEQUENCE_LENGTH] = { + [0] = {0}, +}; + +static const uint16_t ts_non_terminal_alias_map[] = { + 0, +}; + +static const TSStateId ts_primary_state_ids[STATE_COUNT] = { + [0] = 0, + [1] = 1, + [2] = 2, + [3] = 3, + [4] = 4, + [5] = 5, + [6] = 6, + [7] = 7, + [8] = 8, + [9] = 9, + [10] = 10, + [11] = 11, + [12] = 12, + [13] = 13, + [14] = 14, + [15] = 15, + [16] = 16, + [17] = 17, + [18] = 18, + [19] = 19, + [20] = 20, + [21] = 21, + [22] = 22, + [23] = 23, + [24] = 24, + [25] = 25, + [26] = 26, + [27] = 27, + [28] = 28, + [29] = 29, + [30] = 30, + [31] = 31, + [32] = 32, + [33] = 33, + [34] = 34, + [35] = 35, + [36] = 36, + [37] = 37, + [38] = 38, + [39] = 39, + [40] = 40, + [41] = 41, + [42] = 42, + [43] = 43, + [44] = 44, + [45] = 45, + [46] = 46, + [47] = 47, + [48] = 48, + [49] = 49, + [50] = 50, + [51] = 51, + [52] = 52, + [53] = 53, + [54] = 54, + [55] = 55, + [56] = 56, + [57] = 57, + [58] = 58, + [59] = 59, + [60] = 60, + [61] = 61, + [62] = 62, + [63] = 63, + [64] = 64, + [65] = 65, + [66] = 66, + [67] = 67, + [68] = 68, + [69] = 69, + [70] = 70, + [71] = 71, + [72] = 72, + [73] = 73, + [74] = 74, + [75] = 75, + [76] = 76, + [77] = 77, + [78] = 78, + [79] = 79, + [80] = 80, + [81] = 81, + [82] = 82, + [83] = 83, + [84] = 84, + [85] = 85, + [86] = 86, + [87] = 87, + [88] = 88, + [89] = 89, + [90] = 90, + [91] = 91, + [92] = 92, + [93] = 93, + [94] = 94, + [95] = 95, + [96] = 96, + [97] = 97, + [98] = 98, + [99] = 99, + [100] = 100, + [101] = 101, + [102] = 102, + [103] = 103, + [104] = 104, +}; + +static bool ts_lex(TSLexer *lexer, TSStateId state) { + START_LEXER(); + eof = lexer->eof(lexer); + switch (state) { + case 0: + if (eof) ADVANCE(60); + ADVANCE_MAP( + '"', 121, + '(', 72, + ')', 73, + ',', 66, + ':', 76, + ';', 64, + '=', 67, + '?', 77, + '@', 71, + '[', 5, + '\\', 58, + 'b', 43, + 'd', 13, + 'e', 33, + 'f', 30, + 'i', 31, + 'n', 41, + 's', 14, + 't', 57, + 'v', 38, + '{', 62, + '}', 63, + ); + if (('\t' <= lookahead && lookahead <= '\r') || + lookahead == ' ') SKIP(59); + if (('0' <= lookahead && lookahead <= '9')) ADVANCE(125); + END_STATE(); + case 1: + if (lookahead == '\n') SKIP(3); + if (lookahead == '"') ADVANCE(121); + if (lookahead == '\\') ADVANCE(58); + if (('\t' <= lookahead && lookahead <= '\r') || + lookahead == ' ') ADVANCE(122); + if (lookahead != 0) ADVANCE(123); + END_STATE(); + case 2: + if (lookahead == '"') ADVANCE(121); + if (lookahead == ')') ADVANCE(73); + if (lookahead == '}') ADVANCE(63); + if (('\t' <= lookahead && lookahead <= '\r') || + lookahead == ' ') SKIP(2); + if (('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(120); + END_STATE(); + case 3: + if (lookahead == '"') ADVANCE(121); + if (('\t' <= lookahead && lookahead <= '\r') || + lookahead == ' ') SKIP(3); + END_STATE(); + case 4: + if (lookahead == '@') ADVANCE(71); + if (lookahead == 'n') ADVANCE(113); + if (lookahead == '}') ADVANCE(63); + if (('\t' <= lookahead && lookahead <= '\r') || + lookahead == ' ') SKIP(4); + if (('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(120); + END_STATE(); + case 5: + if (lookahead == ']') ADVANCE(88); + END_STATE(); + case 6: + if (lookahead == 'a') ADVANCE(51); + END_STATE(); + case 7: + if (lookahead == 'a') ADVANCE(35); + END_STATE(); + case 8: + if (lookahead == 'a') ADVANCE(54); + END_STATE(); + case 9: + if (lookahead == 'b') ADVANCE(111); + if (lookahead == 'f') ADVANCE(103); + if (lookahead == 'i') ADVANCE(107); + if (lookahead == 's') ADVANCE(115); + if (lookahead == 'v') ADVANCE(108); + if (lookahead == '{') ADVANCE(62); + if (('\t' <= lookahead && lookahead <= '\r') || + lookahead == ' ') SKIP(9); + if (('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(120); + END_STATE(); + case 10: + if (lookahead == 'c') ADVANCE(17); + END_STATE(); + case 11: + if (lookahead == 'c') ADVANCE(8); + END_STATE(); + case 12: + if (lookahead == 'd') ADVANCE(86); + END_STATE(); + case 13: + if (lookahead == 'e') ADVANCE(19); + END_STATE(); + case 14: + if (lookahead == 'e') ADVANCE(47); + if (lookahead == 't') ADVANCE(49); + END_STATE(); + case 15: + if (lookahead == 'e') ADVANCE(61); + END_STATE(); + case 16: + if (lookahead == 'e') ADVANCE(68); + END_STATE(); + case 17: + if (lookahead == 'e') ADVANCE(70); + END_STATE(); + case 18: + if (lookahead == 'e') ADVANCE(7); + END_STATE(); + case 19: + if (lookahead == 'f') ADVANCE(24); + END_STATE(); + case 20: + if (lookahead == 'f') ADVANCE(25); + END_STATE(); + case 21: + if (lookahead == 'g') ADVANCE(80); + END_STATE(); + case 22: + if (lookahead == 'i') ADVANCE(12); + END_STATE(); + case 23: + if (lookahead == 'i') ADVANCE(10); + END_STATE(); + case 24: + if (lookahead == 'i') ADVANCE(37); + END_STATE(); + case 25: + if (lookahead == 'i') ADVANCE(11); + END_STATE(); + case 26: + if (lookahead == 'i') ADVANCE(34); + END_STATE(); + case 27: + if (lookahead == 'i') ADVANCE(44); + END_STATE(); + case 28: + if (lookahead == 'i') ADVANCE(20); + END_STATE(); + case 29: + if (lookahead == 'l') ADVANCE(18); + END_STATE(); + case 30: + if (lookahead == 'l') ADVANCE(39); + END_STATE(); + case 31: + if (lookahead == 'm') ADVANCE(46); + if (lookahead == 'n') ADVANCE(50); + END_STATE(); + case 32: + if (lookahead == 'm') ADVANCE(65); + END_STATE(); + case 33: + if (lookahead == 'n') ADVANCE(55); + END_STATE(); + case 34: + if (lookahead == 'n') ADVANCE(21); + END_STATE(); + case 35: + if (lookahead == 'n') ADVANCE(84); + END_STATE(); + case 36: + if (lookahead == 'n') ADVANCE(74); + END_STATE(); + case 37: + if (lookahead == 'n') ADVANCE(16); + END_STATE(); + case 38: + if (lookahead == 'o') ADVANCE(22); + END_STATE(); + case 39: + if (lookahead == 'o') ADVANCE(6); + END_STATE(); + case 40: + if (lookahead == 'o') ADVANCE(29); + END_STATE(); + case 41: + if (lookahead == 'o') ADVANCE(53); + END_STATE(); + case 42: + if (lookahead == 'o') ADVANCE(48); + END_STATE(); + case 43: + if (lookahead == 'o') ADVANCE(40); + END_STATE(); + case 44: + if (lookahead == 'o') ADVANCE(36); + END_STATE(); + case 45: + if (lookahead == 'p') ADVANCE(15); + END_STATE(); + case 46: + if (lookahead == 'p') ADVANCE(42); + END_STATE(); + case 47: + if (lookahead == 'r') ADVANCE(56); + END_STATE(); + case 48: + if (lookahead == 'r') ADVANCE(52); + END_STATE(); + case 49: + if (lookahead == 'r') ADVANCE(26); + END_STATE(); + case 50: + if (lookahead == 't') ADVANCE(78); + END_STATE(); + case 51: + if (lookahead == 't') ADVANCE(82); + END_STATE(); + case 52: + if (lookahead == 't') ADVANCE(69); + END_STATE(); + case 53: + if (lookahead == 't') ADVANCE(28); + END_STATE(); + case 54: + if (lookahead == 't') ADVANCE(27); + END_STATE(); + case 55: + if (lookahead == 'u') ADVANCE(32); + END_STATE(); + case 56: + if (lookahead == 'v') ADVANCE(23); + END_STATE(); + case 57: + if (lookahead == 'y') ADVANCE(45); + END_STATE(); + case 58: + ADVANCE_MAP( + '"', 124, + '/', 124, + '\\', 124, + 'b', 124, + 'f', 124, + 'n', 124, + 'r', 124, + 't', 124, + 'u', 124, + ); + END_STATE(); + case 59: + if (eof) ADVANCE(60); + ADVANCE_MAP( + '"', 121, + '(', 72, + ')', 73, + ',', 66, + ':', 76, + ';', 64, + '=', 67, + '?', 77, + '@', 71, + '[', 5, + 'b', 43, + 'd', 13, + 'e', 33, + 'f', 30, + 'i', 31, + 'n', 41, + 's', 14, + 't', 57, + 'v', 38, + '{', 62, + '}', 63, + ); + if (('\t' <= lookahead && lookahead <= '\r') || + lookahead == ' ') SKIP(59); + if (('0' <= lookahead && lookahead <= '9')) ADVANCE(125); + END_STATE(); + case 60: + ACCEPT_TOKEN(ts_builtin_sym_end); + END_STATE(); + case 61: + ACCEPT_TOKEN(anon_sym_type); + END_STATE(); + case 62: + ACCEPT_TOKEN(anon_sym_LBRACE); + END_STATE(); + case 63: + ACCEPT_TOKEN(anon_sym_RBRACE); + END_STATE(); + case 64: + ACCEPT_TOKEN(anon_sym_SEMI); + END_STATE(); + case 65: + ACCEPT_TOKEN(anon_sym_enum); + END_STATE(); + case 66: + ACCEPT_TOKEN(anon_sym_COMMA); + END_STATE(); + case 67: + ACCEPT_TOKEN(anon_sym_EQ); + END_STATE(); + case 68: + ACCEPT_TOKEN(anon_sym_define); + END_STATE(); + case 69: + ACCEPT_TOKEN(anon_sym_import); + END_STATE(); + case 70: + ACCEPT_TOKEN(anon_sym_service); + END_STATE(); + case 71: + ACCEPT_TOKEN(anon_sym_AT); + END_STATE(); + case 72: + ACCEPT_TOKEN(anon_sym_LPAREN); + END_STATE(); + case 73: + ACCEPT_TOKEN(anon_sym_RPAREN); + END_STATE(); + case 74: + ACCEPT_TOKEN(anon_sym_notification); + END_STATE(); + case 75: + ACCEPT_TOKEN(anon_sym_notification); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(120); + END_STATE(); + case 76: + ACCEPT_TOKEN(anon_sym_COLON); + END_STATE(); + case 77: + ACCEPT_TOKEN(anon_sym_QMARK); + END_STATE(); + case 78: + ACCEPT_TOKEN(anon_sym_int); + END_STATE(); + case 79: + ACCEPT_TOKEN(anon_sym_int); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(120); + END_STATE(); + case 80: + ACCEPT_TOKEN(anon_sym_string); + END_STATE(); + case 81: + ACCEPT_TOKEN(anon_sym_string); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(120); + END_STATE(); + case 82: + ACCEPT_TOKEN(anon_sym_float); + END_STATE(); + case 83: + ACCEPT_TOKEN(anon_sym_float); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(120); + END_STATE(); + case 84: + ACCEPT_TOKEN(anon_sym_boolean); + END_STATE(); + case 85: + ACCEPT_TOKEN(anon_sym_boolean); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(120); + END_STATE(); + case 86: + ACCEPT_TOKEN(anon_sym_void); + END_STATE(); + case 87: + ACCEPT_TOKEN(anon_sym_void); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(120); + END_STATE(); + case 88: + ACCEPT_TOKEN(anon_sym_LBRACK_RBRACK); + END_STATE(); + case 89: + ACCEPT_TOKEN(sym_identifier); + if (lookahead == 'a') ADVANCE(105); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('b' <= lookahead && lookahead <= 'z')) ADVANCE(120); + END_STATE(); + case 90: + ACCEPT_TOKEN(sym_identifier); + if (lookahead == 'a') ADVANCE(117); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('b' <= lookahead && lookahead <= 'z')) ADVANCE(120); + END_STATE(); + case 91: + ACCEPT_TOKEN(sym_identifier); + if (lookahead == 'a') ADVANCE(119); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('b' <= lookahead && lookahead <= 'z')) ADVANCE(120); + END_STATE(); + case 92: + ACCEPT_TOKEN(sym_identifier); + if (lookahead == 'c') ADVANCE(91); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(120); + END_STATE(); + case 93: + ACCEPT_TOKEN(sym_identifier); + if (lookahead == 'd') ADVANCE(87); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(120); + END_STATE(); + case 94: + ACCEPT_TOKEN(sym_identifier); + if (lookahead == 'e') ADVANCE(89); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(120); + END_STATE(); + case 95: + ACCEPT_TOKEN(sym_identifier); + if (lookahead == 'f') ADVANCE(99); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(120); + END_STATE(); + case 96: + ACCEPT_TOKEN(sym_identifier); + if (lookahead == 'g') ADVANCE(81); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(120); + END_STATE(); + case 97: + ACCEPT_TOKEN(sym_identifier); + if (lookahead == 'i') ADVANCE(93); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(120); + END_STATE(); + case 98: + ACCEPT_TOKEN(sym_identifier); + if (lookahead == 'i') ADVANCE(95); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(120); + END_STATE(); + case 99: + ACCEPT_TOKEN(sym_identifier); + if (lookahead == 'i') ADVANCE(92); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(120); + END_STATE(); + case 100: + ACCEPT_TOKEN(sym_identifier); + if (lookahead == 'i') ADVANCE(104); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(120); + END_STATE(); + case 101: + ACCEPT_TOKEN(sym_identifier); + if (lookahead == 'i') ADVANCE(112); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(120); + END_STATE(); + case 102: + ACCEPT_TOKEN(sym_identifier); + if (lookahead == 'l') ADVANCE(94); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(120); + END_STATE(); + case 103: + ACCEPT_TOKEN(sym_identifier); + if (lookahead == 'l') ADVANCE(109); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(120); + END_STATE(); + case 104: + ACCEPT_TOKEN(sym_identifier); + if (lookahead == 'n') ADVANCE(96); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(120); + END_STATE(); + case 105: + ACCEPT_TOKEN(sym_identifier); + if (lookahead == 'n') ADVANCE(85); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(120); + END_STATE(); + case 106: + ACCEPT_TOKEN(sym_identifier); + if (lookahead == 'n') ADVANCE(75); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(120); + END_STATE(); + case 107: + ACCEPT_TOKEN(sym_identifier); + if (lookahead == 'n') ADVANCE(116); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(120); + END_STATE(); + case 108: + ACCEPT_TOKEN(sym_identifier); + if (lookahead == 'o') ADVANCE(97); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(120); + END_STATE(); + case 109: + ACCEPT_TOKEN(sym_identifier); + if (lookahead == 'o') ADVANCE(90); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(120); + END_STATE(); + case 110: + ACCEPT_TOKEN(sym_identifier); + if (lookahead == 'o') ADVANCE(102); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(120); + END_STATE(); + case 111: + ACCEPT_TOKEN(sym_identifier); + if (lookahead == 'o') ADVANCE(110); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(120); + END_STATE(); + case 112: + ACCEPT_TOKEN(sym_identifier); + if (lookahead == 'o') ADVANCE(106); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(120); + END_STATE(); + case 113: + ACCEPT_TOKEN(sym_identifier); + if (lookahead == 'o') ADVANCE(118); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(120); + END_STATE(); + case 114: + ACCEPT_TOKEN(sym_identifier); + if (lookahead == 'r') ADVANCE(100); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(120); + END_STATE(); + case 115: + ACCEPT_TOKEN(sym_identifier); + if (lookahead == 't') ADVANCE(114); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(120); + END_STATE(); + case 116: + ACCEPT_TOKEN(sym_identifier); + if (lookahead == 't') ADVANCE(79); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(120); + END_STATE(); + case 117: + ACCEPT_TOKEN(sym_identifier); + if (lookahead == 't') ADVANCE(83); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(120); + END_STATE(); + case 118: + ACCEPT_TOKEN(sym_identifier); + if (lookahead == 't') ADVANCE(98); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(120); + END_STATE(); + case 119: + ACCEPT_TOKEN(sym_identifier); + if (lookahead == 't') ADVANCE(101); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(120); + END_STATE(); + case 120: + ACCEPT_TOKEN(sym_identifier); + if (('0' <= lookahead && lookahead <= '9') || + ('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('a' <= lookahead && lookahead <= 'z')) ADVANCE(120); + END_STATE(); + case 121: + ACCEPT_TOKEN(anon_sym_DQUOTE); + END_STATE(); + case 122: + ACCEPT_TOKEN(sym_string_content); + if (lookahead == '\t' || + (0x0b <= lookahead && lookahead <= '\r') || + lookahead == ' ') ADVANCE(122); + if (lookahead != 0 && + (lookahead < '\t' || '\r' < lookahead) && + lookahead != '"' && + lookahead != '\\') ADVANCE(123); + END_STATE(); + case 123: + ACCEPT_TOKEN(sym_string_content); + if (lookahead != 0 && + lookahead != '\n' && + lookahead != '"' && + lookahead != '\\') ADVANCE(123); + END_STATE(); + case 124: + ACCEPT_TOKEN(sym_escape_sequence); + END_STATE(); + case 125: + ACCEPT_TOKEN(sym_number); + if (('0' <= lookahead && lookahead <= '9')) ADVANCE(125); + END_STATE(); + default: + return false; + } +} + +static const 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 = 9}, + [5] = {.lex_state = 9}, + [6] = {.lex_state = 9}, + [7] = {.lex_state = 9}, + [8] = {.lex_state = 9}, + [9] = {.lex_state = 4}, + [10] = {.lex_state = 4}, + [11] = {.lex_state = 4}, + [12] = {.lex_state = 0}, + [13] = {.lex_state = 4}, + [14] = {.lex_state = 0}, + [15] = {.lex_state = 0}, + [16] = {.lex_state = 0}, + [17] = {.lex_state = 0}, + [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 = 4}, + [28] = {.lex_state = 2}, + [29] = {.lex_state = 2}, + [30] = {.lex_state = 2}, + [31] = {.lex_state = 2}, + [32] = {.lex_state = 0}, + [33] = {.lex_state = 0}, + [34] = {.lex_state = 1}, + [35] = {.lex_state = 1}, + [36] = {.lex_state = 1}, + [37] = {.lex_state = 2}, + [38] = {.lex_state = 4}, + [39] = {.lex_state = 0}, + [40] = {.lex_state = 0}, + [41] = {.lex_state = 0}, + [42] = {.lex_state = 4}, + [43] = {.lex_state = 4}, + [44] = {.lex_state = 2}, + [45] = {.lex_state = 0}, + [46] = {.lex_state = 0}, + [47] = {.lex_state = 0}, + [48] = {.lex_state = 4}, + [49] = {.lex_state = 0}, + [50] = {.lex_state = 0}, + [51] = {.lex_state = 0}, + [52] = {.lex_state = 4}, + [53] = {.lex_state = 0}, + [54] = {.lex_state = 2}, + [55] = {.lex_state = 0}, + [56] = {.lex_state = 4}, + [57] = {.lex_state = 2}, + [58] = {.lex_state = 0}, + [59] = {.lex_state = 0}, + [60] = {.lex_state = 0}, + [61] = {.lex_state = 0}, + [62] = {.lex_state = 0}, + [63] = {.lex_state = 4}, + [64] = {.lex_state = 0}, + [65] = {.lex_state = 0}, + [66] = {.lex_state = 2}, + [67] = {.lex_state = 2}, + [68] = {.lex_state = 0}, + [69] = {.lex_state = 0}, + [70] = {.lex_state = 0}, + [71] = {.lex_state = 0}, + [72] = {.lex_state = 0}, + [73] = {.lex_state = 0}, + [74] = {.lex_state = 0}, + [75] = {.lex_state = 0}, + [76] = {.lex_state = 0}, + [77] = {.lex_state = 0}, + [78] = {.lex_state = 0}, + [79] = {.lex_state = 0}, + [80] = {.lex_state = 0}, + [81] = {.lex_state = 0}, + [82] = {.lex_state = 0}, + [83] = {.lex_state = 0}, + [84] = {.lex_state = 2}, + [85] = {.lex_state = 0}, + [86] = {.lex_state = 2}, + [87] = {.lex_state = 0}, + [88] = {.lex_state = 2}, + [89] = {.lex_state = 0}, + [90] = {.lex_state = 0}, + [91] = {.lex_state = 2}, + [92] = {.lex_state = 0}, + [93] = {.lex_state = 0}, + [94] = {.lex_state = 0}, + [95] = {.lex_state = 0}, + [96] = {.lex_state = 0}, + [97] = {.lex_state = 0}, + [98] = {.lex_state = 0}, + [99] = {.lex_state = 2}, + [100] = {.lex_state = 0}, + [101] = {.lex_state = 0}, + [102] = {.lex_state = 0}, + [103] = {.lex_state = 0}, + [104] = {.lex_state = 2}, +}; + +static const uint16_t ts_parse_table[LARGE_STATE_COUNT][SYMBOL_COUNT] = { + [0] = { + [ts_builtin_sym_end] = ACTIONS(1), + [anon_sym_type] = ACTIONS(1), + [anon_sym_LBRACE] = ACTIONS(1), + [anon_sym_RBRACE] = ACTIONS(1), + [anon_sym_SEMI] = ACTIONS(1), + [anon_sym_enum] = ACTIONS(1), + [anon_sym_COMMA] = ACTIONS(1), + [anon_sym_EQ] = ACTIONS(1), + [anon_sym_define] = ACTIONS(1), + [anon_sym_import] = ACTIONS(1), + [anon_sym_service] = ACTIONS(1), + [anon_sym_AT] = ACTIONS(1), + [anon_sym_LPAREN] = ACTIONS(1), + [anon_sym_RPAREN] = ACTIONS(1), + [anon_sym_notification] = ACTIONS(1), + [anon_sym_COLON] = ACTIONS(1), + [anon_sym_QMARK] = ACTIONS(1), + [anon_sym_int] = ACTIONS(1), + [anon_sym_string] = ACTIONS(1), + [anon_sym_float] = ACTIONS(1), + [anon_sym_boolean] = ACTIONS(1), + [anon_sym_void] = ACTIONS(1), + [anon_sym_LBRACK_RBRACK] = ACTIONS(1), + [anon_sym_DQUOTE] = ACTIONS(1), + [sym_escape_sequence] = ACTIONS(1), + [sym_number] = ACTIONS(1), + }, + [1] = { + [sym_document] = STATE(85), + [sym__statement] = STATE(2), + [sym_type_declaration] = STATE(2), + [sym_enum_declaration] = STATE(2), + [sym_define_declaration] = STATE(2), + [sym_import_declaration] = STATE(2), + [sym_service_declaration] = STATE(2), + [aux_sym_document_repeat1] = STATE(2), + [ts_builtin_sym_end] = ACTIONS(3), + [anon_sym_type] = ACTIONS(5), + [anon_sym_enum] = ACTIONS(7), + [anon_sym_define] = ACTIONS(9), + [anon_sym_import] = ACTIONS(11), + [anon_sym_service] = ACTIONS(13), + }, +}; + +static const uint16_t ts_small_parse_table[] = { + [0] = 7, + ACTIONS(5), 1, + anon_sym_type, + ACTIONS(7), 1, + anon_sym_enum, + ACTIONS(9), 1, + anon_sym_define, + ACTIONS(11), 1, + anon_sym_import, + ACTIONS(13), 1, + anon_sym_service, + ACTIONS(15), 1, + ts_builtin_sym_end, + STATE(3), 7, + sym__statement, + sym_type_declaration, + sym_enum_declaration, + sym_define_declaration, + sym_import_declaration, + sym_service_declaration, + aux_sym_document_repeat1, + [28] = 7, + ACTIONS(17), 1, + ts_builtin_sym_end, + ACTIONS(19), 1, + anon_sym_type, + ACTIONS(22), 1, + anon_sym_enum, + ACTIONS(25), 1, + anon_sym_define, + ACTIONS(28), 1, + anon_sym_import, + ACTIONS(31), 1, + anon_sym_service, + STATE(3), 7, + sym__statement, + sym_type_declaration, + sym_enum_declaration, + sym_define_declaration, + sym_import_declaration, + sym_service_declaration, + aux_sym_document_repeat1, + [56] = 6, + ACTIONS(34), 1, + anon_sym_LBRACE, + ACTIONS(38), 1, + sym_identifier, + STATE(32), 1, + sym_primitive_type, + STATE(92), 1, + sym_type, + STATE(39), 2, + sym_array_type, + sym_map_type, + ACTIONS(36), 5, + anon_sym_int, + anon_sym_string, + anon_sym_float, + anon_sym_boolean, + anon_sym_void, + [80] = 6, + ACTIONS(34), 1, + anon_sym_LBRACE, + ACTIONS(38), 1, + sym_identifier, + STATE(32), 1, + sym_primitive_type, + STATE(87), 1, + sym_type, + STATE(39), 2, + sym_array_type, + sym_map_type, + ACTIONS(36), 5, + anon_sym_int, + anon_sym_string, + anon_sym_float, + anon_sym_boolean, + anon_sym_void, + [104] = 6, + ACTIONS(34), 1, + anon_sym_LBRACE, + ACTIONS(38), 1, + sym_identifier, + STATE(32), 1, + sym_primitive_type, + STATE(100), 1, + sym_type, + STATE(39), 2, + sym_array_type, + sym_map_type, + ACTIONS(36), 5, + anon_sym_int, + anon_sym_string, + anon_sym_float, + anon_sym_boolean, + anon_sym_void, + [128] = 6, + ACTIONS(34), 1, + anon_sym_LBRACE, + ACTIONS(38), 1, + sym_identifier, + STATE(32), 1, + sym_primitive_type, + STATE(76), 1, + sym_type, + STATE(39), 2, + sym_array_type, + sym_map_type, + ACTIONS(36), 5, + anon_sym_int, + anon_sym_string, + anon_sym_float, + anon_sym_boolean, + anon_sym_void, + [152] = 6, + ACTIONS(34), 1, + anon_sym_LBRACE, + ACTIONS(38), 1, + sym_identifier, + STATE(32), 1, + sym_primitive_type, + STATE(90), 1, + sym_type, + STATE(39), 2, + sym_array_type, + sym_map_type, + ACTIONS(36), 5, + anon_sym_int, + anon_sym_string, + anon_sym_float, + anon_sym_boolean, + anon_sym_void, + [176] = 6, + ACTIONS(40), 1, + anon_sym_RBRACE, + ACTIONS(42), 1, + anon_sym_AT, + ACTIONS(44), 1, + anon_sym_notification, + ACTIONS(46), 1, + sym_identifier, + STATE(13), 2, + sym_function_decorator, + aux_sym_service_functions_repeat1, + STATE(10), 3, + sym_service_notification, + sym_service_function, + aux_sym_service_functions_repeat2, + [198] = 6, + ACTIONS(48), 1, + anon_sym_RBRACE, + ACTIONS(50), 1, + anon_sym_AT, + ACTIONS(53), 1, + anon_sym_notification, + ACTIONS(56), 1, + sym_identifier, + STATE(13), 2, + sym_function_decorator, + aux_sym_service_functions_repeat1, + STATE(10), 3, + sym_service_notification, + sym_service_function, + aux_sym_service_functions_repeat2, + [220] = 6, + ACTIONS(42), 1, + anon_sym_AT, + ACTIONS(44), 1, + anon_sym_notification, + ACTIONS(46), 1, + sym_identifier, + ACTIONS(59), 1, + anon_sym_RBRACE, + STATE(13), 2, + sym_function_decorator, + aux_sym_service_functions_repeat1, + STATE(9), 3, + sym_service_notification, + sym_service_function, + aux_sym_service_functions_repeat2, + [242] = 3, + ACTIONS(63), 1, + anon_sym_LBRACE, + STATE(16), 1, + sym_attributes, + ACTIONS(61), 6, + ts_builtin_sym_end, + anon_sym_type, + anon_sym_enum, + anon_sym_define, + anon_sym_import, + anon_sym_service, + [257] = 5, + ACTIONS(42), 1, + anon_sym_AT, + ACTIONS(44), 1, + anon_sym_notification, + ACTIONS(46), 1, + sym_identifier, + STATE(27), 2, + sym_function_decorator, + aux_sym_service_functions_repeat1, + STATE(38), 2, + sym_service_notification, + sym_service_function, + [275] = 1, + ACTIONS(65), 6, + ts_builtin_sym_end, + anon_sym_type, + anon_sym_enum, + anon_sym_define, + anon_sym_import, + anon_sym_service, + [284] = 1, + ACTIONS(67), 6, + ts_builtin_sym_end, + anon_sym_type, + anon_sym_enum, + anon_sym_define, + anon_sym_import, + anon_sym_service, + [293] = 1, + ACTIONS(69), 6, + ts_builtin_sym_end, + anon_sym_type, + anon_sym_enum, + anon_sym_define, + anon_sym_import, + anon_sym_service, + [302] = 1, + ACTIONS(71), 6, + ts_builtin_sym_end, + anon_sym_type, + anon_sym_enum, + anon_sym_define, + anon_sym_import, + anon_sym_service, + [311] = 1, + ACTIONS(73), 6, + ts_builtin_sym_end, + anon_sym_type, + anon_sym_enum, + anon_sym_define, + anon_sym_import, + anon_sym_service, + [320] = 1, + ACTIONS(75), 6, + ts_builtin_sym_end, + anon_sym_type, + anon_sym_enum, + anon_sym_define, + anon_sym_import, + anon_sym_service, + [329] = 1, + ACTIONS(77), 6, + ts_builtin_sym_end, + anon_sym_type, + anon_sym_enum, + anon_sym_define, + anon_sym_import, + anon_sym_service, + [338] = 1, + ACTIONS(79), 6, + ts_builtin_sym_end, + anon_sym_type, + anon_sym_enum, + anon_sym_define, + anon_sym_import, + anon_sym_service, + [347] = 1, + ACTIONS(81), 6, + ts_builtin_sym_end, + anon_sym_type, + anon_sym_enum, + anon_sym_define, + anon_sym_import, + anon_sym_service, + [356] = 1, + ACTIONS(83), 6, + ts_builtin_sym_end, + anon_sym_type, + anon_sym_enum, + anon_sym_define, + anon_sym_import, + anon_sym_service, + [365] = 1, + ACTIONS(85), 6, + ts_builtin_sym_end, + anon_sym_type, + anon_sym_enum, + anon_sym_define, + anon_sym_import, + anon_sym_service, + [374] = 1, + ACTIONS(87), 6, + ts_builtin_sym_end, + anon_sym_type, + anon_sym_enum, + anon_sym_define, + anon_sym_import, + anon_sym_service, + [383] = 1, + ACTIONS(89), 6, + ts_builtin_sym_end, + anon_sym_type, + anon_sym_enum, + anon_sym_define, + anon_sym_import, + anon_sym_service, + [392] = 3, + ACTIONS(91), 1, + anon_sym_AT, + ACTIONS(94), 2, + anon_sym_notification, + sym_identifier, + STATE(27), 2, + sym_function_decorator, + aux_sym_service_functions_repeat1, + [404] = 4, + ACTIONS(96), 1, + anon_sym_RBRACE, + ACTIONS(98), 1, + sym_identifier, + STATE(102), 1, + sym_pair, + STATE(28), 2, + sym_attribute, + aux_sym_attributes_repeat1, + [418] = 4, + ACTIONS(101), 1, + anon_sym_RBRACE, + ACTIONS(103), 1, + sym_identifier, + STATE(61), 1, + sym_enum_value, + STATE(75), 2, + sym_enum_value_assignment, + sym_enum_value_declaration, + [432] = 4, + ACTIONS(105), 1, + anon_sym_RBRACE, + ACTIONS(107), 1, + sym_identifier, + STATE(102), 1, + sym_pair, + STATE(28), 2, + sym_attribute, + aux_sym_attributes_repeat1, + [446] = 4, + ACTIONS(107), 1, + sym_identifier, + ACTIONS(109), 1, + anon_sym_RBRACE, + STATE(102), 1, + sym_pair, + STATE(30), 2, + sym_attribute, + aux_sym_attributes_repeat1, + [460] = 2, + ACTIONS(113), 1, + anon_sym_LBRACK_RBRACK, + ACTIONS(111), 4, + anon_sym_RBRACE, + anon_sym_SEMI, + anon_sym_COMMA, + anon_sym_RPAREN, + [470] = 1, + ACTIONS(115), 5, + anon_sym_RBRACE, + anon_sym_SEMI, + anon_sym_COMMA, + anon_sym_RPAREN, + anon_sym_LBRACK_RBRACK, + [478] = 3, + ACTIONS(117), 1, + anon_sym_DQUOTE, + STATE(36), 1, + aux_sym__string_content, + ACTIONS(119), 2, + sym_string_content, + sym_escape_sequence, + [489] = 3, + ACTIONS(121), 1, + anon_sym_DQUOTE, + STATE(34), 1, + aux_sym__string_content, + ACTIONS(123), 2, + sym_string_content, + sym_escape_sequence, + [500] = 3, + ACTIONS(125), 1, + anon_sym_DQUOTE, + STATE(36), 1, + aux_sym__string_content, + ACTIONS(127), 2, + sym_string_content, + sym_escape_sequence, + [511] = 4, + ACTIONS(107), 1, + sym_identifier, + ACTIONS(130), 1, + anon_sym_RBRACE, + STATE(31), 1, + sym_attribute, + STATE(102), 1, + sym_pair, + [524] = 2, + ACTIONS(48), 2, + anon_sym_RBRACE, + anon_sym_AT, + ACTIONS(132), 2, + anon_sym_notification, + sym_identifier, + [533] = 1, + ACTIONS(111), 4, + anon_sym_RBRACE, + anon_sym_SEMI, + anon_sym_COMMA, + anon_sym_RPAREN, + [540] = 1, + ACTIONS(134), 4, + anon_sym_RBRACE, + anon_sym_SEMI, + anon_sym_COMMA, + anon_sym_RPAREN, + [547] = 1, + ACTIONS(136), 4, + anon_sym_RBRACE, + anon_sym_SEMI, + anon_sym_COMMA, + anon_sym_RPAREN, + [554] = 2, + ACTIONS(138), 2, + anon_sym_RBRACE, + anon_sym_AT, + ACTIONS(140), 2, + anon_sym_notification, + sym_identifier, + [563] = 2, + ACTIONS(142), 2, + anon_sym_RBRACE, + anon_sym_AT, + ACTIONS(144), 2, + anon_sym_notification, + sym_identifier, + [572] = 3, + ACTIONS(103), 1, + sym_identifier, + STATE(72), 1, + sym_enum_value, + STATE(75), 2, + sym_enum_value_assignment, + sym_enum_value_declaration, + [583] = 3, + ACTIONS(146), 1, + anon_sym_COMMA, + ACTIONS(148), 1, + anon_sym_RPAREN, + STATE(53), 1, + aux_sym_function_arguments_repeat1, + [593] = 3, + ACTIONS(150), 1, + anon_sym_RPAREN, + ACTIONS(152), 1, + anon_sym_DQUOTE, + STATE(55), 1, + sym_string, + [603] = 3, + ACTIONS(154), 1, + anon_sym_COMMA, + ACTIONS(157), 1, + anon_sym_RPAREN, + STATE(47), 1, + aux_sym_decorator_arguments_repeat1, + [613] = 2, + ACTIONS(159), 1, + anon_sym_AT, + ACTIONS(161), 2, + anon_sym_notification, + sym_identifier, + [621] = 3, + ACTIONS(163), 1, + anon_sym_COMMA, + ACTIONS(166), 1, + anon_sym_RPAREN, + STATE(49), 1, + aux_sym_function_arguments_repeat1, + [631] = 3, + ACTIONS(168), 1, + anon_sym_COMMA, + ACTIONS(170), 1, + anon_sym_RPAREN, + STATE(47), 1, + aux_sym_decorator_arguments_repeat1, + [641] = 3, + ACTIONS(172), 1, + anon_sym_RBRACE, + ACTIONS(174), 1, + anon_sym_COMMA, + STATE(64), 1, + aux_sym_enum_values_repeat1, + [651] = 2, + ACTIONS(176), 1, + anon_sym_AT, + ACTIONS(178), 2, + anon_sym_notification, + sym_identifier, + [659] = 3, + ACTIONS(146), 1, + anon_sym_COMMA, + ACTIONS(180), 1, + anon_sym_RPAREN, + STATE(49), 1, + aux_sym_function_arguments_repeat1, + [669] = 3, + ACTIONS(182), 1, + anon_sym_RPAREN, + ACTIONS(184), 1, + sym_identifier, + STATE(45), 1, + sym_function_argument, + [679] = 3, + ACTIONS(168), 1, + anon_sym_COMMA, + ACTIONS(186), 1, + anon_sym_RPAREN, + STATE(50), 1, + aux_sym_decorator_arguments_repeat1, + [689] = 2, + ACTIONS(188), 1, + anon_sym_AT, + ACTIONS(190), 2, + anon_sym_notification, + sym_identifier, + [697] = 3, + ACTIONS(152), 1, + anon_sym_DQUOTE, + ACTIONS(192), 1, + sym_identifier, + STATE(101), 1, + sym_string, + [707] = 1, + ACTIONS(194), 3, + anon_sym_SEMI, + anon_sym_COMMA, + anon_sym_RPAREN, + [713] = 1, + ACTIONS(196), 3, + anon_sym_SEMI, + anon_sym_COMMA, + anon_sym_RPAREN, + [719] = 2, + STATE(93), 1, + sym_map_key_type, + ACTIONS(198), 2, + anon_sym_int, + anon_sym_string, + [727] = 3, + ACTIONS(174), 1, + anon_sym_COMMA, + ACTIONS(200), 1, + anon_sym_RBRACE, + STATE(51), 1, + aux_sym_enum_values_repeat1, + [737] = 2, + ACTIONS(204), 1, + anon_sym_EQ, + ACTIONS(202), 2, + anon_sym_RBRACE, + anon_sym_COMMA, + [745] = 2, + ACTIONS(206), 1, + anon_sym_AT, + ACTIONS(208), 2, + anon_sym_notification, + sym_identifier, + [753] = 3, + ACTIONS(210), 1, + anon_sym_RBRACE, + ACTIONS(212), 1, + anon_sym_COMMA, + STATE(64), 1, + aux_sym_enum_values_repeat1, + [763] = 1, + ACTIONS(215), 2, + anon_sym_SEMI, + anon_sym_COLON, + [768] = 2, + ACTIONS(184), 1, + sym_identifier, + STATE(74), 1, + sym_function_argument, + [775] = 1, + ACTIONS(217), 2, + anon_sym_RBRACE, + sym_identifier, + [780] = 1, + ACTIONS(157), 2, + anon_sym_COMMA, + anon_sym_RPAREN, + [785] = 2, + ACTIONS(219), 1, + anon_sym_COLON, + ACTIONS(221), 1, + anon_sym_QMARK, + [792] = 1, + ACTIONS(223), 2, + anon_sym_SEMI, + anon_sym_COLON, + [797] = 1, + ACTIONS(225), 2, + anon_sym_RBRACE, + anon_sym_COMMA, + [802] = 1, + ACTIONS(210), 2, + anon_sym_RBRACE, + anon_sym_COMMA, + [807] = 2, + ACTIONS(227), 1, + anon_sym_LBRACE, + STATE(21), 1, + sym_service_functions, + [814] = 1, + ACTIONS(166), 2, + anon_sym_COMMA, + anon_sym_RPAREN, + [819] = 1, + ACTIONS(229), 2, + anon_sym_RBRACE, + anon_sym_COMMA, + [824] = 1, + ACTIONS(231), 2, + anon_sym_COMMA, + anon_sym_RPAREN, + [829] = 2, + ACTIONS(233), 1, + anon_sym_LPAREN, + STATE(63), 1, + sym_decorator_arguments, + [836] = 2, + ACTIONS(235), 1, + anon_sym_LPAREN, + STATE(89), 1, + sym_function_arguments, + [843] = 2, + ACTIONS(235), 1, + anon_sym_LPAREN, + STATE(97), 1, + sym_function_arguments, + [850] = 2, + ACTIONS(152), 1, + anon_sym_DQUOTE, + STATE(68), 1, + sym_string, + [857] = 2, + ACTIONS(237), 1, + anon_sym_LBRACE, + STATE(17), 1, + sym_enum_values, + [864] = 2, + ACTIONS(152), 1, + anon_sym_DQUOTE, + STATE(95), 1, + sym_string, + [871] = 1, + ACTIONS(239), 2, + anon_sym_SEMI, + anon_sym_COLON, + [876] = 1, + ACTIONS(241), 1, + sym_identifier, + [880] = 1, + ACTIONS(243), 1, + ts_builtin_sym_end, + [884] = 1, + ACTIONS(245), 1, + sym_identifier, + [888] = 1, + ACTIONS(247), 1, + anon_sym_SEMI, + [892] = 1, + ACTIONS(249), 1, + sym_identifier, + [896] = 1, + ACTIONS(251), 1, + anon_sym_COLON, + [900] = 1, + ACTIONS(253), 1, + anon_sym_SEMI, + [904] = 1, + ACTIONS(255), 1, + sym_identifier, + [908] = 1, + ACTIONS(257), 1, + anon_sym_SEMI, + [912] = 1, + ACTIONS(259), 1, + anon_sym_COMMA, + [916] = 1, + ACTIONS(261), 1, + anon_sym_COMMA, + [920] = 1, + ACTIONS(263), 1, + anon_sym_SEMI, + [924] = 1, + ACTIONS(265), 1, + anon_sym_COLON, + [928] = 1, + ACTIONS(267), 1, + anon_sym_SEMI, + [932] = 1, + ACTIONS(269), 1, + sym_number, + [936] = 1, + ACTIONS(271), 1, + sym_identifier, + [940] = 1, + ACTIONS(273), 1, + anon_sym_RBRACE, + [944] = 1, + ACTIONS(275), 1, + anon_sym_SEMI, + [948] = 1, + ACTIONS(277), 1, + anon_sym_SEMI, + [952] = 1, + ACTIONS(279), 1, + anon_sym_COLON, + [956] = 1, + ACTIONS(281), 1, + sym_identifier, +}; + +static const uint32_t ts_small_parse_table_map[] = { + [SMALL_STATE(2)] = 0, + [SMALL_STATE(3)] = 28, + [SMALL_STATE(4)] = 56, + [SMALL_STATE(5)] = 80, + [SMALL_STATE(6)] = 104, + [SMALL_STATE(7)] = 128, + [SMALL_STATE(8)] = 152, + [SMALL_STATE(9)] = 176, + [SMALL_STATE(10)] = 198, + [SMALL_STATE(11)] = 220, + [SMALL_STATE(12)] = 242, + [SMALL_STATE(13)] = 257, + [SMALL_STATE(14)] = 275, + [SMALL_STATE(15)] = 284, + [SMALL_STATE(16)] = 293, + [SMALL_STATE(17)] = 302, + [SMALL_STATE(18)] = 311, + [SMALL_STATE(19)] = 320, + [SMALL_STATE(20)] = 329, + [SMALL_STATE(21)] = 338, + [SMALL_STATE(22)] = 347, + [SMALL_STATE(23)] = 356, + [SMALL_STATE(24)] = 365, + [SMALL_STATE(25)] = 374, + [SMALL_STATE(26)] = 383, + [SMALL_STATE(27)] = 392, + [SMALL_STATE(28)] = 404, + [SMALL_STATE(29)] = 418, + [SMALL_STATE(30)] = 432, + [SMALL_STATE(31)] = 446, + [SMALL_STATE(32)] = 460, + [SMALL_STATE(33)] = 470, + [SMALL_STATE(34)] = 478, + [SMALL_STATE(35)] = 489, + [SMALL_STATE(36)] = 500, + [SMALL_STATE(37)] = 511, + [SMALL_STATE(38)] = 524, + [SMALL_STATE(39)] = 533, + [SMALL_STATE(40)] = 540, + [SMALL_STATE(41)] = 547, + [SMALL_STATE(42)] = 554, + [SMALL_STATE(43)] = 563, + [SMALL_STATE(44)] = 572, + [SMALL_STATE(45)] = 583, + [SMALL_STATE(46)] = 593, + [SMALL_STATE(47)] = 603, + [SMALL_STATE(48)] = 613, + [SMALL_STATE(49)] = 621, + [SMALL_STATE(50)] = 631, + [SMALL_STATE(51)] = 641, + [SMALL_STATE(52)] = 651, + [SMALL_STATE(53)] = 659, + [SMALL_STATE(54)] = 669, + [SMALL_STATE(55)] = 679, + [SMALL_STATE(56)] = 689, + [SMALL_STATE(57)] = 697, + [SMALL_STATE(58)] = 707, + [SMALL_STATE(59)] = 713, + [SMALL_STATE(60)] = 719, + [SMALL_STATE(61)] = 727, + [SMALL_STATE(62)] = 737, + [SMALL_STATE(63)] = 745, + [SMALL_STATE(64)] = 753, + [SMALL_STATE(65)] = 763, + [SMALL_STATE(66)] = 768, + [SMALL_STATE(67)] = 775, + [SMALL_STATE(68)] = 780, + [SMALL_STATE(69)] = 785, + [SMALL_STATE(70)] = 792, + [SMALL_STATE(71)] = 797, + [SMALL_STATE(72)] = 802, + [SMALL_STATE(73)] = 807, + [SMALL_STATE(74)] = 814, + [SMALL_STATE(75)] = 819, + [SMALL_STATE(76)] = 824, + [SMALL_STATE(77)] = 829, + [SMALL_STATE(78)] = 836, + [SMALL_STATE(79)] = 843, + [SMALL_STATE(80)] = 850, + [SMALL_STATE(81)] = 857, + [SMALL_STATE(82)] = 864, + [SMALL_STATE(83)] = 871, + [SMALL_STATE(84)] = 876, + [SMALL_STATE(85)] = 880, + [SMALL_STATE(86)] = 884, + [SMALL_STATE(87)] = 888, + [SMALL_STATE(88)] = 892, + [SMALL_STATE(89)] = 896, + [SMALL_STATE(90)] = 900, + [SMALL_STATE(91)] = 904, + [SMALL_STATE(92)] = 908, + [SMALL_STATE(93)] = 912, + [SMALL_STATE(94)] = 916, + [SMALL_STATE(95)] = 920, + [SMALL_STATE(96)] = 924, + [SMALL_STATE(97)] = 928, + [SMALL_STATE(98)] = 932, + [SMALL_STATE(99)] = 936, + [SMALL_STATE(100)] = 940, + [SMALL_STATE(101)] = 944, + [SMALL_STATE(102)] = 948, + [SMALL_STATE(103)] = 952, + [SMALL_STATE(104)] = 956, +}; + +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}}, REDUCE(sym_document, 0, 0, 0), + [5] = {.entry = {.count = 1, .reusable = true}}, SHIFT(88), + [7] = {.entry = {.count = 1, .reusable = true}}, SHIFT(104), + [9] = {.entry = {.count = 1, .reusable = true}}, SHIFT(99), + [11] = {.entry = {.count = 1, .reusable = true}}, SHIFT(82), + [13] = {.entry = {.count = 1, .reusable = true}}, SHIFT(86), + [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(88), + [22] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym_document_repeat1, 2, 0, 0), SHIFT_REPEAT(104), + [25] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym_document_repeat1, 2, 0, 0), SHIFT_REPEAT(99), + [28] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym_document_repeat1, 2, 0, 0), SHIFT_REPEAT(82), + [31] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym_document_repeat1, 2, 0, 0), SHIFT_REPEAT(86), + [34] = {.entry = {.count = 1, .reusable = true}}, SHIFT(60), + [36] = {.entry = {.count = 1, .reusable = false}}, SHIFT(33), + [38] = {.entry = {.count = 1, .reusable = false}}, SHIFT(32), + [40] = {.entry = {.count = 1, .reusable = true}}, SHIFT(14), + [42] = {.entry = {.count = 1, .reusable = true}}, SHIFT(91), + [44] = {.entry = {.count = 1, .reusable = false}}, SHIFT(84), + [46] = {.entry = {.count = 1, .reusable = false}}, SHIFT(78), + [48] = {.entry = {.count = 1, .reusable = true}}, REDUCE(aux_sym_service_functions_repeat2, 2, 0, 0), + [50] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym_service_functions_repeat2, 2, 0, 0), SHIFT_REPEAT(91), + [53] = {.entry = {.count = 2, .reusable = false}}, REDUCE(aux_sym_service_functions_repeat2, 2, 0, 0), SHIFT_REPEAT(84), + [56] = {.entry = {.count = 2, .reusable = false}}, REDUCE(aux_sym_service_functions_repeat2, 2, 0, 0), SHIFT_REPEAT(78), + [59] = {.entry = {.count = 1, .reusable = true}}, SHIFT(23), + [61] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_type_declaration, 2, 0, 0), + [63] = {.entry = {.count = 1, .reusable = true}}, SHIFT(37), + [65] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_service_functions, 3, 0, 0), + [67] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_enum_values, 3, 0, 0), + [69] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_type_declaration, 3, 0, 0), + [71] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_enum_declaration, 3, 0, 0), + [73] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_attributes, 4, 0, 0), + [75] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_enum_values, 4, 0, 0), + [77] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_import_declaration, 3, 0, 0), + [79] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_service_declaration, 3, 0, 0), + [81] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_attributes, 2, 0, 0), + [83] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_service_functions, 2, 0, 0), + [85] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_enum_values, 2, 0, 0), + [87] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_attributes, 3, 0, 0), + [89] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_define_declaration, 4, 0, 0), + [91] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym_service_functions_repeat1, 2, 0, 0), SHIFT_REPEAT(91), + [94] = {.entry = {.count = 1, .reusable = false}}, REDUCE(aux_sym_service_functions_repeat1, 2, 0, 0), + [96] = {.entry = {.count = 1, .reusable = true}}, REDUCE(aux_sym_attributes_repeat1, 2, 0, 0), + [98] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym_attributes_repeat1, 2, 0, 0), SHIFT_REPEAT(69), + [101] = {.entry = {.count = 1, .reusable = true}}, SHIFT(24), + [103] = {.entry = {.count = 1, .reusable = true}}, SHIFT(62), + [105] = {.entry = {.count = 1, .reusable = true}}, SHIFT(18), + [107] = {.entry = {.count = 1, .reusable = true}}, SHIFT(69), + [109] = {.entry = {.count = 1, .reusable = true}}, SHIFT(25), + [111] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_type, 1, 0, 0), + [113] = {.entry = {.count = 1, .reusable = true}}, SHIFT(41), + [115] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_primitive_type, 1, 0, 0), + [117] = {.entry = {.count = 1, .reusable = false}}, SHIFT(58), + [119] = {.entry = {.count = 1, .reusable = true}}, SHIFT(36), + [121] = {.entry = {.count = 1, .reusable = false}}, SHIFT(59), + [123] = {.entry = {.count = 1, .reusable = true}}, SHIFT(34), + [125] = {.entry = {.count = 1, .reusable = false}}, REDUCE(aux_sym__string_content, 2, 0, 0), + [127] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym__string_content, 2, 0, 0), SHIFT_REPEAT(36), + [130] = {.entry = {.count = 1, .reusable = true}}, SHIFT(22), + [132] = {.entry = {.count = 1, .reusable = false}}, REDUCE(aux_sym_service_functions_repeat2, 2, 0, 0), + [134] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_map_type, 5, 0, 0), + [136] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_array_type, 2, 0, 0), + [138] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_service_notification, 4, 0, 3), + [140] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_service_notification, 4, 0, 3), + [142] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_service_function, 5, 0, 4), + [144] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_service_function, 5, 0, 4), + [146] = {.entry = {.count = 1, .reusable = true}}, SHIFT(66), + [148] = {.entry = {.count = 1, .reusable = true}}, SHIFT(83), + [150] = {.entry = {.count = 1, .reusable = true}}, SHIFT(56), + [152] = {.entry = {.count = 1, .reusable = true}}, SHIFT(35), + [154] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym_decorator_arguments_repeat1, 2, 0, 0), SHIFT_REPEAT(80), + [157] = {.entry = {.count = 1, .reusable = true}}, REDUCE(aux_sym_decorator_arguments_repeat1, 2, 0, 0), + [159] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_decorator_arguments, 4, 0, 0), + [161] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_decorator_arguments, 4, 0, 0), + [163] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym_function_arguments_repeat1, 2, 0, 0), SHIFT_REPEAT(66), + [166] = {.entry = {.count = 1, .reusable = true}}, REDUCE(aux_sym_function_arguments_repeat1, 2, 0, 0), + [168] = {.entry = {.count = 1, .reusable = true}}, SHIFT(80), + [170] = {.entry = {.count = 1, .reusable = true}}, SHIFT(48), + [172] = {.entry = {.count = 1, .reusable = true}}, SHIFT(19), + [174] = {.entry = {.count = 1, .reusable = true}}, SHIFT(44), + [176] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_decorator_arguments, 3, 0, 0), + [178] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_decorator_arguments, 3, 0, 0), + [180] = {.entry = {.count = 1, .reusable = true}}, SHIFT(70), + [182] = {.entry = {.count = 1, .reusable = true}}, SHIFT(65), + [184] = {.entry = {.count = 1, .reusable = true}}, SHIFT(96), + [186] = {.entry = {.count = 1, .reusable = true}}, SHIFT(52), + [188] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_decorator_arguments, 2, 0, 0), + [190] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_decorator_arguments, 2, 0, 0), + [192] = {.entry = {.count = 1, .reusable = true}}, SHIFT(101), + [194] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_string, 3, 0, 0), + [196] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_string, 2, 0, 0), + [198] = {.entry = {.count = 1, .reusable = true}}, SHIFT(94), + [200] = {.entry = {.count = 1, .reusable = true}}, SHIFT(15), + [202] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_enum_value_declaration, 1, 0, 0), + [204] = {.entry = {.count = 1, .reusable = true}}, SHIFT(98), + [206] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_function_decorator, 3, 0, 0), + [208] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_function_decorator, 3, 0, 0), + [210] = {.entry = {.count = 1, .reusable = true}}, REDUCE(aux_sym_enum_values_repeat1, 2, 0, 0), + [212] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym_enum_values_repeat1, 2, 0, 0), SHIFT_REPEAT(44), + [215] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_function_arguments, 2, 0, 0), + [217] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_attribute, 2, 0, 0), + [219] = {.entry = {.count = 1, .reusable = true}}, SHIFT(5), + [221] = {.entry = {.count = 1, .reusable = true}}, SHIFT(103), + [223] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_function_arguments, 4, 0, 0), + [225] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_enum_value_assignment, 3, 0, 0), + [227] = {.entry = {.count = 1, .reusable = true}}, SHIFT(11), + [229] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_enum_value, 1, 0, 0), + [231] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_function_argument, 3, 0, 0), + [233] = {.entry = {.count = 1, .reusable = true}}, SHIFT(46), + [235] = {.entry = {.count = 1, .reusable = true}}, SHIFT(54), + [237] = {.entry = {.count = 1, .reusable = true}}, SHIFT(29), + [239] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_function_arguments, 3, 0, 0), + [241] = {.entry = {.count = 1, .reusable = true}}, SHIFT(79), + [243] = {.entry = {.count = 1, .reusable = true}}, ACCEPT_INPUT(), + [245] = {.entry = {.count = 1, .reusable = true}}, SHIFT(73), + [247] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_pair, 3, 0, 1), + [249] = {.entry = {.count = 1, .reusable = true}}, SHIFT(12), + [251] = {.entry = {.count = 1, .reusable = true}}, SHIFT(8), + [253] = {.entry = {.count = 1, .reusable = true}}, SHIFT(43), + [255] = {.entry = {.count = 1, .reusable = true}}, SHIFT(77), + [257] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_pair, 4, 0, 2), + [259] = {.entry = {.count = 1, .reusable = true}}, SHIFT(6), + [261] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_map_key_type, 1, 0, 0), + [263] = {.entry = {.count = 1, .reusable = true}}, SHIFT(20), + [265] = {.entry = {.count = 1, .reusable = true}}, SHIFT(7), + [267] = {.entry = {.count = 1, .reusable = true}}, SHIFT(42), + [269] = {.entry = {.count = 1, .reusable = true}}, SHIFT(71), + [271] = {.entry = {.count = 1, .reusable = true}}, SHIFT(57), + [273] = {.entry = {.count = 1, .reusable = true}}, SHIFT(40), + [275] = {.entry = {.count = 1, .reusable = true}}, SHIFT(26), + [277] = {.entry = {.count = 1, .reusable = true}}, SHIFT(67), + [279] = {.entry = {.count = 1, .reusable = true}}, SHIFT(4), + [281] = {.entry = {.count = 1, .reusable = true}}, SHIFT(81), +}; + +#ifdef __cplusplus +extern "C" { +#endif +#ifdef TREE_SITTER_HIDE_SYMBOLS +#define TS_PUBLIC +#elif defined(_WIN32) +#define TS_PUBLIC __declspec(dllexport) +#else +#define TS_PUBLIC __attribute__((visibility("default"))) +#endif + +TS_PUBLIC const TSLanguage *tree_sitter_jrpc(void) { + static const 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 = &ts_parse_table[0][0], + .small_parse_table = ts_small_parse_table, + .small_parse_table_map = ts_small_parse_table_map, + .parse_actions = ts_parse_actions, + .symbol_names = ts_symbol_names, + .field_names = ts_field_names, + .field_map_slices = ts_field_map_slices, + .field_map_entries = ts_field_map_entries, + .symbol_metadata = ts_symbol_metadata, + .public_symbol_map = ts_symbol_map, + .alias_map = ts_non_terminal_alias_map, + .alias_sequences = &ts_alias_sequences[0][0], + .lex_modes = ts_lex_modes, + .lex_fn = ts_lex, + .primary_state_ids = ts_primary_state_ids, + }; + return &language; +} +#ifdef __cplusplus +} +#endif diff --git a/src/tree_sitter/alloc.h b/src/tree_sitter/alloc.h new file mode 100644 index 0000000..1f4466d --- /dev/null +++ b/src/tree_sitter/alloc.h @@ -0,0 +1,54 @@ +#ifndef TREE_SITTER_ALLOC_H_ +#define TREE_SITTER_ALLOC_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include + +// Allow clients to override allocation functions +#ifdef TREE_SITTER_REUSE_ALLOCATOR + +extern void *(*ts_current_malloc)(size_t); +extern void *(*ts_current_calloc)(size_t, size_t); +extern void *(*ts_current_realloc)(void *, size_t); +extern void (*ts_current_free)(void *); + +#ifndef ts_malloc +#define ts_malloc ts_current_malloc +#endif +#ifndef ts_calloc +#define ts_calloc ts_current_calloc +#endif +#ifndef ts_realloc +#define ts_realloc ts_current_realloc +#endif +#ifndef ts_free +#define ts_free ts_current_free +#endif + +#else + +#ifndef ts_malloc +#define ts_malloc malloc +#endif +#ifndef ts_calloc +#define ts_calloc calloc +#endif +#ifndef ts_realloc +#define ts_realloc realloc +#endif +#ifndef ts_free +#define ts_free free +#endif + +#endif + +#ifdef __cplusplus +} +#endif + +#endif // TREE_SITTER_ALLOC_H_ diff --git a/src/tree_sitter/array.h b/src/tree_sitter/array.h new file mode 100644 index 0000000..15a3b23 --- /dev/null +++ b/src/tree_sitter/array.h @@ -0,0 +1,290 @@ +#ifndef TREE_SITTER_ARRAY_H_ +#define TREE_SITTER_ARRAY_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "./alloc.h" + +#include +#include +#include +#include +#include + +#ifdef _MSC_VER +#pragma warning(disable : 4101) +#elif defined(__GNUC__) || defined(__clang__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunused-variable" +#endif + +#define Array(T) \ + struct { \ + T *contents; \ + uint32_t size; \ + uint32_t capacity; \ + } + +/// Initialize an array. +#define array_init(self) \ + ((self)->size = 0, (self)->capacity = 0, (self)->contents = NULL) + +/// Create an empty array. +#define array_new() \ + { NULL, 0, 0 } + +/// Get a pointer to the element at a given `index` in the array. +#define array_get(self, _index) \ + (assert((uint32_t)(_index) < (self)->size), &(self)->contents[_index]) + +/// Get a pointer to the first element in the array. +#define array_front(self) array_get(self, 0) + +/// Get a pointer to the last element in the array. +#define array_back(self) array_get(self, (self)->size - 1) + +/// Clear the array, setting its size to zero. Note that this does not free any +/// memory allocated for the array's contents. +#define array_clear(self) ((self)->size = 0) + +/// Reserve `new_capacity` elements of space in the array. If `new_capacity` is +/// less than the array's current capacity, this function has no effect. +#define array_reserve(self, new_capacity) \ + _array__reserve((Array *)(self), array_elem_size(self), new_capacity) + +/// Free any memory allocated for this array. Note that this does not free any +/// memory allocated for the array's contents. +#define array_delete(self) _array__delete((Array *)(self)) + +/// Push a new `element` onto the end of the array. +#define array_push(self, element) \ + (_array__grow((Array *)(self), 1, array_elem_size(self)), \ + (self)->contents[(self)->size++] = (element)) + +/// Increase the array's size by `count` elements. +/// New elements are zero-initialized. +#define array_grow_by(self, count) \ + do { \ + if ((count) == 0) break; \ + _array__grow((Array *)(self), count, array_elem_size(self)); \ + memset((self)->contents + (self)->size, 0, (count) * array_elem_size(self)); \ + (self)->size += (count); \ + } while (0) + +/// Append all elements from one array to the end of another. +#define array_push_all(self, other) \ + array_extend((self), (other)->size, (other)->contents) + +/// Append `count` elements to the end of the array, reading their values from the +/// `contents` pointer. +#define array_extend(self, count, contents) \ + _array__splice( \ + (Array *)(self), array_elem_size(self), (self)->size, \ + 0, count, contents \ + ) + +/// Remove `old_count` elements from the array starting at the given `index`. At +/// the same index, insert `new_count` new elements, reading their values from the +/// `new_contents` pointer. +#define array_splice(self, _index, old_count, new_count, new_contents) \ + _array__splice( \ + (Array *)(self), array_elem_size(self), _index, \ + old_count, new_count, new_contents \ + ) + +/// Insert one `element` into the array at the given `index`. +#define array_insert(self, _index, element) \ + _array__splice((Array *)(self), array_elem_size(self), _index, 0, 1, &(element)) + +/// Remove one element from the array at the given `index`. +#define array_erase(self, _index) \ + _array__erase((Array *)(self), array_elem_size(self), _index) + +/// Pop the last element off the array, returning the element by value. +#define array_pop(self) ((self)->contents[--(self)->size]) + +/// Assign the contents of one array to another, reallocating if necessary. +#define array_assign(self, other) \ + _array__assign((Array *)(self), (const Array *)(other), array_elem_size(self)) + +/// Swap one array with another +#define array_swap(self, other) \ + _array__swap((Array *)(self), (Array *)(other)) + +/// Get the size of the array contents +#define array_elem_size(self) (sizeof *(self)->contents) + +/// Search a sorted array for a given `needle` value, using the given `compare` +/// callback to determine the order. +/// +/// If an existing element is found to be equal to `needle`, then the `index` +/// out-parameter is set to the existing value's index, and the `exists` +/// out-parameter is set to true. Otherwise, `index` is set to an index where +/// `needle` should be inserted in order to preserve the sorting, and `exists` +/// is set to false. +#define array_search_sorted_with(self, compare, needle, _index, _exists) \ + _array__search_sorted(self, 0, compare, , needle, _index, _exists) + +/// Search a sorted array for a given `needle` value, using integer comparisons +/// of a given struct field (specified with a leading dot) to determine the order. +/// +/// See also `array_search_sorted_with`. +#define array_search_sorted_by(self, field, needle, _index, _exists) \ + _array__search_sorted(self, 0, _compare_int, field, needle, _index, _exists) + +/// Insert a given `value` into a sorted array, using the given `compare` +/// callback to determine the order. +#define array_insert_sorted_with(self, compare, value) \ + do { \ + unsigned _index, _exists; \ + array_search_sorted_with(self, compare, &(value), &_index, &_exists); \ + if (!_exists) array_insert(self, _index, value); \ + } while (0) + +/// Insert a given `value` into a sorted array, using integer comparisons of +/// a given struct field (specified with a leading dot) to determine the order. +/// +/// See also `array_search_sorted_by`. +#define array_insert_sorted_by(self, field, value) \ + do { \ + unsigned _index, _exists; \ + array_search_sorted_by(self, field, (value) field, &_index, &_exists); \ + if (!_exists) array_insert(self, _index, value); \ + } while (0) + +// Private + +typedef Array(void) Array; + +/// This is not what you're looking for, see `array_delete`. +static inline void _array__delete(Array *self) { + if (self->contents) { + ts_free(self->contents); + self->contents = NULL; + self->size = 0; + self->capacity = 0; + } +} + +/// This is not what you're looking for, see `array_erase`. +static inline void _array__erase(Array *self, size_t element_size, + uint32_t index) { + assert(index < self->size); + char *contents = (char *)self->contents; + memmove(contents + index * element_size, contents + (index + 1) * element_size, + (self->size - index - 1) * element_size); + self->size--; +} + +/// This is not what you're looking for, see `array_reserve`. +static inline void _array__reserve(Array *self, size_t element_size, uint32_t new_capacity) { + if (new_capacity > self->capacity) { + if (self->contents) { + self->contents = ts_realloc(self->contents, new_capacity * element_size); + } else { + self->contents = ts_malloc(new_capacity * element_size); + } + self->capacity = new_capacity; + } +} + +/// This is not what you're looking for, see `array_assign`. +static inline void _array__assign(Array *self, const Array *other, size_t element_size) { + _array__reserve(self, element_size, other->size); + self->size = other->size; + memcpy(self->contents, other->contents, self->size * element_size); +} + +/// This is not what you're looking for, see `array_swap`. +static inline void _array__swap(Array *self, Array *other) { + Array swap = *other; + *other = *self; + *self = swap; +} + +/// This is not what you're looking for, see `array_push` or `array_grow_by`. +static inline void _array__grow(Array *self, uint32_t count, size_t element_size) { + uint32_t new_size = self->size + count; + if (new_size > self->capacity) { + uint32_t new_capacity = self->capacity * 2; + if (new_capacity < 8) new_capacity = 8; + if (new_capacity < new_size) new_capacity = new_size; + _array__reserve(self, element_size, new_capacity); + } +} + +/// This is not what you're looking for, see `array_splice`. +static inline void _array__splice(Array *self, size_t element_size, + uint32_t index, uint32_t old_count, + uint32_t new_count, const void *elements) { + uint32_t new_size = self->size + new_count - old_count; + uint32_t old_end = index + old_count; + uint32_t new_end = index + new_count; + assert(old_end <= self->size); + + _array__reserve(self, element_size, new_size); + + char *contents = (char *)self->contents; + if (self->size > old_end) { + memmove( + contents + new_end * element_size, + contents + old_end * element_size, + (self->size - old_end) * element_size + ); + } + if (new_count > 0) { + if (elements) { + memcpy( + (contents + index * element_size), + elements, + new_count * element_size + ); + } else { + memset( + (contents + index * element_size), + 0, + new_count * element_size + ); + } + } + self->size += new_count - old_count; +} + +/// A binary search routine, based on Rust's `std::slice::binary_search_by`. +/// This is not what you're looking for, see `array_search_sorted_with` or `array_search_sorted_by`. +#define _array__search_sorted(self, start, compare, suffix, needle, _index, _exists) \ + do { \ + *(_index) = start; \ + *(_exists) = false; \ + uint32_t size = (self)->size - *(_index); \ + if (size == 0) break; \ + int comparison; \ + while (size > 1) { \ + uint32_t half_size = size / 2; \ + uint32_t mid_index = *(_index) + half_size; \ + comparison = compare(&((self)->contents[mid_index] suffix), (needle)); \ + if (comparison <= 0) *(_index) = mid_index; \ + size -= half_size; \ + } \ + comparison = compare(&((self)->contents[*(_index)] suffix), (needle)); \ + if (comparison == 0) *(_exists) = true; \ + else if (comparison < 0) *(_index) += 1; \ + } while (0) + +/// Helper macro for the `_sorted_by` routines below. This takes the left (existing) +/// parameter by reference in order to work with the generic sorting function above. +#define _compare_int(a, b) ((int)*(a) - (int)(b)) + +#ifdef _MSC_VER +#pragma warning(default : 4101) +#elif defined(__GNUC__) || defined(__clang__) +#pragma GCC diagnostic pop +#endif + +#ifdef __cplusplus +} +#endif + +#endif // TREE_SITTER_ARRAY_H_ diff --git a/src/tree_sitter/parser.h b/src/tree_sitter/parser.h new file mode 100644 index 0000000..799f599 --- /dev/null +++ b/src/tree_sitter/parser.h @@ -0,0 +1,266 @@ +#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 TSStateId; +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 *); + void (*log)(const TSLexer *, const char *, ...); +}; + +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; + +typedef struct { + int32_t start; + int32_t end; +} TSCharacterRange; + +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 * const *symbol_names; + const char * const *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; + 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 + */ + +#ifdef _MSC_VER +#define UNUSED __pragma(warning(suppress : 4101)) +#else +#define UNUSED __attribute__((unused)) +#endif + +#define START_LEXER() \ + bool result = false; \ + bool skip = false; \ + UNUSED \ + 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 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; \ + 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_name, children, precedence, prod_id) \ + {{ \ + .reduce = { \ + .type = TSParseActionTypeReduce, \ + .symbol = symbol_name, \ + .child_count = children, \ + .dynamic_precedence = precedence, \ + .production_id = prod_id \ + }, \ + }} + +#define RECOVER() \ + {{ \ + .type = TSParseActionTypeRecover \ + }} + +#define ACCEPT_INPUT() \ + {{ \ + .type = TSParseActionTypeAccept \ + }} + +#ifdef __cplusplus +} +#endif + +#endif // TREE_SITTER_PARSER_H_