pax_global_header00006660000000000000000000000064151071277250014521gustar00rootroot0000000000000052 comment=f0285fe577ad298ad79f8633e643ad60646e3027 tree-sitter-ini-1.4.0/000077500000000000000000000000001510712772500145475ustar00rootroot00000000000000tree-sitter-ini-1.4.0/.editorconfig000066400000000000000000000011401510712772500172200ustar00rootroot00000000000000root = true [*] charset = utf-8 end_of_line = lf insert_final_newline = true trim_trailing_whitespace = true [*.{json,toml,yml,gyp}] indent_style = space indent_size = 2 [*.js] indent_style = space indent_size = 2 [*.txt] # Test/corpus files may intentionally have trailing whitespace. trim_trailing_whitespace = false [*.rs] indent_style = space indent_size = 4 [*.{c,cc,h}] 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 tree-sitter-ini-1.4.0/.gitattributes000066400000000000000000000004121510712772500174370ustar00rootroot00000000000000* text 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 tree-sitter-ini-1.4.0/.gitignore000066400000000000000000000005041510712772500165360ustar00rootroot00000000000000# Rust artifacts target/ # Node artifacts build/ prebuilds/ node_modules/ # Swift artifacts .build/ # Go artifacts _obj/ # Python artifacts .venv/ dist/ *.egg-info *.whl # C artifacts *.a *.so *.so.* *.dylib *.dll *.pc # Example dirs /examples/*/ # Grammar volatiles *.wasm *.obj *.o # Archives *.tar.gz *.tgz *.zip tree-sitter-ini-1.4.0/CMakeLists.txt000066400000000000000000000053551510712772500173170ustar00rootroot00000000000000cmake_minimum_required(VERSION 3.13) project(tree-sitter-ini VERSION "1.4.0" DESCRIPTION "Ini grammar for tree-sitter" HOMEPAGE_URL "https://github.com/justinmk/tree-sitter-ini" LANGUAGES C) option(BUILD_SHARED_LIBS "Build using shared libraries" ON) option(TREE_SITTER_REUSE_ALLOCATOR "Reuse the library allocator" OFF) set(TREE_SITTER_ABI_VERSION 15 CACHE STRING "Tree-sitter ABI version") if(NOT ${TREE_SITTER_ABI_VERSION} MATCHES "^[0-9]+$") unset(TREE_SITTER_ABI_VERSION CACHE) message(FATAL_ERROR "TREE_SITTER_ABI_VERSION must be an integer") endif() find_program(TREE_SITTER_CLI tree-sitter DOC "Tree-sitter CLI") add_custom_command(OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/src/parser.c" DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/grammar.json" COMMAND "${TREE_SITTER_CLI}" generate src/grammar.json --abi=${TREE_SITTER_ABI_VERSION} WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" COMMENT "Generating parser.c") add_library(tree-sitter-ini src/parser.c) if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/src/scanner.c) target_sources(tree-sitter-ini PRIVATE src/scanner.c) endif() target_include_directories(tree-sitter-ini PRIVATE src INTERFACE $ $) target_compile_definitions(tree-sitter-ini PRIVATE $<$:TREE_SITTER_REUSE_ALLOCATOR> $<$:TREE_SITTER_DEBUG>) set_target_properties(tree-sitter-ini PROPERTIES C_STANDARD 11 POSITION_INDEPENDENT_CODE ON SOVERSION "${TREE_SITTER_ABI_VERSION}.${PROJECT_VERSION_MAJOR}" DEFINE_SYMBOL "") configure_file(bindings/c/tree-sitter-ini.pc.in "${CMAKE_CURRENT_BINARY_DIR}/tree-sitter-ini.pc" @ONLY) include(GNUInstallDirs) install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bindings/c/tree_sitter" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" FILES_MATCHING PATTERN "*.h") install(FILES "${CMAKE_CURRENT_BINARY_DIR}/tree-sitter-ini.pc" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig") install(TARGETS tree-sitter-ini LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") file(GLOB QUERIES queries/*.scm) install(FILES ${QUERIES} DESTINATION "${CMAKE_INSTALL_DATADIR}/tree-sitter/queries/ini") add_custom_target(ts-test "${TREE_SITTER_CLI}" test WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" COMMENT "tree-sitter test") tree-sitter-ini-1.4.0/Cargo.toml000066400000000000000000000010131510712772500164720ustar00rootroot00000000000000[package] name = "tree-sitter-ini" description = "ini grammar for the tree-sitter parsing library" version = "1.4.0" keywords = ["incremental", "parsing", "ini"] categories = ["parsing", "text-editors"] repository = "https://github.com/justinmk/tree-sitter-ini" edition = "2018" license = "MIT" build = "bindings/rust/build.rs" include = [ "bindings/rust/*", "grammar.js", "queries/*", "src/*", ] [lib] path = "bindings/rust/lib.rs" [dependencies] tree-sitter-language = "0.1.0" [build-dependencies] cc = "1.0" tree-sitter-ini-1.4.0/LICENSE000066400000000000000000000261351510712772500155630ustar00rootroot00000000000000 Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. tree-sitter-ini-1.4.0/Makefile000066400000000000000000000071111510712772500162070ustar00rootroot00000000000000VERSION := 1.4.0 LANGUAGE_NAME := tree-sitter-ini # 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 # ABI versioning SONAME_MAJOR := $(word 1,$(subst ., ,$(VERSION))) SONAME_MINOR := $(word 2,$(subst ., ,$(VERSION))) # 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 # OS-specific bits ifeq ($(OS),Windows_NT) $(error "Windows is not supported") else ifeq ($(shell uname),Darwin) SOEXT = dylib SOEXTVER_MAJOR = $(SONAME_MAJOR).dylib SOEXTVER = $(SONAME_MAJOR).$(SONAME_MINOR).dylib LINKSHARED := $(LINKSHARED)-dynamiclib -Wl, ifneq ($(ADDITIONAL_LIBS),) LINKSHARED := $(LINKSHARED)$(ADDITIONAL_LIBS), endif LINKSHARED := $(LINKSHARED)-install_name,$(LIBDIR)/lib$(LANGUAGE_NAME).$(SONAME_MAJOR).dylib,-rpath,@executable_path/../Frameworks else SOEXT = so SOEXTVER_MAJOR = so.$(SONAME_MAJOR) SOEXTVER = so.$(SONAME_MAJOR).$(SONAME_MINOR) LINKSHARED := $(LINKSHARED)-shared -Wl, ifneq ($(ADDITIONAL_LIBS),) LINKSHARED := $(LINKSHARED)$(ADDITIONAL_LIBS) endif LINKSHARED := $(LINKSHARED)-soname,lib$(LANGUAGE_NAME).so.$(SONAME_MAJOR) 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 tree-sitter-ini-1.4.0/Package.swift000066400000000000000000000027011510712772500171600ustar00rootroot00000000000000// swift-tools-version:5.3 import PackageDescription let package = Package( name: "TreeSitterIni", products: [ .library(name: "TreeSitterIni", targets: ["TreeSitterIni"]), ], dependencies: [], targets: [ .target(name: "TreeSitterIni", 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")]) ], cLanguageStandard: .c11 ) tree-sitter-ini-1.4.0/README.md000066400000000000000000000033171510712772500160320ustar00rootroot00000000000000tree-sitter-ini ================== This grammar implements the [INI format](https://en.wikipedia.org/wiki/INI_file). Overview -------- Example INI file: ```ini [section 1] some_key = some_value another-key = another value [another section] # Keys may contain whitespace. key 1 = value 1 # Value may be empty. key_2 = ``` See [test/corpus/](./test/corpus/) for more examples. Notes ----- - Section name must appear on a line by itself. - Equals sign (=) and semicolon (;) are [reserved characters](https://en.wikipedia.org/wiki/INI_file#Key-value_pairs) and cannot appear in the key. Any whitespace surrounding the key is stripped. - Comments (`;` or `#`) must start at column 1. Trailing comments are not supported yet. [#13](https://github.com/justinmk/tree-sitter-ini/issues/13) - Duplicate names are not checked. - Line continuations (`\`) are not supported. - `setting_value` includes whitespace. [#3](https://github.com/justinmk/tree-sitter-ini/issues/3). Should values exclude surrounding whitespace? - [Quoted keys/values](https://en.wikipedia.org/wiki/INI_file#Quoted_values) are not supported yet. - Escape sequences are not supported. Reference --------- - https://en.wikipedia.org/wiki/INI_file - https://github.com/textmate/ini.tmbundle Release ------- Steps to perform a release: 1. Bump and tag the version (choose `patch`/`minor`/`major` as appropriate). ``` npm version patch -m "release %s" ``` 2. Bump to prerelease, without creating a tag . ``` npm version --no-git-tag-version prerelease --preid dev && git add package*.json && git commit -m bump ``` 3. Push. ``` git push --follow-tags ``` 4. Release the tagged commit: https://github.com/justinmk/tree-sitter-ini/releases/new tree-sitter-ini-1.4.0/binding.gyp000066400000000000000000000012041510712772500166770ustar00rootroot00000000000000{ "targets": [ { "target_name": "tree_sitter_ini_binding", "dependencies": [ " typedef struct TSLanguage TSLanguage; extern "C" TSLanguage *tree_sitter_ini(); // "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, "ini"); auto language = Napi::External::New(env, tree_sitter_ini()); language.TypeTag(&LANGUAGE_TYPE_TAG); exports["language"] = language; return exports; } NODE_API_MODULE(tree_sitter_ini_binding, Init) tree-sitter-ini-1.4.0/bindings/node/binding_test.js000066400000000000000000000004041510712772500222760ustar00rootroot00000000000000/// 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("."))); }); tree-sitter-ini-1.4.0/bindings/node/index.d.ts000066400000000000000000000007041510712772500211730ustar00rootroot00000000000000type 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; tree-sitter-ini-1.4.0/bindings/node/index.js000066400000000000000000000003111510712772500207310ustar00rootroot00000000000000const root = require("path").join(__dirname, "..", ".."); module.exports = require("node-gyp-build")(root); try { module.exports.nodeTypeInfo = require("../../src/node-types.json"); } catch (_) {} tree-sitter-ini-1.4.0/bindings/python/000077500000000000000000000000001510712772500176655ustar00rootroot00000000000000tree-sitter-ini-1.4.0/bindings/python/tests/000077500000000000000000000000001510712772500210275ustar00rootroot00000000000000tree-sitter-ini-1.4.0/bindings/python/tests/test_binding.py000066400000000000000000000004371510712772500240560ustar00rootroot00000000000000from unittest import TestCase import tree_sitter, tree_sitter_ini class TestLanguage(TestCase): def test_can_load_grammar(self): try: tree_sitter.Language(tree_sitter_ini.language()) except Exception: self.fail("Error loading Ini grammar") tree-sitter-ini-1.4.0/bindings/python/tree_sitter_ini/000077500000000000000000000000001510712772500230555ustar00rootroot00000000000000tree-sitter-ini-1.4.0/bindings/python/tree_sitter_ini/__init__.py000066400000000000000000000001261510712772500251650ustar00rootroot00000000000000"Ini grammar for tree-sitter" from ._binding import language __all__ = ["language"] tree-sitter-ini-1.4.0/bindings/python/tree_sitter_ini/__init__.pyi000066400000000000000000000000331510712772500253330ustar00rootroot00000000000000def language() -> int: ... tree-sitter-ini-1.4.0/bindings/python/tree_sitter_ini/binding.c000066400000000000000000000012451510712772500246350ustar00rootroot00000000000000#include typedef struct TSLanguage TSLanguage; TSLanguage *tree_sitter_ini(void); static PyObject* _binding_language(PyObject *Py_UNUSED(self), PyObject *Py_UNUSED(args)) { return PyCapsule_New(tree_sitter_ini(), "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); } tree-sitter-ini-1.4.0/bindings/python/tree_sitter_ini/py.typed000066400000000000000000000000001510712772500245420ustar00rootroot00000000000000tree-sitter-ini-1.4.0/bindings/rust/000077500000000000000000000000001510712772500173415ustar00rootroot00000000000000tree-sitter-ini-1.4.0/bindings/rust/build.rs000066400000000000000000000025451510712772500210140ustar00rootroot00000000000000fn main() { let src_dir = std::path::Path::new("src"); let mut c_config = cc::Build::new(); c_config.include(&src_dir); c_config .flag_if_supported("-Wno-unused-parameter") .flag_if_supported("-Wno-unused-but-set-variable") .flag_if_supported("-Wno-trigraphs"); #[cfg(target_env = "msvc")] c_config.flag("-utf-8"); let parser_path = src_dir.join("parser.c"); c_config.file(&parser_path); // If your language uses an external scanner written in C, // then include this block of code: /* let scanner_path = src_dir.join("scanner.c"); c_config.file(&scanner_path); println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap()); */ c_config.compile("parser"); println!("cargo:rerun-if-changed={}", parser_path.to_str().unwrap()); // If your language uses an external scanner written in C++, // then include this block of code: /* let mut cpp_config = cc::Build::new(); cpp_config.cpp(true); cpp_config.include(&src_dir); cpp_config .flag_if_supported("-Wno-unused-parameter") .flag_if_supported("-Wno-unused-but-set-variable"); let scanner_path = src_dir.join("scanner.cc"); cpp_config.file(&scanner_path); cpp_config.compile("scanner"); println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap()); */ } tree-sitter-ini-1.4.0/bindings/rust/lib.rs000066400000000000000000000036351510712772500204640ustar00rootroot00000000000000//! This crate provides Ini 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_ini::LANGUAGE; //! parser //! .set_language(&language.into()) //! .expect("Error loading Ini 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_ini() -> *const (); } /// The tree-sitter [`LanguageFn`] for this grammar. pub const LANGUAGE: LanguageFn = unsafe { LanguageFn::from_raw(tree_sitter_ini) }; /// 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 Ini parser"); } } tree-sitter-ini-1.4.0/bindings/swift/000077500000000000000000000000001510712772500175005ustar00rootroot00000000000000tree-sitter-ini-1.4.0/bindings/swift/TreeSitterIni/000077500000000000000000000000001510712772500222325ustar00rootroot00000000000000tree-sitter-ini-1.4.0/bindings/swift/TreeSitterIni/ini.h000066400000000000000000000003521510712772500231620ustar00rootroot00000000000000#ifndef TREE_SITTER_INI_H_ #define TREE_SITTER_INI_H_ typedef struct TSLanguage TSLanguage; #ifdef __cplusplus extern "C" { #endif const TSLanguage *tree_sitter_ini(void); #ifdef __cplusplus } #endif #endif // TREE_SITTER_INI_H_ tree-sitter-ini-1.4.0/bindings/swift/TreeSitterIniTests/000077500000000000000000000000001510712772500232555ustar00rootroot00000000000000tree-sitter-ini-1.4.0/bindings/swift/TreeSitterIniTests/TreeSitterIniTests.swift000066400000000000000000000005431510712772500301120ustar00rootroot00000000000000import XCTest import SwiftTreeSitter import TreeSitterIni final class TreeSitterIniTests: XCTestCase { func testCanLoadGrammar() throws { let parser = Parser() let language = Language(language: tree_sitter_ini()) XCTAssertNoThrow(try parser.setLanguage(language), "Error loading Ini grammar") } } tree-sitter-ini-1.4.0/go.mod000066400000000000000000000001541510712772500156550ustar00rootroot00000000000000module github.com/tree-sitter/tree-sitter-ini go 1.23 require github.com/tree-sitter/go-tree-sitter v0.23 tree-sitter-ini-1.4.0/grammar.js000066400000000000000000000016651510712772500165430ustar00rootroot00000000000000/// // @ts-check module.exports = grammar({ name: 'ini', extras: $ => [ $.comment, $._blank, /[\t ]/ ], rules: { document: $ => seq( repeat($._blank), // Eat blank lines at top of file. optional(repeat(seq($.setting))), repeat($.section), ), // Section has: // - a title // - zero or more settings (name=value pairs) // - comments (optional) section: $ => prec.left(seq( $.section_name, repeat(seq( $.setting, )), )), section_name: $ => seq( '[', alias(/[^\[\]]+/, $.text), ']', /\r?\n/, ), setting: $ => seq( alias(/[^;#=\s\[]+( *[^;#=\s\[])*/, $.setting_name), '=', optional(alias(/.+/, $.setting_value)), /\r?\n/, ), comment: $ => seq(/[;#]/, alias(/[^\r\n]*/, $.text), /\r?\n/), _blank: () => field('blank', /\r?\n/), } }); tree-sitter-ini-1.4.0/notes.md000066400000000000000000000337201510712772500162260ustar00rootroot00000000000000# treesitter ini, aws-config This is a tree-sitter experience report. ## Why treesitter? > Tree-sitter uses context-aware tokenization - in a given parse state, > Tree-sitter only recognizes tokens that are syntactically valid in that > state. This is what allows Tree-sitter to tokenize languages correctly > without requiring the grammar author to think about different lexer modes. — [ref](https://github.com/tree-sitter/tree-sitter/pull/1635) tree-sitter has nice docs to walkthrough this: https://tree-sitter.github.io/tree-sitter/creating-parsers https://siraben.dev/2022/03/01/tree-sitter.html is another good tutorial and provides some motivation for treesitter: ## Experience report "tree-sitter" should be named "treesitter". There is zero reason to choose a multi-word name if you can avoid it. Multi-word names manifest in various forms depending on the context: "treeSitter", "TreeSitter", "tree_sitter", "tree-sitter". This is worthless entropy. Here's the C code for an `.ini` parser generated by tree-sitter. It has an API exposed as a C dynamic library, usable from any language. How did I do this? See below. #include … enum { … sym_setting_name = 6, sym_setting_value = 7, … }; static const char *ts_symbol_names[] = { [sym_setting_name] = "setting_name", [sym_setting_value] = "setting_value", … }; static bool ts_lex(TSLexer *lexer, TSStateId state) { START_LEXER(); eof = lexer->eof(lexer); switch (state) { case 0: … END_STATE(); … case 8: ACCEPT_TOKEN(aux_sym_section_name_token1); if (lookahead == '\n') ADVANCE(10); if (lookahead == '[' || lookahead == ']') ADVANCE(19); if (lookahead != 0) ADVANCE(8); END_STATE(); … case 14: ACCEPT_TOKEN(sym_setting_name); if (lookahead == '\n') ADVANCE(16); if (lookahead == '=') ADVANCE(19); if (lookahead != 0) ADVANCE(14); END_STATE(); … } } static uint16_t ts_parse_table[LARGE_STATE_COUNT][SYMBOL_COUNT] = { [0] = { … }, [1] = { … [sym_section] = STATE(3), [sym_section_name] = STATE(2), }, }; Creating a new parser for the INI file type ------------------------------------------- $ npm init # Install a small module that lets your parser be used from Node. $ npm install --save nan # Install (and depend-on) the Tree-sitter CLI. $ npm install --save-dev tree-sitter-cli Create the grammar.js stub -------------------------- `grammar.js`: module.exports = grammar({ name: 'ini', rules: { // TODO: add the actual grammar rules source_file: $ => 'hello' } }); Generate the parser ------------------- $ ./node_modules/.bin/tree-sitter generate That generates `src/parser.c` from the `grammar.js` that we defined (typically tree-sitter projects put this in their `npm run build` script in `package.json`). The parser can be tested now: $ echo hello > test $ ./node_modules/.bin/tree-sitter parse test (source_file [0, 0] - [1, 0]) It also generates some glue files to compile the parser's C source a library and load it as a Node.js module. Cool! - `binding.gyp` tells Node.js how to compile the parser's C source. - `tree-sitter generate` automatically compiles `parser.c` into a dynamically-loadable library. - `index.js` is the entrypoint for Node.js to load the compiled C module. - `src/binding.cc` wraps your parser in a JavaScript object for Node.js - `src/tree_sitter/parser.h` is a C header by `parser.c`. Tree-sitter will detect ambiguity. For example this `grammar.js` is ambiguous: module.exports = grammar({ name: 'ini', rules: { document: $ => $._value, _value: $ => choice( $.a, $.b, ), a: $ => 'hello', b: $ => 'hello' } }); Tree-sitter throws a `Unresolved conflict` error when it detects ambiguity: $ ./node_modules/.bin/tree-sitter generate Unresolved conflict for symbol sequence: 'hello' • EOF … Possible interpretations: 1: (a 'hello') • EOF … 2: (b 'hello') • EOF … Possible resolutions: 1: Specify a higher precedence in `a` than in the other rules. 2: Specify a higher precedence in `b` than in the other rules. 3: Add a conflict for these rules: `a`, `b` Developing the grammar, part 1 ------------------------------ One of my favorite things about tree-sitter is its use of S-expressions ("sexps") to **define test-cases** and **pretty-print** the AST. S-expressions are the human-readable representation of the AST. They are similar to HTML/XML/SGML (but simpler and older): just a very simple way to express a tree of things. Here's the first test for my "ini" grammar: ================== Test 1 ================== foo = bar --- () It fails: $ ./node_modules/.bin/tree-sitter test main: ✗ Test 1 1 failure: expected / actual 1. Test 1: (ERROR (UNEXPECTED 'f')) () (ERROR (UNEXPECTED 'f')) () Now I can start developing the grammar. Tree-sitter provides a [DSL](https://tree-sitter.github.io/tree-sitter/creating-parsers#the-grammar-dsl) to define grammars. - `name`: Name of the grammar. - `rules`: - Symbols (the `$` object): Use `$.foo` to another grammar symbol within a rule. - String and Regex literals: terminal symbols. - Sequences: `seq(rule1, rule2, …)`: matches rules in the given order. - Alternatives: `choice(rule1, rule2, …)`: matches any one rule in the set. - Repetitions: `repeat(rule)` matches _zero-or-more_ rules. - `repeat1(rule)` matches _one-or-more_ rules. - `optional(rule)` matches _zero-or-one_ rule. - Precedence: `prec(number, rule)` marks a rule with a precedence to resolve ambiguities ("LR(1) conflicts") - `prec.left([number], rule)` marks a rule as _left-associative_, i.e. prefers a match that ends _earlier_. - `prec.right([number], rule)` prefers a match that ends _later_. - `prec.dynamic(number, rule)` decides precedence at runtime! Uses the `conflicts` field in the grammar, when there is a "genuine ambiguity" (multiple matching rules). - `token(rule)` marks a rule as producing a single token; the entire rule subtree will be handled atomically by the lexer, as if you had written it all using a single regular expression. - Its content will be represented in the final syntax tree as a single leaf node. (Whereas If you don't use TOKEN, there will be a separate leaf node in the tree for each string literal or regexp in the subtree.) - `alias(rule, name)` renames a rule in the AST. - Example: `alias($.foo, $.bar)` appears as _named_ node `bar` - Example: `alias($.foo, 'bar')` appears as _anonymous_ node "bar". - `field(name, rule)` assigns a _field name_ to the matching child nodes, which can be used to access the nodes from the AST. - `extras`: array of tokens that may appear _anywhere_. Often used for whitespace and comments. Example (also the default!): ``` extras: $ => [ /\s/ ], ``` - `inline`: useful for rules used in multiple places but for which you don’t want AST nodes. - `conflicts`: defines _intentional_ ambiguities (LR(1) conflicts), which tree-sitter will resolve at _runtime_ (dynamic precedence). - `externals`: token names which can be returned by an external scanner. Allows you to write custom C code which runs during the lexing process to handle non-regular lexical rules (e.g. Python indentation). - `word`: matches keywords for keyword extraction optimization. - `supertypes`: hidden rules considered to be ‘supertypes’ in the generated _node types_ file (useful for statically-typed languages) Reading about `seq()` gives me enough to try a toy rule for the "ini" grammar: - `grammar.js`: ``` module.exports = grammar({ name: 'ini', rules: { document: $ => $._value, _value: $ => choice( $.kvpair, ), kvpair: $ => seq( /[^=]+/, '=', /.+/ ), } }); ``` - `test/corpus/main.txt`: ``` ================== Test 1 ================== foo = bar --- (document (kvpair)) ``` The test passes... $ ./node_modules/.bin/tree-sitter generate && ./node_modules/.bin/tree-sitter test main: ✓ Test 1 ...but this initial grammar lacks granularity: it doesn't parse the individual parts of `kvpair`, i.e. we probably want "key" and "value". And it feels wrong to use regex to exclude "=", that will probably be avoided more "formally" in the final grammar. In fact [this section](https://tree-sitter.github.io/tree-sitter/creating-parsers#writing-the-grammar) of the docs mentions two properties to write a good parser: 1. _Intuitive structure._ Because the grammar directly influences the structure of the AST! 2. _Adherence to LR(1)._ For optimal performance. Developing the grammar, part 2 ------------------------------ Now that I have a toy grammar feeding into a passing test, I am ready to experiment. - I see [tree-sitter-json grammar](https://github.com/tree-sitter/tree-sitter-json/blob/d3976b27df8622ed17bef6dd5e358b398e73c676/grammar.js#L54) combines `seq(optional(choice(…)))` in a rule--even assigning rules to local variables--and return a single rule via `return token(…)`. - I see that [tree-sitter-javascript](https://github.com/tree-sitter/tree-sitter-javascript/blob/a2e3d72f82716a20982ecc06c349c54ec40d54df/grammar.js#L35) includes comments in its `extra` directive. ini files are very simple: - they have three parts: section, settings, and comments ``` [section 1] a = val1 b = val2 # comment ``` - a section might not have any "content", only a title: ``` [section 1] ``` From there I'm able to introduce a `setting` rule, and define `section` in terms of `section_name` and `setting`. module.exports = grammar({ name: 'ini', extras: $ => [ $.comment, /\s/, ], rules: { document: $ => repeat( $.section ), section: $ => { return seq( // Section must have a name. $.section_name, // Section has zero or more settings (name=value pairs). repeat($.setting), ) }, section_name: $ => seq( '[', /[^\[\]]+/, ']', '\n', // Section name must be on its own line. ), setting: $ => seq( $.setting_name, '=', $.setting_value, '\n', // Only one setting per line. ), setting_name: $ => /[^=]+/, setting_value: $ => /.+/, comment: $ => token( seq('#', /.*/), ), } }); That passes this updated test: ================== Test 1 ================== [a section title] foo = bar --- (document (section (section_name) (setting (setting_name) (setting_value)))) # Actually use it! Now we can actually parse stuff! Such as [this AWS config example](https://docs.aws.amazon.com/credref/latest/refdocs/file-format.html): File `test-awsconfig`: [default] region = us-west-2 output = json [profile dev-user] region = us-east-1 output = text [profile developers] role_arn = arn:aws:iam::123456789012:role/developers source_profile = dev-user region = us-west-2 output = json Parse it: $ ./node_modules/.bin/tree-sitter parse test-awsconfig (document [0, 0] - [13, 0] (section [0, 0] - [13, 0] (section_name [0, 0] - [1, 0]) (setting [1, 0] - [2, 0] (setting_name [1, 0] - [1, 7]) (setting_value [1, 8] - [1, 18])) (setting [2, 0] - [4, 0] (setting_name [2, 0] - [2, 7]) (setting_value [2, 8] - [2, 13])) (setting [4, 0] - [6, 0] (setting_name [4, 0] - [5, 7]) (setting_value [5, 8] - [5, 18])) (setting [6, 0] - [8, 0] (setting_name [6, 0] - [6, 7]) (setting_value [6, 8] - [6, 13])) (setting [8, 0] - [10, 0] (setting_name [8, 0] - [9, 9]) (setting_value [9, 10] - [9, 52])) (setting [10, 0] - [11, 0] (setting_name [10, 0] - [10, 15]) (setting_value [10, 16] - [10, 25])) (setting [11, 0] - [12, 0] (setting_name [11, 0] - [11, 7]) (setting_value [11, 8] - [11, 18])) (setting [12, 0] - [13, 0] (setting_name [12, 0] - [12, 7]) (setting_value [12, 8] - [12, 13])))) # Error handling One of the most valuable features of a parser-generator is its ability to flag errors and report _where_ the error occurred in the source code. An ini file without a section heading is an error. foo = bar $ ./node_modules/.bin/tree-sitter parse test-awsconfig (document [0, 0] - [1, 0] (ERROR [0, 0] - [0, 9] (ERROR [0, 0] - [0, 3]) (ERROR [0, 6] - [0, 9]))) # Preventing duplicate symbols From an [early tree-sitter discussion](https://github.com/tree-sitter/tree-sitter/issues/130#issuecomment-364830185), author Max Brunsfeld: > Thus far, I don't really consider "type II correctness" to be a goal for Tree-sitter, because I think it's fundamentally incompatible with one of the most important goals of the project: to be able to parse source code files based solely on their language, without knowing any auxiliary information about the files. > > For example, tree-sitter-python should be able to parse any python code you can find, without knowing what python version the code is meant to run on. That means it needs to parse the union of Python 2 and Python 3. # Capturing whitespace Whitespace will be included in _all_ nodes if you have _any_ `$.word` node that captures leading whitespace. tree-sitter-ini-1.4.0/package-lock.json000066400000000000000000000314301510712772500177640ustar00rootroot00000000000000{ "name": "tree-sitter-ini", "version": "1.4.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "tree-sitter-ini", "version": "1.4.0", "hasInstallScript": true, "license": "Apache-2.0", "dependencies": { "node-addon-api": "^7.1.0", "node-gyp-build": "^4.8.0" }, "devDependencies": { "prebuildify": "^6.0.0", "tree-sitter-cli": "^0.20.8" }, "peerDependencies": { "tree-sitter": "^0.21.0" }, "peerDependenciesMeta": { "tree_sitter": { "optional": true } } }, "node_modules/base64-js": { "version": "1.5.1", "resolved": "https://registry.npmjs.org/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://registry.npmjs.org/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://registry.npmjs.org/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://registry.npmjs.org/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://registry.npmjs.org/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://registry.npmjs.org/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://registry.npmjs.org/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://registry.npmjs.org/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://registry.npmjs.org/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://registry.npmjs.org/mkdirp-classic/-/mkdirp-classic-0.5.3.tgz", "integrity": "sha512-gKLcREMhtuZRwRAfqP3RFW+TK4JqApVBtOIftVgjuABpAtpxhPGaDcfvbhNvD0B8iD1oUr/txX35NjcaY6Ns/A==", "dev": true, "license": "MIT" }, "node_modules/node-abi": { "version": "3.74.0", "resolved": "https://registry.npmjs.org/node-abi/-/node-abi-3.74.0.tgz", "integrity": "sha512-c5XK0MjkGBrQPGYG24GBADZud0NCbznxNx0ZkS+ebUTrmV1qTDxPxSL8zEAPURXSbLRWVexxmP4986BziahL5w==", "dev": true, "license": "MIT", "dependencies": { "semver": "^7.3.5" }, "engines": { "node": ">=10" } }, "node_modules/node-addon-api": { "version": "7.1.1", "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-7.1.1.tgz", "integrity": "sha512-5m3bsyrjFWE1xf7nz7YXdN4udnVtXK6/Yfgn5qnahL6bCkf2yKt4k3nuTKAtT4r3IG8JNR2ncsIMdZuAzJjHQQ==", "license": "MIT" }, "node_modules/node-gyp-build": { "version": "4.8.4", "resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.8.4.tgz", "integrity": "sha512-LA4ZjwlnUblHVgq0oBF3Jl/6h/Nvs5fzBLwdEF4nuxnFdsfajde4WfxtJr3CaiH+F6ewcIB/q4jQ4UzPyid+CQ==", "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://registry.npmjs.org/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://registry.npmjs.org/once/-/once-1.4.0.tgz", "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==", "dev": true, "license": "ISC", "dependencies": { "wrappy": "1" } }, "node_modules/path-key": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/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://registry.npmjs.org/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://registry.npmjs.org/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://registry.npmjs.org/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://registry.npmjs.org/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.7.1", "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.1.tgz", "integrity": "sha512-hlq8tAfn0m/61p4BVRcPzIGr6LKiMwo4VM6dGi6pt4qcRkmNzTcWq6eCEjEh+qXjkMDvPlOFFSGwQjoEa6gyMA==", "dev": true, "license": "ISC", "bin": { "semver": "bin/semver.js" }, "engines": { "node": ">=10" } }, "node_modules/string_decoder": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/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.4", "resolved": "https://registry.npmjs.org/tar-fs/-/tar-fs-2.1.4.tgz", "integrity": "sha512-mDAjwmZdh7LTT6pNleZ05Yt65HC3E+NiQzl672vQG38jIrehtJk/J3mNwIg+vShQPcLF/LV7CMnDW6vjj6sfYQ==", "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://registry.npmjs.org/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": { "version": "0.21.1", "resolved": "https://registry.npmjs.org/tree-sitter/-/tree-sitter-0.21.1.tgz", "integrity": "sha512-7dxoA6kYvtgWw80265MyqJlkRl4yawIjO7S5MigytjELkX43fV2WsAXzsNfO7sBpPPCF5Gp0+XzHk0DwLCq3xQ==", "hasInstallScript": true, "license": "MIT", "dependencies": { "node-addon-api": "^8.0.0", "node-gyp-build": "^4.8.0" } }, "node_modules/tree-sitter-cli": { "version": "0.20.8", "resolved": "https://registry.npmjs.org/tree-sitter-cli/-/tree-sitter-cli-0.20.8.tgz", "integrity": "sha512-XjTcS3wdTy/2cc/ptMLc/WRyOLECRYcMTrSWyhZnj1oGSOWbHLTklgsgRICU3cPfb0vy+oZCC33M43u6R1HSCA==", "dev": true, "hasInstallScript": true, "license": "MIT", "bin": { "tree-sitter": "cli.js" } }, "node_modules/tree-sitter/node_modules/node-addon-api": { "version": "8.3.1", "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-8.3.1.tgz", "integrity": "sha512-lytcDEdxKjGJPTLEfW4mYMigRezMlyJY8W4wxJK8zE533Jlb8L8dRuObJFWg2P+AuOIxoCgKF+2Oq4d4Zd0OUA==", "license": "MIT", "engines": { "node": "^18 || ^20 || >= 21" } }, "node_modules/util-deprecate": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==", "dev": true, "license": "MIT" }, "node_modules/wrappy": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==", "dev": true, "license": "ISC" } } } tree-sitter-ini-1.4.0/package.json000066400000000000000000000020301510712772500170300ustar00rootroot00000000000000{ "name": "tree-sitter-ini", "version": "1.4.0", "description": "INI grammar for tree-sitter", "main": "bindings/node", "types": "bindings/node", "scripts": { "install": "node-gyp-build", "prestart": "tree-sitter build --wasm", "start": "tree-sitter playground", "test": "node --test bindings/node/*_test.js" }, "keywords": [ "tree-sitter", "parser", "ini" ], "files": [ "grammar.js", "binding.gyp", "bindings/node/*", "queries/**", "src/**" ], "author": "Justin M. Keyes", "license": "Apache-2.0", "dependencies": { "node-addon-api": "^7.1.0", "node-gyp-build": "^4.8.0" }, "peerDependencies": { "tree-sitter": "^0.21.0" }, "peerDependenciesMeta": { "tree_sitter": { "optional": true } }, "devDependencies": { "prebuildify": "^6.0.0", "tree-sitter-cli": "^0.20.8" }, "tree-sitter": [ { "scope": "source.ini", "highlights": "queries/highlights.scm", "file-types": [ "ini" ] } ] } tree-sitter-ini-1.4.0/pyproject.toml000066400000000000000000000013341510712772500174640ustar00rootroot00000000000000[build-system] requires = ["setuptools>=42", "wheel"] build-backend = "setuptools.build_meta" [project] name = "tree-sitter-ini" description = "Ini grammar for tree-sitter" version = "1.4.0" keywords = ["incremental", "parsing", "tree-sitter", "ini"] classifiers = [ "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Topic :: Software Development :: Compilers", "Topic :: Text Processing :: Linguistic", "Typing :: Typed" ] requires-python = ">=3.8" license.text = "MIT" readme = "README.md" [project.urls] Homepage = "https://github.com/tree-sitter/tree-sitter-ini" [project.optional-dependencies] core = ["tree-sitter~=0.21"] [tool.cibuildwheel] build = "cp38-*" build-frontend = "build" tree-sitter-ini-1.4.0/queries/000077500000000000000000000000001510712772500162245ustar00rootroot00000000000000tree-sitter-ini-1.4.0/queries/folds.scm000066400000000000000000000000201510712772500200270ustar00rootroot00000000000000(section) @fold tree-sitter-ini-1.4.0/queries/highlights.scm000066400000000000000000000003511510712772500210610ustar00rootroot00000000000000(section_name (text) @type) ; consistency with toml (comment) @comment @spell [ "[" "]" ] @punctuation.bracket "=" @operator (setting (setting_name) @property) ; (setting_value) @none ; grammar does not support subtypes tree-sitter-ini-1.4.0/setup.py000066400000000000000000000031661510712772500162670ustar00rootroot00000000000000from 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_ini", "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 = "cp38", "abi3" return python, abi, platform setup( packages=find_packages("bindings/python"), package_dir={"": "bindings/python"}, package_data={ "tree_sitter_ini": ["*.pyi", "py.typed"], "tree_sitter_ini.queries": ["*.scm"], }, ext_package="tree_sitter_ini", ext_modules=[ Extension( name="_binding", sources=[ "bindings/python/tree_sitter_ini/binding.c", "src/parser.c", # NOTE: if your language uses an external scanner, add it here. ], extra_compile_args=[ "-std=c11", ] if system() != "Windows" else [ "/std:c11", "/utf-8", ], define_macros=[ ("Py_LIMITED_API", "0x03080000"), ("PY_SSIZE_T_CLEAN", None) ], include_dirs=["src"], py_limited_api=True, ) ], cmdclass={ "build": Build, "bdist_wheel": BdistWheel }, zip_safe=False ) tree-sitter-ini-1.4.0/src/000077500000000000000000000000001510712772500153365ustar00rootroot00000000000000tree-sitter-ini-1.4.0/src/grammar.json000066400000000000000000000071131510712772500176610ustar00rootroot00000000000000{ "$schema": "https://tree-sitter.github.io/tree-sitter/assets/schemas/grammar.schema.json", "name": "ini", "rules": { "document": { "type": "SEQ", "members": [ { "type": "REPEAT", "content": { "type": "SYMBOL", "name": "_blank" } }, { "type": "CHOICE", "members": [ { "type": "REPEAT", "content": { "type": "SEQ", "members": [ { "type": "SYMBOL", "name": "setting" } ] } }, { "type": "BLANK" } ] }, { "type": "REPEAT", "content": { "type": "SYMBOL", "name": "section" } } ] }, "section": { "type": "PREC_LEFT", "value": 0, "content": { "type": "SEQ", "members": [ { "type": "SYMBOL", "name": "section_name" }, { "type": "REPEAT", "content": { "type": "SEQ", "members": [ { "type": "SYMBOL", "name": "setting" } ] } } ] } }, "section_name": { "type": "SEQ", "members": [ { "type": "STRING", "value": "[" }, { "type": "ALIAS", "content": { "type": "PATTERN", "value": "[^\\[\\]]+" }, "named": true, "value": "text" }, { "type": "STRING", "value": "]" }, { "type": "PATTERN", "value": "\\r?\\n" } ] }, "setting": { "type": "SEQ", "members": [ { "type": "ALIAS", "content": { "type": "PATTERN", "value": "[^;#=\\s\\[]+( *[^;#=\\s\\[])*" }, "named": true, "value": "setting_name" }, { "type": "STRING", "value": "=" }, { "type": "CHOICE", "members": [ { "type": "ALIAS", "content": { "type": "PATTERN", "value": ".+" }, "named": true, "value": "setting_value" }, { "type": "BLANK" } ] }, { "type": "PATTERN", "value": "\\r?\\n" } ] }, "comment": { "type": "SEQ", "members": [ { "type": "PATTERN", "value": "[;#]" }, { "type": "ALIAS", "content": { "type": "PATTERN", "value": "[^\\r\\n]*" }, "named": true, "value": "text" }, { "type": "PATTERN", "value": "\\r?\\n" } ] }, "_blank": { "type": "FIELD", "name": "blank", "content": { "type": "PATTERN", "value": "\\r?\\n" } } }, "extras": [ { "type": "SYMBOL", "name": "comment" }, { "type": "SYMBOL", "name": "_blank" }, { "type": "PATTERN", "value": "[\\t ]" } ], "conflicts": [], "precedences": [], "externals": [], "inline": [], "supertypes": [], "reserved": {} }tree-sitter-ini-1.4.0/src/node-types.json000066400000000000000000000033251510712772500203230ustar00rootroot00000000000000[ { "type": "comment", "named": true, "fields": {}, "children": { "multiple": false, "required": true, "types": [ { "type": "text", "named": true } ] } }, { "type": "document", "named": true, "root": true, "fields": {}, "children": { "multiple": true, "required": false, "types": [ { "type": "section", "named": true }, { "type": "setting", "named": true } ] } }, { "type": "section", "named": true, "fields": {}, "children": { "multiple": true, "required": true, "types": [ { "type": "section_name", "named": true }, { "type": "setting", "named": true } ] } }, { "type": "section_name", "named": true, "fields": {}, "children": { "multiple": false, "required": true, "types": [ { "type": "text", "named": true } ] } }, { "type": "setting", "named": true, "fields": {}, "children": { "multiple": true, "required": true, "types": [ { "type": "setting_name", "named": true }, { "type": "setting_value", "named": true } ] } }, { "type": "=", "named": false }, { "type": "[", "named": false }, { "type": "]", "named": false }, { "type": "setting_name", "named": true }, { "type": "setting_value", "named": true }, { "type": "text", "named": true } ]tree-sitter-ini-1.4.0/src/parser.c000066400000000000000000000611461510712772500170060ustar00rootroot00000000000000/* Automatically generated by tree-sitter v0.25.3 (2a835ee029dca1c325e6f1c01dbce40396f6123e) */ #include "tree_sitter/parser.h" #if defined(__GNUC__) || defined(__clang__) #pragma GCC diagnostic ignored "-Wmissing-field-initializers" #endif #define LANGUAGE_VERSION 15 #define STATE_COUNT 30 #define LARGE_STATE_COUNT 5 #define SYMBOL_COUNT 19 #define ALIAS_COUNT 0 #define TOKEN_COUNT 10 #define EXTERNAL_TOKEN_COUNT 0 #define FIELD_COUNT 1 #define MAX_ALIAS_SEQUENCE_LENGTH 4 #define MAX_RESERVED_WORD_SET_SIZE 0 #define PRODUCTION_ID_COUNT 2 #define SUPERTYPE_COUNT 0 enum ts_symbol_identifiers { anon_sym_LBRACK = 1, aux_sym_section_name_token1 = 2, anon_sym_RBRACK = 3, aux_sym_section_name_token2 = 4, aux_sym_setting_token1 = 5, anon_sym_EQ = 6, aux_sym_setting_token2 = 7, aux_sym_comment_token1 = 8, aux_sym_comment_token2 = 9, sym_document = 10, sym_section = 11, sym_section_name = 12, sym_setting = 13, sym_comment = 14, sym__blank = 15, aux_sym_document_repeat1 = 16, aux_sym_document_repeat2 = 17, aux_sym_document_repeat3 = 18, }; static const char * const ts_symbol_names[] = { [ts_builtin_sym_end] = "end", [anon_sym_LBRACK] = "[", [aux_sym_section_name_token1] = "text", [anon_sym_RBRACK] = "]", [aux_sym_section_name_token2] = "section_name_token2", [aux_sym_setting_token1] = "setting_name", [anon_sym_EQ] = "=", [aux_sym_setting_token2] = "setting_value", [aux_sym_comment_token1] = "comment_token1", [aux_sym_comment_token2] = "text", [sym_document] = "document", [sym_section] = "section", [sym_section_name] = "section_name", [sym_setting] = "setting", [sym_comment] = "comment", [sym__blank] = "_blank", [aux_sym_document_repeat1] = "document_repeat1", [aux_sym_document_repeat2] = "document_repeat2", [aux_sym_document_repeat3] = "document_repeat3", }; static const TSSymbol ts_symbol_map[] = { [ts_builtin_sym_end] = ts_builtin_sym_end, [anon_sym_LBRACK] = anon_sym_LBRACK, [aux_sym_section_name_token1] = aux_sym_section_name_token1, [anon_sym_RBRACK] = anon_sym_RBRACK, [aux_sym_section_name_token2] = aux_sym_section_name_token2, [aux_sym_setting_token1] = aux_sym_setting_token1, [anon_sym_EQ] = anon_sym_EQ, [aux_sym_setting_token2] = aux_sym_setting_token2, [aux_sym_comment_token1] = aux_sym_comment_token1, [aux_sym_comment_token2] = aux_sym_section_name_token1, [sym_document] = sym_document, [sym_section] = sym_section, [sym_section_name] = sym_section_name, [sym_setting] = sym_setting, [sym_comment] = sym_comment, [sym__blank] = sym__blank, [aux_sym_document_repeat1] = aux_sym_document_repeat1, [aux_sym_document_repeat2] = aux_sym_document_repeat2, [aux_sym_document_repeat3] = aux_sym_document_repeat3, }; static const TSSymbolMetadata ts_symbol_metadata[] = { [ts_builtin_sym_end] = { .visible = false, .named = true, }, [anon_sym_LBRACK] = { .visible = true, .named = false, }, [aux_sym_section_name_token1] = { .visible = true, .named = true, }, [anon_sym_RBRACK] = { .visible = true, .named = false, }, [aux_sym_section_name_token2] = { .visible = false, .named = false, }, [aux_sym_setting_token1] = { .visible = true, .named = true, }, [anon_sym_EQ] = { .visible = true, .named = false, }, [aux_sym_setting_token2] = { .visible = true, .named = true, }, [aux_sym_comment_token1] = { .visible = false, .named = false, }, [aux_sym_comment_token2] = { .visible = true, .named = true, }, [sym_document] = { .visible = true, .named = true, }, [sym_section] = { .visible = true, .named = true, }, [sym_section_name] = { .visible = true, .named = true, }, [sym_setting] = { .visible = true, .named = true, }, [sym_comment] = { .visible = true, .named = true, }, [sym__blank] = { .visible = false, .named = true, }, [aux_sym_document_repeat1] = { .visible = false, .named = false, }, [aux_sym_document_repeat2] = { .visible = false, .named = false, }, [aux_sym_document_repeat3] = { .visible = false, .named = false, }, }; enum ts_field_identifiers { field_blank = 1, }; static const char * const ts_field_names[] = { [0] = NULL, [field_blank] = "blank", }; static const TSMapSlice ts_field_map_slices[PRODUCTION_ID_COUNT] = { [1] = {.index = 0, .length = 1}, }; static const TSFieldMapEntry ts_field_map_entries[] = { [0] = {field_blank, 0}, }; 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] = 17, [29] = 29, }; static bool ts_lex(TSLexer *lexer, TSStateId state) { START_LEXER(); eof = lexer->eof(lexer); switch (state) { case 0: if (eof) ADVANCE(6); if (lookahead == '\n') ADVANCE(12); if (lookahead == '\r') ADVANCE(1); if (lookahead == '=') ADVANCE(14); if (lookahead == '[') ADVANCE(7); if (lookahead == ']') ADVANCE(11); if (lookahead == '\t' || lookahead == ' ') SKIP(0); if (lookahead == '#' || lookahead == ';') ADVANCE(18); END_STATE(); case 1: if (lookahead == '\n') ADVANCE(12); END_STATE(); case 2: if (lookahead == '\n') ADVANCE(12); if (lookahead == '\r') ADVANCE(15); if (lookahead == '\t' || lookahead == ' ') ADVANCE(16); if (lookahead == '#' || lookahead == ';') ADVANCE(17); if (lookahead != 0) ADVANCE(17); END_STATE(); case 3: if (lookahead == '\n') ADVANCE(10); if (lookahead == '\r') ADVANCE(9); if (lookahead == '\t' || lookahead == ' ') ADVANCE(8); if (lookahead == '#' || lookahead == ';') ADVANCE(10); if (lookahead != 0 && lookahead != '[' && lookahead != ']') ADVANCE(10); END_STATE(); case 4: if (lookahead == ' ') ADVANCE(4); if (lookahead != 0 && (lookahead < '\t' || '\r' < lookahead) && lookahead != '#' && lookahead != ';' && lookahead != '=' && lookahead != '[') ADVANCE(13); END_STATE(); case 5: if (eof) ADVANCE(6); if (lookahead == '\n') ADVANCE(12); if (lookahead == '\r') ADVANCE(1); if (lookahead == '[') ADVANCE(7); if (lookahead == '\t' || lookahead == ' ') SKIP(5); if (lookahead == '#' || lookahead == ';') ADVANCE(18); if (lookahead != 0 && (lookahead < '\t' || '\r' < lookahead) && lookahead != '=') ADVANCE(13); END_STATE(); case 6: ACCEPT_TOKEN(ts_builtin_sym_end); END_STATE(); case 7: ACCEPT_TOKEN(anon_sym_LBRACK); END_STATE(); case 8: ACCEPT_TOKEN(aux_sym_section_name_token1); if (lookahead == '\n') ADVANCE(10); if (lookahead == '\r') ADVANCE(9); if (lookahead == '\t' || lookahead == ' ') ADVANCE(8); if (lookahead == '#' || lookahead == ';') ADVANCE(10); if (lookahead != 0 && lookahead != '[' && lookahead != ']') ADVANCE(10); END_STATE(); case 9: ACCEPT_TOKEN(aux_sym_section_name_token1); if (lookahead == '\n') ADVANCE(10); if (lookahead != 0 && lookahead != '[' && lookahead != ']') ADVANCE(10); END_STATE(); case 10: ACCEPT_TOKEN(aux_sym_section_name_token1); if (lookahead != 0 && lookahead != '[' && lookahead != ']') ADVANCE(10); END_STATE(); case 11: ACCEPT_TOKEN(anon_sym_RBRACK); END_STATE(); case 12: ACCEPT_TOKEN(aux_sym_section_name_token2); END_STATE(); case 13: ACCEPT_TOKEN(aux_sym_setting_token1); if (lookahead == ' ') ADVANCE(4); if (lookahead != 0 && (lookahead < '\t' || '\r' < lookahead) && lookahead != '#' && lookahead != ';' && lookahead != '=' && lookahead != '[') ADVANCE(13); END_STATE(); case 14: ACCEPT_TOKEN(anon_sym_EQ); END_STATE(); case 15: ACCEPT_TOKEN(aux_sym_setting_token2); if (lookahead == '\n') ADVANCE(12); if (lookahead != 0) ADVANCE(17); END_STATE(); case 16: ACCEPT_TOKEN(aux_sym_setting_token2); if (lookahead == '\r') ADVANCE(15); if (lookahead == '\t' || lookahead == ' ') ADVANCE(16); if (lookahead == '#' || lookahead == ';') ADVANCE(17); if (lookahead != 0 && lookahead != '\t' && lookahead != '\n') ADVANCE(17); END_STATE(); case 17: ACCEPT_TOKEN(aux_sym_setting_token2); if (lookahead != 0 && lookahead != '\n') ADVANCE(17); END_STATE(); case 18: ACCEPT_TOKEN(aux_sym_comment_token1); END_STATE(); case 19: ACCEPT_TOKEN(aux_sym_comment_token1); if (lookahead != 0 && lookahead != '\n' && lookahead != '\r') ADVANCE(21); END_STATE(); case 20: ACCEPT_TOKEN(aux_sym_comment_token2); if (lookahead == '\t' || lookahead == ' ') ADVANCE(20); if (lookahead == '#' || lookahead == ';') ADVANCE(19); if (lookahead != 0 && lookahead != '\t' && lookahead != '\n' && lookahead != '\r') ADVANCE(21); END_STATE(); case 21: ACCEPT_TOKEN(aux_sym_comment_token2); if (lookahead != 0 && lookahead != '\n' && lookahead != '\r') ADVANCE(21); END_STATE(); default: return false; } } static const TSLexerMode ts_lex_modes[STATE_COUNT] = { [0] = {.lex_state = 0}, [1] = {.lex_state = 5}, [2] = {.lex_state = 5}, [3] = {.lex_state = 5}, [4] = {.lex_state = 5}, [5] = {.lex_state = 5}, [6] = {.lex_state = 0}, [7] = {.lex_state = 0}, [8] = {.lex_state = 5}, [9] = {.lex_state = 0}, [10] = {.lex_state = 5}, [11] = {.lex_state = 0}, [12] = {.lex_state = 5}, [13] = {.lex_state = 5}, [14] = {.lex_state = 5}, [15] = {.lex_state = 5}, [16] = {.lex_state = 5}, [17] = {.lex_state = 5}, [18] = {.lex_state = 0}, [19] = {.lex_state = 3}, [20] = {.lex_state = 0}, [21] = {.lex_state = 0}, [22] = {.lex_state = 20}, [23] = {.lex_state = 0}, [24] = {.lex_state = 2}, [25] = {.lex_state = 0}, [26] = {.lex_state = 0}, [27] = {.lex_state = 0}, [28] = {(TSStateId)(-1),}, [29] = {(TSStateId)(-1),}, }; static const uint16_t ts_parse_table[LARGE_STATE_COUNT][SYMBOL_COUNT] = { [STATE(0)] = { [sym_comment] = STATE(0), [sym__blank] = STATE(0), [ts_builtin_sym_end] = ACTIONS(1), [anon_sym_LBRACK] = ACTIONS(1), [anon_sym_RBRACK] = ACTIONS(1), [aux_sym_section_name_token2] = ACTIONS(3), [anon_sym_EQ] = ACTIONS(1), [aux_sym_comment_token1] = ACTIONS(5), }, [STATE(1)] = { [sym_document] = STATE(20), [sym_section] = STATE(18), [sym_section_name] = STATE(5), [sym_setting] = STATE(13), [sym_comment] = STATE(1), [sym__blank] = STATE(1), [aux_sym_document_repeat1] = STATE(2), [aux_sym_document_repeat2] = STATE(3), [aux_sym_document_repeat3] = STATE(6), [ts_builtin_sym_end] = ACTIONS(7), [anon_sym_LBRACK] = ACTIONS(9), [aux_sym_section_name_token2] = ACTIONS(11), [aux_sym_setting_token1] = ACTIONS(13), [aux_sym_comment_token1] = ACTIONS(5), }, [STATE(2)] = { [sym_section] = STATE(18), [sym_section_name] = STATE(5), [sym_setting] = STATE(13), [sym_comment] = STATE(2), [sym__blank] = STATE(2), [aux_sym_document_repeat1] = STATE(12), [aux_sym_document_repeat2] = STATE(4), [aux_sym_document_repeat3] = STATE(7), [ts_builtin_sym_end] = ACTIONS(15), [anon_sym_LBRACK] = ACTIONS(9), [aux_sym_section_name_token2] = ACTIONS(11), [aux_sym_setting_token1] = ACTIONS(13), [aux_sym_comment_token1] = ACTIONS(5), }, [STATE(3)] = { [sym_section] = STATE(18), [sym_section_name] = STATE(5), [sym_setting] = STATE(13), [sym_comment] = STATE(3), [sym__blank] = STATE(3), [aux_sym_document_repeat2] = STATE(10), [aux_sym_document_repeat3] = STATE(7), [ts_builtin_sym_end] = ACTIONS(15), [anon_sym_LBRACK] = ACTIONS(9), [aux_sym_section_name_token2] = ACTIONS(3), [aux_sym_setting_token1] = ACTIONS(13), [aux_sym_comment_token1] = ACTIONS(5), }, [STATE(4)] = { [sym_section] = STATE(18), [sym_section_name] = STATE(5), [sym_setting] = STATE(13), [sym_comment] = STATE(4), [sym__blank] = STATE(4), [aux_sym_document_repeat2] = STATE(10), [aux_sym_document_repeat3] = STATE(11), [ts_builtin_sym_end] = ACTIONS(17), [anon_sym_LBRACK] = ACTIONS(9), [aux_sym_section_name_token2] = ACTIONS(3), [aux_sym_setting_token1] = ACTIONS(13), [aux_sym_comment_token1] = ACTIONS(5), }, }; static const uint16_t ts_small_parse_table[] = { [0] = 7, ACTIONS(3), 1, aux_sym_section_name_token2, ACTIONS(5), 1, aux_sym_comment_token1, ACTIONS(13), 1, aux_sym_setting_token1, STATE(8), 1, aux_sym_document_repeat2, STATE(13), 1, sym_setting, ACTIONS(19), 2, ts_builtin_sym_end, anon_sym_LBRACK, STATE(5), 2, sym_comment, sym__blank, [24] = 8, ACTIONS(3), 1, aux_sym_section_name_token2, ACTIONS(5), 1, aux_sym_comment_token1, ACTIONS(9), 1, anon_sym_LBRACK, ACTIONS(15), 1, ts_builtin_sym_end, STATE(5), 1, sym_section_name, STATE(9), 1, aux_sym_document_repeat3, STATE(18), 1, sym_section, STATE(6), 2, sym_comment, sym__blank, [50] = 8, ACTIONS(3), 1, aux_sym_section_name_token2, ACTIONS(5), 1, aux_sym_comment_token1, ACTIONS(9), 1, anon_sym_LBRACK, ACTIONS(17), 1, ts_builtin_sym_end, STATE(5), 1, sym_section_name, STATE(9), 1, aux_sym_document_repeat3, STATE(18), 1, sym_section, STATE(7), 2, sym_comment, sym__blank, [76] = 7, ACTIONS(3), 1, aux_sym_section_name_token2, ACTIONS(5), 1, aux_sym_comment_token1, ACTIONS(13), 1, aux_sym_setting_token1, STATE(10), 1, aux_sym_document_repeat2, STATE(13), 1, sym_setting, ACTIONS(21), 2, ts_builtin_sym_end, anon_sym_LBRACK, STATE(8), 2, sym_comment, sym__blank, [100] = 7, ACTIONS(3), 1, aux_sym_section_name_token2, ACTIONS(5), 1, aux_sym_comment_token1, ACTIONS(23), 1, ts_builtin_sym_end, ACTIONS(25), 1, anon_sym_LBRACK, STATE(5), 1, sym_section_name, STATE(18), 1, sym_section, STATE(9), 3, sym_comment, sym__blank, aux_sym_document_repeat3, [124] = 6, ACTIONS(3), 1, aux_sym_section_name_token2, ACTIONS(5), 1, aux_sym_comment_token1, ACTIONS(30), 1, aux_sym_setting_token1, STATE(13), 1, sym_setting, ACTIONS(28), 2, ts_builtin_sym_end, anon_sym_LBRACK, STATE(10), 3, sym_comment, sym__blank, aux_sym_document_repeat2, [146] = 8, ACTIONS(3), 1, aux_sym_section_name_token2, ACTIONS(5), 1, aux_sym_comment_token1, ACTIONS(9), 1, anon_sym_LBRACK, ACTIONS(33), 1, ts_builtin_sym_end, STATE(5), 1, sym_section_name, STATE(9), 1, aux_sym_document_repeat3, STATE(18), 1, sym_section, STATE(11), 2, sym_comment, sym__blank, [172] = 4, ACTIONS(5), 1, aux_sym_comment_token1, ACTIONS(37), 1, aux_sym_section_name_token2, ACTIONS(35), 3, ts_builtin_sym_end, anon_sym_LBRACK, aux_sym_setting_token1, STATE(12), 3, sym_comment, sym__blank, aux_sym_document_repeat1, [189] = 4, ACTIONS(3), 1, aux_sym_section_name_token2, ACTIONS(5), 1, aux_sym_comment_token1, STATE(13), 2, sym_comment, sym__blank, ACTIONS(40), 3, ts_builtin_sym_end, anon_sym_LBRACK, aux_sym_setting_token1, [205] = 4, ACTIONS(3), 1, aux_sym_section_name_token2, ACTIONS(5), 1, aux_sym_comment_token1, STATE(14), 2, sym_comment, sym__blank, ACTIONS(42), 3, ts_builtin_sym_end, anon_sym_LBRACK, aux_sym_setting_token1, [221] = 4, ACTIONS(3), 1, aux_sym_section_name_token2, ACTIONS(5), 1, aux_sym_comment_token1, STATE(15), 2, sym_comment, sym__blank, ACTIONS(44), 3, ts_builtin_sym_end, anon_sym_LBRACK, aux_sym_setting_token1, [237] = 4, ACTIONS(3), 1, aux_sym_section_name_token2, ACTIONS(5), 1, aux_sym_comment_token1, STATE(16), 2, sym_comment, sym__blank, ACTIONS(46), 3, ts_builtin_sym_end, anon_sym_LBRACK, aux_sym_setting_token1, [253] = 3, ACTIONS(5), 1, aux_sym_comment_token1, STATE(17), 2, sym_comment, sym__blank, ACTIONS(48), 4, ts_builtin_sym_end, anon_sym_LBRACK, aux_sym_section_name_token2, aux_sym_setting_token1, [267] = 4, ACTIONS(3), 1, aux_sym_section_name_token2, ACTIONS(5), 1, aux_sym_comment_token1, ACTIONS(50), 2, ts_builtin_sym_end, anon_sym_LBRACK, STATE(18), 2, sym_comment, sym__blank, [282] = 4, ACTIONS(52), 1, aux_sym_section_name_token1, ACTIONS(54), 1, aux_sym_section_name_token2, ACTIONS(56), 1, aux_sym_comment_token1, STATE(19), 2, sym_comment, sym__blank, [296] = 4, ACTIONS(3), 1, aux_sym_section_name_token2, ACTIONS(5), 1, aux_sym_comment_token1, ACTIONS(58), 1, ts_builtin_sym_end, STATE(20), 2, sym_comment, sym__blank, [310] = 4, ACTIONS(3), 1, aux_sym_section_name_token2, ACTIONS(5), 1, aux_sym_comment_token1, ACTIONS(60), 1, anon_sym_EQ, STATE(21), 2, sym_comment, sym__blank, [324] = 4, ACTIONS(54), 1, aux_sym_section_name_token2, ACTIONS(56), 1, aux_sym_comment_token1, ACTIONS(62), 1, aux_sym_comment_token2, STATE(22), 2, sym_comment, sym__blank, [338] = 4, ACTIONS(3), 1, aux_sym_section_name_token2, ACTIONS(5), 1, aux_sym_comment_token1, ACTIONS(64), 1, anon_sym_RBRACK, STATE(23), 2, sym_comment, sym__blank, [352] = 4, ACTIONS(56), 1, aux_sym_comment_token1, ACTIONS(66), 1, aux_sym_section_name_token2, ACTIONS(68), 1, aux_sym_setting_token2, STATE(24), 2, sym_comment, sym__blank, [366] = 3, ACTIONS(5), 1, aux_sym_comment_token1, ACTIONS(70), 1, aux_sym_section_name_token2, STATE(25), 2, sym_comment, sym__blank, [377] = 3, ACTIONS(5), 1, aux_sym_comment_token1, ACTIONS(72), 1, aux_sym_section_name_token2, STATE(26), 2, sym_comment, sym__blank, [388] = 3, ACTIONS(5), 1, aux_sym_comment_token1, ACTIONS(74), 1, aux_sym_section_name_token2, STATE(27), 2, sym_comment, sym__blank, [399] = 1, ACTIONS(48), 1, ts_builtin_sym_end, [403] = 1, ACTIONS(76), 1, ts_builtin_sym_end, }; static const uint32_t ts_small_parse_table_map[] = { [SMALL_STATE(5)] = 0, [SMALL_STATE(6)] = 24, [SMALL_STATE(7)] = 50, [SMALL_STATE(8)] = 76, [SMALL_STATE(9)] = 100, [SMALL_STATE(10)] = 124, [SMALL_STATE(11)] = 146, [SMALL_STATE(12)] = 172, [SMALL_STATE(13)] = 189, [SMALL_STATE(14)] = 205, [SMALL_STATE(15)] = 221, [SMALL_STATE(16)] = 237, [SMALL_STATE(17)] = 253, [SMALL_STATE(18)] = 267, [SMALL_STATE(19)] = 282, [SMALL_STATE(20)] = 296, [SMALL_STATE(21)] = 310, [SMALL_STATE(22)] = 324, [SMALL_STATE(23)] = 338, [SMALL_STATE(24)] = 352, [SMALL_STATE(25)] = 366, [SMALL_STATE(26)] = 377, [SMALL_STATE(27)] = 388, [SMALL_STATE(28)] = 399, [SMALL_STATE(29)] = 403, }; static const TSParseActionEntry ts_parse_actions[] = { [0] = {.entry = {.count = 0, .reusable = false}}, [1] = {.entry = {.count = 1, .reusable = false}}, RECOVER(), [3] = {.entry = {.count = 1, .reusable = true}}, SHIFT(28), [5] = {.entry = {.count = 1, .reusable = true}}, SHIFT(22), [7] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_document, 0, 0, 0), [9] = {.entry = {.count = 1, .reusable = true}}, SHIFT(19), [11] = {.entry = {.count = 1, .reusable = true}}, SHIFT(17), [13] = {.entry = {.count = 1, .reusable = true}}, SHIFT(21), [15] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_document, 1, 0, 0), [17] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_document, 2, 0, 0), [19] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_section, 1, 0, 0), [21] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_section, 2, 0, 0), [23] = {.entry = {.count = 1, .reusable = true}}, REDUCE(aux_sym_document_repeat3, 2, 0, 0), [25] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym_document_repeat3, 2, 0, 0), SHIFT_REPEAT(19), [28] = {.entry = {.count = 1, .reusable = true}}, REDUCE(aux_sym_document_repeat2, 2, 0, 0), [30] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym_document_repeat2, 2, 0, 0), SHIFT_REPEAT(21), [33] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_document, 3, 0, 0), [35] = {.entry = {.count = 1, .reusable = true}}, REDUCE(aux_sym_document_repeat1, 2, 0, 0), [37] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym_document_repeat1, 2, 0, 0), SHIFT_REPEAT(17), [40] = {.entry = {.count = 1, .reusable = true}}, REDUCE(aux_sym_document_repeat2, 1, 0, 0), [42] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_section_name, 4, 0, 0), [44] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_setting, 3, 0, 0), [46] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_setting, 4, 0, 0), [48] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym__blank, 1, 0, 1), [50] = {.entry = {.count = 1, .reusable = true}}, REDUCE(aux_sym_document_repeat3, 1, 0, 0), [52] = {.entry = {.count = 1, .reusable = true}}, SHIFT(23), [54] = {.entry = {.count = 1, .reusable = false}}, SHIFT(28), [56] = {.entry = {.count = 1, .reusable = false}}, SHIFT(22), [58] = {.entry = {.count = 1, .reusable = true}}, ACCEPT_INPUT(), [60] = {.entry = {.count = 1, .reusable = true}}, SHIFT(24), [62] = {.entry = {.count = 1, .reusable = false}}, SHIFT(25), [64] = {.entry = {.count = 1, .reusable = true}}, SHIFT(27), [66] = {.entry = {.count = 1, .reusable = false}}, SHIFT(15), [68] = {.entry = {.count = 1, .reusable = false}}, SHIFT(26), [70] = {.entry = {.count = 1, .reusable = true}}, SHIFT(29), [72] = {.entry = {.count = 1, .reusable = true}}, SHIFT(16), [74] = {.entry = {.count = 1, .reusable = true}}, SHIFT(14), [76] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_comment, 3, 0, 0), }; #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_ini(void) { static const TSLanguage language = { .abi_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, .supertype_count = SUPERTYPE_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 = (const void*)ts_lex_modes, .lex_fn = ts_lex, .primary_state_ids = ts_primary_state_ids, .name = "ini", .max_reserved_word_set_size = 0, .metadata = { .major_version = 1, .minor_version = 3, .patch_version = 0, }, }; return &language; } #ifdef __cplusplus } #endif tree-sitter-ini-1.4.0/src/tree_sitter/000077500000000000000000000000001510712772500176675ustar00rootroot00000000000000tree-sitter-ini-1.4.0/src/tree_sitter/alloc.h000066400000000000000000000017311510712772500211340ustar00rootroot00000000000000#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 size); extern void *(*ts_current_calloc)(size_t count, size_t size); extern void *(*ts_current_realloc)(void *ptr, size_t size); extern void (*ts_current_free)(void *ptr); #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_ tree-sitter-ini-1.4.0/src/tree_sitter/array.h000066400000000000000000000242771510712772500211720ustar00rootroot00000000000000#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(push) #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(pop) #elif defined(__GNUC__) || defined(__clang__) #pragma GCC diagnostic pop #endif #ifdef __cplusplus } #endif #endif // TREE_SITTER_ARRAY_H_ tree-sitter-ini-1.4.0/src/tree_sitter/parser.h000066400000000000000000000167761510712772500213550ustar00rootroot00000000000000#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; typedef struct TSLanguageMetadata TSLanguageMetadata; typedef struct TSLanguageMetadata { uint8_t major_version; uint8_t minor_version; uint8_t patch_version; } TSLanguageMetadata; #endif typedef struct { TSFieldId field_id; uint8_t child_index; bool inherited; } TSFieldMapEntry; // Used to index the field and supertype maps. typedef struct { uint16_t index; uint16_t length; } TSMapSlice; 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 struct { uint16_t lex_state; uint16_t external_lex_state; uint16_t reserved_word_set_id; } TSLexerMode; 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 abi_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 TSMapSlice *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 TSLexerMode *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; const char *name; const TSSymbol *reserved_words; uint16_t max_reserved_word_set_size; uint32_t supertype_count; const TSSymbol *supertype_symbols; const TSMapSlice *supertype_map_slices; const TSSymbol *supertype_map_entries; TSLanguageMetadata metadata; }; static inline bool set_contains(const 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; const 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; } const 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_ tree-sitter-ini-1.4.0/test-awsconfig000066400000000000000000000004131510712772500174250ustar00rootroot00000000000000 [default] region = us-west-2 output = json [profile dev-user] region = us-east-1 output = text [profile developers] role_arn = arn:aws:iam::123456789012:role/developers # foo source_profile = dev-user region = us-west-2 output = json # foo tree-sitter-ini-1.4.0/test/000077500000000000000000000000001510712772500155265ustar00rootroot00000000000000tree-sitter-ini-1.4.0/test/corpus/000077500000000000000000000000001510712772500170415ustar00rootroot00000000000000tree-sitter-ini-1.4.0/test/corpus/main.txt000066400000000000000000000165461510712772500205420ustar00rootroot00000000000000================================================================================ one section ================================================================================ [a section title] foo = bar -------------------------------------------------------------------------------- (document (section (section_name (text)) (setting (setting_name) (setting_value)))) ================================================================================ setting value may be null/empty #9 ================================================================================ [section 1] setting 1 = setting 2 = x setting 3 = # comment setting 4 = y setting-5 = [section 2] -------------------------------------------------------------------------------- (document (section (section_name (text)) (setting (setting_name)) (setting (setting_name) (setting_value)) (setting (setting_name)) (comment (text)) (setting (setting_name) (setting_value)) (setting (setting_name))) (section (section_name (text)))) ================================================================================ weird key names ================================================================================ # key with whitespace https://github.com/justinmk/tree-sitter-ini/issues/11 [fruit.Date] taste = novel Trademark Issues="truly unlikely" ignore all white space = my value x = v -------------------------------------------------------------------------------- (document (comment (text)) (section (section_name (text)) (setting (setting_name) (setting_value)) (setting (setting_name) (setting_value)) (setting (setting_name) (setting_value)) (setting (setting_name) (setting_value)))) ================================================================================ many sections, some empty ================================================================================ # comment ... [a section title] foo = bar [section 2] foo = bar [section 3, which is empty] [section4] 2f_a3-x = not! an equals sign... foo = bar # Interesting note about duplicates in tree-sitter: # https://github.com/tree-sitter/tree-sitter/issues/130 # foo --foo-- = bar ``foo`` = bar # a straggler comment... # another -------------------------------------------------------------------------------- (document (comment (text)) (section (section_name (text)) (setting (setting_name) (setting_value))) (section (section_name (text)) (setting (setting_name) (setting_value))) (section (section_name (text))) (section (section_name (text)) (setting (setting_name) (setting_value)) (setting (setting_name) (setting_value)) (comment (text)) (comment (text)) (comment (text)) (setting (setting_name) (setting_value)) (setting (setting_name) (setting_value))) (comment (text)) (comment (text))) ================================================================================ only comments ================================================================================ # ; # -------------------------------------------------------------------------------- (document (comment (text)) (comment (text)) (comment (text))) ================================================================================ mixed comments #5 ================================================================================ ; # 1 ; comment1 [section1] ; comment2 # comment3 key1=val1 # comment1 [section2] # comment2 ; comment3 key1=val1 -------------------------------------------------------------------------------- (document (comment (text)) (comment (text)) (comment (text)) (section (section_name (text)) (comment (text)) (comment (text)) (setting (setting_name) (setting_value))) (comment (text)) (section (section_name (text)) (comment (text)) (comment (text)) (setting (setting_name) (setting_value)))) ================================================================================ one section (empty) ================================================================================ [section with no content] -------------------------------------------------------------------------------- (document (section (section_name (text)))) ================================================================================ NOT a comment ================================================================================ [foo] bar = baz # not-a-comment zim = -1>3 ; not-a-comment -------------------------------------------------------------------------------- (document (section (section_name (text)) (setting (setting_name) (setting_value)) (setting (setting_name) (setting_value)))) ================================================================================ invalid section ================================================================================ [not a section] a = b # not-a-comment -------------------------------------------------------------------------------- (document (ERROR (text) (UNEXPECTED 'a') (UNEXPECTED 'b')) (comment (text))) ================================================================================ ~/.aws/config ================================================================================ # AWS config doc: # https://docs.aws.amazon.com/credref/latest/refdocs/file-format.html [default] region = us-west-2 output = json [profile dev-user] # foo region = us-east-1 output = text [profile developers] role_arn = arn:aws:iam::123456789012:role/developers # foo # foo source_profile = dev-user region = us-west-2 output = json # foo -------------------------------------------------------------------------------- (document (comment (text)) (comment (text)) (section (section_name (text)) (setting (setting_name) (setting_value)) (setting (setting_name) (setting_value))) (section (section_name (text)) (comment (text)) (setting (setting_name) (setting_value)) (setting (setting_name) (setting_value))) (section (section_name (text)) (setting (setting_name) (setting_value)) (comment (text)) (comment (text)) (setting (setting_name) (setting_value)) (setting (setting_name) (setting_value)) (setting (setting_name) (setting_value))) (comment (text))) ================================================================================ global-parameters ================================================================================ # leading comment a=b # another comment [section] c=d -------------------------------------------------------------------------------- (document (comment (text)) (setting (setting_name) (setting_value)) (comment (text)) (section (section_name (text)) (setting (setting_name) (setting_value)))) tree-sitter-ini-1.4.0/tree-sitter.json000066400000000000000000000015141510712772500177120ustar00rootroot00000000000000{ "$schema": "https://tree-sitter.github.io/tree-sitter/assets/schemas/config.schema.json", "grammars": [ { "name": "ini", "camelcase": "Ini", "title": "Ini", "scope": "source.ini", "file-types": [ "ini" ], "injection-regex": "^ini$", "class-name": "TreeSitterIni" } ], "metadata": { "version": "1.4.0", "license": "Apache-2.0", "description": "Ini grammar for tree-sitter", "authors": [ { "name": "Justin M. Keyes", "email": "justinkz@gmail.com", "url": "https://sink.io/" } ], "links": { "repository": "https://github.com/justinmk/tree-sitter-ini" } }, "bindings": { "c": true, "go": true, "node": true, "python": true, "rust": true, "swift": true, "zig": false } }