tree-sitter implementation for the confindent configuration language

tree-sitter init

+950
+46
.editorconfig
··· 1 + root = true 2 + 3 + [*] 4 + charset = utf-8 5 + 6 + [*.{json,toml,yml,gyp}] 7 + indent_style = space 8 + indent_size = 2 9 + 10 + [*.js] 11 + indent_style = space 12 + indent_size = 2 13 + 14 + [*.scm] 15 + indent_style = space 16 + indent_size = 2 17 + 18 + [*.{c,cc,h}] 19 + indent_style = space 20 + indent_size = 4 21 + 22 + [*.rs] 23 + indent_style = space 24 + indent_size = 4 25 + 26 + [*.{py,pyi}] 27 + indent_style = space 28 + indent_size = 4 29 + 30 + [*.swift] 31 + indent_style = space 32 + indent_size = 4 33 + 34 + [*.go] 35 + indent_style = tab 36 + indent_size = 8 37 + 38 + [Makefile] 39 + indent_style = tab 40 + indent_size = 8 41 + 42 + [parser.c] 43 + indent_size = 2 44 + 45 + [{alloc,array,parser}.h] 46 + indent_size = 2
+41
.gitattributes
··· 1 + * text=auto eol=lf 2 + 3 + # Generated source files 4 + src/*.json linguist-generated 5 + src/parser.c linguist-generated 6 + src/tree_sitter/* linguist-generated 7 + 8 + # C bindings 9 + bindings/c/** linguist-generated 10 + CMakeLists.txt linguist-generated 11 + Makefile linguist-generated 12 + 13 + # Rust bindings 14 + bindings/rust/* linguist-generated 15 + Cargo.toml linguist-generated 16 + Cargo.lock linguist-generated 17 + 18 + # Node.js bindings 19 + bindings/node/* linguist-generated 20 + binding.gyp linguist-generated 21 + package.json linguist-generated 22 + package-lock.json linguist-generated 23 + 24 + # Python bindings 25 + bindings/python/** linguist-generated 26 + setup.py linguist-generated 27 + pyproject.toml linguist-generated 28 + 29 + # Go bindings 30 + bindings/go/* linguist-generated 31 + go.mod linguist-generated 32 + go.sum linguist-generated 33 + 34 + # Swift bindings 35 + bindings/swift/** linguist-generated 36 + Package.swift linguist-generated 37 + Package.resolved linguist-generated 38 + 39 + # Zig bindings 40 + build.zig linguist-generated 41 + build.zig.zon linguist-generated
+47
.gitignore
··· 1 + # Rust artifacts 2 + target/ 3 + 4 + # Node artifacts 5 + build/ 6 + prebuilds/ 7 + node_modules/ 8 + 9 + # Swift artifacts 10 + .build/ 11 + 12 + # Go artifacts 13 + _obj/ 14 + 15 + # Python artifacts 16 + .venv/ 17 + dist/ 18 + *.egg-info 19 + *.whl 20 + 21 + # C artifacts 22 + *.a 23 + *.so 24 + *.so.* 25 + *.dylib 26 + *.dll 27 + *.pc 28 + *.exp 29 + *.lib 30 + 31 + # Zig artifacts 32 + .zig-cache/ 33 + zig-cache/ 34 + zig-out/ 35 + 36 + # Example dirs 37 + /examples/*/ 38 + 39 + # Grammar volatiles 40 + *.wasm 41 + *.obj 42 + *.o 43 + 44 + # Archives 45 + *.tar.gz 46 + *.tgz 47 + *.zip
+66
CMakeLists.txt
··· 1 + cmake_minimum_required(VERSION 3.13) 2 + 3 + project(tree-sitter-confindent 4 + VERSION "0.1.0" 5 + DESCRIPTION "tree-sitter implementation for the Confindent configuration language" 6 + HOMEPAGE_URL "https://tangled.org/@nove.dev/tree-sitter-confindent" 7 + LANGUAGES C) 8 + 9 + option(BUILD_SHARED_LIBS "Build using shared libraries" ON) 10 + option(TREE_SITTER_REUSE_ALLOCATOR "Reuse the library allocator" OFF) 11 + 12 + set(TREE_SITTER_ABI_VERSION 15 CACHE STRING "Tree-sitter ABI version") 13 + if(NOT ${TREE_SITTER_ABI_VERSION} MATCHES "^[0-9]+$") 14 + unset(TREE_SITTER_ABI_VERSION CACHE) 15 + message(FATAL_ERROR "TREE_SITTER_ABI_VERSION must be an integer") 16 + endif() 17 + 18 + find_program(TREE_SITTER_CLI tree-sitter DOC "Tree-sitter CLI") 19 + 20 + add_custom_command(OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/src/parser.c" 21 + DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/grammar.json" 22 + COMMAND "${TREE_SITTER_CLI}" generate src/grammar.json 23 + --abi=${TREE_SITTER_ABI_VERSION} 24 + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" 25 + COMMENT "Generating parser.c") 26 + 27 + add_library(tree-sitter-confindent src/parser.c) 28 + if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/src/scanner.c) 29 + target_sources(tree-sitter-confindent PRIVATE src/scanner.c) 30 + endif() 31 + target_include_directories(tree-sitter-confindent 32 + PRIVATE src 33 + INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/bindings/c> 34 + $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>) 35 + 36 + target_compile_definitions(tree-sitter-confindent PRIVATE 37 + $<$<BOOL:${TREE_SITTER_REUSE_ALLOCATOR}>:TREE_SITTER_REUSE_ALLOCATOR> 38 + $<$<CONFIG:Debug>:TREE_SITTER_DEBUG>) 39 + 40 + set_target_properties(tree-sitter-confindent 41 + PROPERTIES 42 + C_STANDARD 11 43 + POSITION_INDEPENDENT_CODE ON 44 + SOVERSION "${TREE_SITTER_ABI_VERSION}.${PROJECT_VERSION_MAJOR}" 45 + DEFINE_SYMBOL "") 46 + 47 + configure_file(bindings/c/tree-sitter-confindent.pc.in 48 + "${CMAKE_CURRENT_BINARY_DIR}/tree-sitter-confindent.pc" @ONLY) 49 + 50 + include(GNUInstallDirs) 51 + 52 + install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bindings/c/tree_sitter" 53 + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" 54 + FILES_MATCHING PATTERN "*.h") 55 + install(FILES "${CMAKE_CURRENT_BINARY_DIR}/tree-sitter-confindent.pc" 56 + DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig") 57 + install(TARGETS tree-sitter-confindent 58 + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") 59 + 60 + file(GLOB QUERIES queries/*.scm) 61 + install(FILES ${QUERIES} 62 + DESTINATION "${CMAKE_INSTALL_DATADIR}/tree-sitter/queries/confindent") 63 + 64 + add_custom_target(ts-test "${TREE_SITTER_CLI}" test 65 + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" 66 + COMMENT "tree-sitter test")
+34
Cargo.toml
··· 1 + [package] 2 + name = "tree-sitter-confindent" 3 + description = "tree-sitter implementation for the Confindent configuration language" 4 + version = "0.1.0" 5 + authors = ["Devon Sawatsky <devon@nove.dev>"] 6 + license = "ISC" 7 + readme = "README.md" 8 + keywords = ["incremental", "parsing", "tree-sitter", "confindent"] 9 + categories = ["parser-implementations", "parsing", "text-editors"] 10 + repository = "https://tangled.org/@nove.dev/tree-sitter-confindent" 11 + edition = "2021" 12 + autoexamples = false 13 + 14 + build = "bindings/rust/build.rs" 15 + include = [ 16 + "bindings/rust/*", 17 + "grammar.js", 18 + "queries/*", 19 + "src/*", 20 + "tree-sitter.json", 21 + "LICENSE", 22 + ] 23 + 24 + [lib] 25 + path = "bindings/rust/lib.rs" 26 + 27 + [dependencies] 28 + tree-sitter-language = "0.1" 29 + 30 + [build-dependencies] 31 + cc = "1.2" 32 + 33 + [dev-dependencies] 34 + tree-sitter = "0.25.3"
+97
Makefile
··· 1 + ifeq ($(OS),Windows_NT) 2 + $(error Windows is not supported) 3 + endif 4 + 5 + LANGUAGE_NAME := tree-sitter-confindent 6 + HOMEPAGE_URL := https://tangled.org/@nove.dev/tree-sitter-confindent 7 + VERSION := 0.1.0 8 + 9 + # repository 10 + SRC_DIR := src 11 + 12 + TS ?= tree-sitter 13 + 14 + # install directory layout 15 + PREFIX ?= /usr/local 16 + DATADIR ?= $(PREFIX)/share 17 + INCLUDEDIR ?= $(PREFIX)/include 18 + LIBDIR ?= $(PREFIX)/lib 19 + PCLIBDIR ?= $(LIBDIR)/pkgconfig 20 + 21 + # source/object files 22 + PARSER := $(SRC_DIR)/parser.c 23 + EXTRAS := $(filter-out $(PARSER),$(wildcard $(SRC_DIR)/*.c)) 24 + OBJS := $(patsubst %.c,%.o,$(PARSER) $(EXTRAS)) 25 + 26 + # flags 27 + ARFLAGS ?= rcs 28 + override CFLAGS += -I$(SRC_DIR) -std=c11 -fPIC 29 + 30 + # ABI versioning 31 + SONAME_MAJOR = $(shell sed -n 's/\#define LANGUAGE_VERSION //p' $(PARSER)) 32 + SONAME_MINOR = $(word 1,$(subst ., ,$(VERSION))) 33 + 34 + # OS-specific bits 35 + ifeq ($(shell uname),Darwin) 36 + SOEXT = dylib 37 + SOEXTVER_MAJOR = $(SONAME_MAJOR).$(SOEXT) 38 + SOEXTVER = $(SONAME_MAJOR).$(SONAME_MINOR).$(SOEXT) 39 + LINKSHARED = -dynamiclib -Wl,-install_name,$(LIBDIR)/lib$(LANGUAGE_NAME).$(SOEXTVER),-rpath,@executable_path/../Frameworks 40 + else 41 + SOEXT = so 42 + SOEXTVER_MAJOR = $(SOEXT).$(SONAME_MAJOR) 43 + SOEXTVER = $(SOEXT).$(SONAME_MAJOR).$(SONAME_MINOR) 44 + LINKSHARED = -shared -Wl,-soname,lib$(LANGUAGE_NAME).$(SOEXTVER) 45 + endif 46 + ifneq ($(filter $(shell uname),FreeBSD NetBSD DragonFly),) 47 + PCLIBDIR := $(PREFIX)/libdata/pkgconfig 48 + endif 49 + 50 + all: lib$(LANGUAGE_NAME).a lib$(LANGUAGE_NAME).$(SOEXT) $(LANGUAGE_NAME).pc 51 + 52 + lib$(LANGUAGE_NAME).a: $(OBJS) 53 + $(AR) $(ARFLAGS) $@ $^ 54 + 55 + lib$(LANGUAGE_NAME).$(SOEXT): $(OBJS) 56 + $(CC) $(LDFLAGS) $(LINKSHARED) $^ $(LDLIBS) -o $@ 57 + ifneq ($(STRIP),) 58 + $(STRIP) $@ 59 + endif 60 + 61 + $(LANGUAGE_NAME).pc: bindings/c/$(LANGUAGE_NAME).pc.in 62 + sed -e 's|@PROJECT_VERSION@|$(VERSION)|' \ 63 + -e 's|@CMAKE_INSTALL_LIBDIR@|$(LIBDIR:$(PREFIX)/%=%)|' \ 64 + -e 's|@CMAKE_INSTALL_INCLUDEDIR@|$(INCLUDEDIR:$(PREFIX)/%=%)|' \ 65 + -e 's|@PROJECT_DESCRIPTION@|$(DESCRIPTION)|' \ 66 + -e 's|@PROJECT_HOMEPAGE_URL@|$(HOMEPAGE_URL)|' \ 67 + -e 's|@CMAKE_INSTALL_PREFIX@|$(PREFIX)|' $< > $@ 68 + 69 + $(PARSER): $(SRC_DIR)/grammar.json 70 + $(TS) generate $^ 71 + 72 + install: all 73 + install -d '$(DESTDIR)$(DATADIR)'/tree-sitter/queries/confindent '$(DESTDIR)$(INCLUDEDIR)'/tree_sitter '$(DESTDIR)$(PCLIBDIR)' '$(DESTDIR)$(LIBDIR)' 74 + install -m644 bindings/c/tree_sitter/$(LANGUAGE_NAME).h '$(DESTDIR)$(INCLUDEDIR)'/tree_sitter/$(LANGUAGE_NAME).h 75 + install -m644 $(LANGUAGE_NAME).pc '$(DESTDIR)$(PCLIBDIR)'/$(LANGUAGE_NAME).pc 76 + install -m644 lib$(LANGUAGE_NAME).a '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).a 77 + install -m755 lib$(LANGUAGE_NAME).$(SOEXT) '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXTVER) 78 + ln -sf lib$(LANGUAGE_NAME).$(SOEXTVER) '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXTVER_MAJOR) 79 + ln -sf lib$(LANGUAGE_NAME).$(SOEXTVER_MAJOR) '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXT) 80 + install -m644 queries/*.scm '$(DESTDIR)$(DATADIR)'/tree-sitter/queries/confindent 81 + 82 + uninstall: 83 + $(RM) '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).a \ 84 + '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXTVER) \ 85 + '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXTVER_MAJOR) \ 86 + '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXT) \ 87 + '$(DESTDIR)$(INCLUDEDIR)'/tree_sitter/$(LANGUAGE_NAME).h \ 88 + '$(DESTDIR)$(PCLIBDIR)'/$(LANGUAGE_NAME).pc 89 + $(RM) -r '$(DESTDIR)$(DATADIR)'/tree-sitter/queries/confindent 90 + 91 + clean: 92 + $(RM) $(OBJS) $(LANGUAGE_NAME).pc lib$(LANGUAGE_NAME).a lib$(LANGUAGE_NAME).$(SOEXT) 93 + 94 + test: 95 + $(TS) test 96 + 97 + .PHONY: all install uninstall clean test
+41
Package.swift
··· 1 + // swift-tools-version:5.3 2 + 3 + import Foundation 4 + import PackageDescription 5 + 6 + var sources = ["src/parser.c"] 7 + if FileManager.default.fileExists(atPath: "src/scanner.c") { 8 + sources.append("src/scanner.c") 9 + } 10 + 11 + let package = Package( 12 + name: "TreeSitterConfindent", 13 + products: [ 14 + .library(name: "TreeSitterConfindent", targets: ["TreeSitterConfindent"]), 15 + ], 16 + dependencies: [ 17 + .package(url: "https://github.com/tree-sitter/swift-tree-sitter", from: "0.8.0"), 18 + ], 19 + targets: [ 20 + .target( 21 + name: "TreeSitterConfindent", 22 + dependencies: [], 23 + path: ".", 24 + sources: sources, 25 + resources: [ 26 + .copy("queries") 27 + ], 28 + publicHeadersPath: "bindings/swift", 29 + cSettings: [.headerSearchPath("src")] 30 + ), 31 + .testTarget( 32 + name: "TreeSitterConfindentTests", 33 + dependencies: [ 34 + "SwiftTreeSitter", 35 + "TreeSitterConfindent", 36 + ], 37 + path: "bindings/swift/TreeSitterConfindentTests" 38 + ) 39 + ], 40 + cLanguageStandard: .c11 41 + )
+35
binding.gyp
··· 1 + { 2 + "targets": [ 3 + { 4 + "target_name": "tree_sitter_confindent_binding", 5 + "dependencies": [ 6 + "<!(node -p \"require('node-addon-api').targets\"):node_addon_api_except", 7 + ], 8 + "include_dirs": [ 9 + "src", 10 + ], 11 + "sources": [ 12 + "bindings/node/binding.cc", 13 + "src/parser.c", 14 + ], 15 + "variables": { 16 + "has_scanner": "<!(node -p \"fs.existsSync('src/scanner.c')\")" 17 + }, 18 + "conditions": [ 19 + ["has_scanner=='true'", { 20 + "sources+": ["src/scanner.c"], 21 + }], 22 + ["OS!='win'", { 23 + "cflags_c": [ 24 + "-std=c11", 25 + ], 26 + }, { # OS == "win" 27 + "cflags_c": [ 28 + "/std:c11", 29 + "/utf-8", 30 + ], 31 + }], 32 + ], 33 + } 34 + ] 35 + }
+10
bindings/c/tree-sitter-confindent.pc.in
··· 1 + prefix=@CMAKE_INSTALL_PREFIX@ 2 + libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@ 3 + includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@ 4 + 5 + Name: tree-sitter-confindent 6 + Description: @PROJECT_DESCRIPTION@ 7 + URL: @PROJECT_HOMEPAGE_URL@ 8 + Version: @PROJECT_VERSION@ 9 + Libs: -L${libdir} -ltree-sitter-confindent 10 + Cflags: -I${includedir}
+16
bindings/c/tree_sitter/tree-sitter-confindent.h
··· 1 + #ifndef TREE_SITTER_CONFINDENT_H_ 2 + #define TREE_SITTER_CONFINDENT_H_ 3 + 4 + typedef struct TSLanguage TSLanguage; 5 + 6 + #ifdef __cplusplus 7 + extern "C" { 8 + #endif 9 + 10 + const TSLanguage *tree_sitter_confindent(void); 11 + 12 + #ifdef __cplusplus 13 + } 14 + #endif 15 + 16 + #endif // TREE_SITTER_CONFINDENT_H_
+15
bindings/go/binding.go
··· 1 + package tree_sitter_confindent 2 + 3 + // #cgo CFLAGS: -std=c11 -fPIC 4 + // #include "../../src/parser.c" 5 + // #if __has_include("../../src/scanner.c") 6 + // #include "../../src/scanner.c" 7 + // #endif 8 + import "C" 9 + 10 + import "unsafe" 11 + 12 + // Get the tree-sitter Language for this grammar. 13 + func Language() unsafe.Pointer { 14 + return unsafe.Pointer(C.tree_sitter_confindent()) 15 + }
+15
bindings/go/binding_test.go
··· 1 + package tree_sitter_confindent_test 2 + 3 + import ( 4 + "testing" 5 + 6 + tree_sitter "github.com/tree-sitter/go-tree-sitter" 7 + tree_sitter_confindent "tangled.org/@nove.dev/tree-sitter-confindent/bindings/go" 8 + ) 9 + 10 + func TestCanLoadGrammar(t *testing.T) { 11 + language := tree_sitter.NewLanguage(tree_sitter_confindent.Language()) 12 + if language == nil { 13 + t.Errorf("Error loading Confindent grammar") 14 + } 15 + }
+19
bindings/node/binding.cc
··· 1 + #include <napi.h> 2 + 3 + typedef struct TSLanguage TSLanguage; 4 + 5 + extern "C" TSLanguage *tree_sitter_confindent(); 6 + 7 + // "tree-sitter", "language" hashed with BLAKE2 8 + const napi_type_tag LANGUAGE_TYPE_TAG = { 9 + 0x8AF2E5212AD58ABF, 0xD5006CAD83ABBA16 10 + }; 11 + 12 + Napi::Object Init(Napi::Env env, Napi::Object exports) { 13 + auto language = Napi::External<TSLanguage>::New(env, tree_sitter_confindent()); 14 + language.TypeTag(&LANGUAGE_TYPE_TAG); 15 + exports["language"] = language; 16 + return exports; 17 + } 18 + 19 + NODE_API_MODULE(tree_sitter_confindent_binding, Init)
+9
bindings/node/binding_test.js
··· 1 + const assert = require("node:assert"); 2 + const { test } = require("node:test"); 3 + 4 + const Parser = require("tree-sitter"); 5 + 6 + test("can load grammar", () => { 7 + const parser = new Parser(); 8 + assert.doesNotThrow(() => parser.setLanguage(require("."))); 9 + });
+27
bindings/node/index.d.ts
··· 1 + type BaseNode = { 2 + type: string; 3 + named: boolean; 4 + }; 5 + 6 + type ChildNode = { 7 + multiple: boolean; 8 + required: boolean; 9 + types: BaseNode[]; 10 + }; 11 + 12 + type NodeInfo = 13 + | (BaseNode & { 14 + subtypes: BaseNode[]; 15 + }) 16 + | (BaseNode & { 17 + fields: { [name: string]: ChildNode }; 18 + children: ChildNode[]; 19 + }); 20 + 21 + type Language = { 22 + language: unknown; 23 + nodeTypeInfo: NodeInfo[]; 24 + }; 25 + 26 + declare const language: Language; 27 + export = language;
+11
bindings/node/index.js
··· 1 + const root = require("path").join(__dirname, "..", ".."); 2 + 3 + module.exports = 4 + typeof process.versions.bun === "string" 5 + // Support `bun build --compile` by being statically analyzable enough to find the .node file at build-time 6 + ? require(`../../prebuilds/${process.platform}-${process.arch}/tree-sitter-confindent.node`) 7 + : require("node-gyp-build")(root); 8 + 9 + try { 10 + module.exports.nodeTypeInfo = require("../../src/node-types.json"); 11 + } catch (_) {}
+12
bindings/python/tests/test_binding.py
··· 1 + from unittest import TestCase 2 + 3 + import tree_sitter 4 + import tree_sitter_confindent 5 + 6 + 7 + class TestLanguage(TestCase): 8 + def test_can_load_grammar(self): 9 + try: 10 + tree_sitter.Language(tree_sitter_confindent.language()) 11 + except Exception: 12 + self.fail("Error loading Confindent grammar")
+42
bindings/python/tree_sitter_confindent/__init__.py
··· 1 + """tree-sitter implementation for the Confindent configuration language""" 2 + 3 + from importlib.resources import files as _files 4 + 5 + from ._binding import language 6 + 7 + 8 + def _get_query(name, file): 9 + query = _files(f"{__package__}.queries") / file 10 + globals()[name] = query.read_text() 11 + return globals()[name] 12 + 13 + 14 + def __getattr__(name): 15 + # NOTE: uncomment these to include any queries that this grammar contains: 16 + 17 + # if name == "HIGHLIGHTS_QUERY": 18 + # return _get_query("HIGHLIGHTS_QUERY", "highlights.scm") 19 + # if name == "INJECTIONS_QUERY": 20 + # return _get_query("INJECTIONS_QUERY", "injections.scm") 21 + # if name == "LOCALS_QUERY": 22 + # return _get_query("LOCALS_QUERY", "locals.scm") 23 + # if name == "TAGS_QUERY": 24 + # return _get_query("TAGS_QUERY", "tags.scm") 25 + 26 + raise AttributeError(f"module {__name__!r} has no attribute {name!r}") 27 + 28 + 29 + __all__ = [ 30 + "language", 31 + # "HIGHLIGHTS_QUERY", 32 + # "INJECTIONS_QUERY", 33 + # "LOCALS_QUERY", 34 + # "TAGS_QUERY", 35 + ] 36 + 37 + 38 + def __dir__(): 39 + return sorted(__all__ + [ 40 + "__all__", "__builtins__", "__cached__", "__doc__", "__file__", 41 + "__loader__", "__name__", "__package__", "__path__", "__spec__", 42 + ])
+10
bindings/python/tree_sitter_confindent/__init__.pyi
··· 1 + from typing import Final 2 + 3 + # NOTE: uncomment these to include any queries that this grammar contains: 4 + 5 + # HIGHLIGHTS_QUERY: Final[str] 6 + # INJECTIONS_QUERY: Final[str] 7 + # LOCALS_QUERY: Final[str] 8 + # TAGS_QUERY: Final[str] 9 + 10 + def language() -> object: ...
+35
bindings/python/tree_sitter_confindent/binding.c
··· 1 + #include <Python.h> 2 + 3 + typedef struct TSLanguage TSLanguage; 4 + 5 + TSLanguage *tree_sitter_confindent(void); 6 + 7 + static PyObject* _binding_language(PyObject *Py_UNUSED(self), PyObject *Py_UNUSED(args)) { 8 + return PyCapsule_New(tree_sitter_confindent(), "tree_sitter.Language", NULL); 9 + } 10 + 11 + static struct PyModuleDef_Slot slots[] = { 12 + #ifdef Py_GIL_DISABLED 13 + {Py_mod_gil, Py_MOD_GIL_NOT_USED}, 14 + #endif 15 + {0, NULL} 16 + }; 17 + 18 + static PyMethodDef methods[] = { 19 + {"language", _binding_language, METH_NOARGS, 20 + "Get the tree-sitter language for this grammar."}, 21 + {NULL, NULL, 0, NULL} 22 + }; 23 + 24 + static struct PyModuleDef module = { 25 + .m_base = PyModuleDef_HEAD_INIT, 26 + .m_name = "_binding", 27 + .m_doc = NULL, 28 + .m_size = 0, 29 + .m_methods = methods, 30 + .m_slots = slots, 31 + }; 32 + 33 + PyMODINIT_FUNC PyInit__binding(void) { 34 + return PyModuleDef_Init(&module); 35 + }
bindings/python/tree_sitter_confindent/py.typed

This is a binary file and will not be displayed.

+21
bindings/rust/build.rs
··· 1 + fn main() { 2 + let src_dir = std::path::Path::new("src"); 3 + 4 + let mut c_config = cc::Build::new(); 5 + c_config.std("c11").include(src_dir); 6 + 7 + #[cfg(target_env = "msvc")] 8 + c_config.flag("-utf-8"); 9 + 10 + let parser_path = src_dir.join("parser.c"); 11 + c_config.file(&parser_path); 12 + println!("cargo:rerun-if-changed={}", parser_path.to_str().unwrap()); 13 + 14 + let scanner_path = src_dir.join("scanner.c"); 15 + if scanner_path.exists() { 16 + c_config.file(&scanner_path); 17 + println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap()); 18 + } 19 + 20 + c_config.compile("tree-sitter-confindent"); 21 + }
+53
bindings/rust/lib.rs
··· 1 + //! This crate provides Confindent language support for the [tree-sitter][] parsing library. 2 + //! 3 + //! Typically, you will use the [LANGUAGE][] constant to add this language to a 4 + //! tree-sitter [Parser][], and then use the parser to parse some code: 5 + //! 6 + //! ``` 7 + //! let code = r#" 8 + //! "#; 9 + //! let mut parser = tree_sitter::Parser::new(); 10 + //! let language = tree_sitter_confindent::LANGUAGE; 11 + //! parser 12 + //! .set_language(&language.into()) 13 + //! .expect("Error loading Confindent parser"); 14 + //! let tree = parser.parse(code, None).unwrap(); 15 + //! assert!(!tree.root_node().has_error()); 16 + //! ``` 17 + //! 18 + //! [Parser]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Parser.html 19 + //! [tree-sitter]: https://tree-sitter.github.io/ 20 + 21 + use tree_sitter_language::LanguageFn; 22 + 23 + extern "C" { 24 + fn tree_sitter_confindent() -> *const (); 25 + } 26 + 27 + /// The tree-sitter [`LanguageFn`][LanguageFn] for this grammar. 28 + /// 29 + /// [LanguageFn]: https://docs.rs/tree-sitter-language/*/tree_sitter_language/struct.LanguageFn.html 30 + pub const LANGUAGE: LanguageFn = unsafe { LanguageFn::from_raw(tree_sitter_confindent) }; 31 + 32 + /// The content of the [`node-types.json`][] file for this grammar. 33 + /// 34 + /// [`node-types.json`]: https://tree-sitter.github.io/tree-sitter/using-parsers/6-static-node-types 35 + pub const NODE_TYPES: &str = include_str!("../../src/node-types.json"); 36 + 37 + // NOTE: uncomment these to include any queries that this grammar contains: 38 + 39 + // pub const HIGHLIGHTS_QUERY: &str = include_str!("../../queries/highlights.scm"); 40 + // pub const INJECTIONS_QUERY: &str = include_str!("../../queries/injections.scm"); 41 + // pub const LOCALS_QUERY: &str = include_str!("../../queries/locals.scm"); 42 + // pub const TAGS_QUERY: &str = include_str!("../../queries/tags.scm"); 43 + 44 + #[cfg(test)] 45 + mod tests { 46 + #[test] 47 + fn test_can_load_grammar() { 48 + let mut parser = tree_sitter::Parser::new(); 49 + parser 50 + .set_language(&super::LANGUAGE.into()) 51 + .expect("Error loading Confindent parser"); 52 + } 53 + }
+16
bindings/swift/TreeSitterConfindent/confindent.h
··· 1 + #ifndef TREE_SITTER_CONFINDENT_H_ 2 + #define TREE_SITTER_CONFINDENT_H_ 3 + 4 + typedef struct TSLanguage TSLanguage; 5 + 6 + #ifdef __cplusplus 7 + extern "C" { 8 + #endif 9 + 10 + const TSLanguage *tree_sitter_confindent(void); 11 + 12 + #ifdef __cplusplus 13 + } 14 + #endif 15 + 16 + #endif // TREE_SITTER_CONFINDENT_H_
+12
bindings/swift/TreeSitterConfindentTests/TreeSitterConfindentTests.swift
··· 1 + import XCTest 2 + import SwiftTreeSitter 3 + import TreeSitterConfindent 4 + 5 + final class TreeSitterConfindentTests: XCTestCase { 6 + func testCanLoadGrammar() throws { 7 + let parser = Parser() 8 + let language = Language(language: tree_sitter_confindent()) 9 + XCTAssertNoThrow(try parser.setLanguage(language), 10 + "Error loading Confindent grammar") 11 + } 12 + }
+5
go.mod
··· 1 + module tangled.org/@nove.dev/tree-sitter-confindent 2 + 3 + go 1.22 4 + 5 + require github.com/tree-sitter/go-tree-sitter v0.24.0
+17
grammar.js
··· 1 + /** 2 + * @file tree-sitter implementation for the Confindent configuration language 3 + * @author Devon Sawatsky <devon@nove.dev> 4 + * @license ISC 5 + */ 6 + 7 + /// <reference types="tree-sitter-cli/dsl" /> 8 + // @ts-check 9 + 10 + module.exports = grammar({ 11 + name: "confindent", 12 + 13 + rules: { 14 + // TODO: add the actual grammar rules 15 + source_file: $ => "hello" 16 + } 17 + });
+52
package.json
··· 1 + { 2 + "name": "tree-sitter-confindent", 3 + "version": "0.1.0", 4 + "description": "tree-sitter implementation for the Confindent configuration language", 5 + "repository": "https://tangled.org/@nove.dev/tree-sitter-confindent", 6 + "license": "ISC", 7 + "author": { 8 + "name": "Devon Sawatsky", 9 + "email": "devon@nove.dev", 10 + "url": "https://nove.dev/" 11 + }, 12 + "main": "bindings/node", 13 + "types": "bindings/node", 14 + "keywords": [ 15 + "incremental", 16 + "parsing", 17 + "tree-sitter", 18 + "confindent" 19 + ], 20 + "files": [ 21 + "grammar.js", 22 + "tree-sitter.json", 23 + "binding.gyp", 24 + "prebuilds/**", 25 + "bindings/node/*", 26 + "queries/*", 27 + "src/**", 28 + "*.wasm" 29 + ], 30 + "dependencies": { 31 + "node-addon-api": "^8.2.1", 32 + "node-gyp-build": "^4.8.2" 33 + }, 34 + "devDependencies": { 35 + "prebuildify": "^6.0.1", 36 + "tree-sitter-cli": "^0.25.3" 37 + }, 38 + "peerDependencies": { 39 + "tree-sitter": "^0.21.1" 40 + }, 41 + "peerDependenciesMeta": { 42 + "tree-sitter": { 43 + "optional": true 44 + } 45 + }, 46 + "scripts": { 47 + "install": "node-gyp-build", 48 + "prestart": "tree-sitter build --wasm", 49 + "start": "tree-sitter playground", 50 + "test": "node --test bindings/node/*_test.js" 51 + } 52 + }
+29
pyproject.toml
··· 1 + [build-system] 2 + requires = ["setuptools>=42", "wheel"] 3 + build-backend = "setuptools.build_meta" 4 + 5 + [project] 6 + name = "tree-sitter-confindent" 7 + description = "tree-sitter implementation for the Confindent configuration language" 8 + version = "0.1.0" 9 + keywords = ["incremental", "parsing", "tree-sitter", "confindent"] 10 + classifiers = [ 11 + "Intended Audience :: Developers", 12 + "Topic :: Software Development :: Compilers", 13 + "Topic :: Text Processing :: Linguistic", 14 + "Typing :: Typed", 15 + ] 16 + authors = [{ name = "Devon Sawatsky", email = "devon@nove.dev" }] 17 + requires-python = ">=3.10" 18 + license.text = "ISC" 19 + readme = "README.md" 20 + 21 + [project.urls] 22 + Homepage = "https://tangled.org/@nove.dev/tree-sitter-confindent" 23 + 24 + [project.optional-dependencies] 25 + core = ["tree-sitter~=0.24"] 26 + 27 + [tool.cibuildwheel] 28 + build = "cp310-*" 29 + build-frontend = "build"
+77
setup.py
··· 1 + from os import path 2 + from platform import system 3 + from sysconfig import get_config_var 4 + 5 + from setuptools import Extension, find_packages, setup 6 + from setuptools.command.build import build 7 + from setuptools.command.egg_info import egg_info 8 + from wheel.bdist_wheel import bdist_wheel 9 + 10 + sources = [ 11 + "bindings/python/tree_sitter_confindent/binding.c", 12 + "src/parser.c", 13 + ] 14 + if path.exists("src/scanner.c"): 15 + sources.append("src/scanner.c") 16 + 17 + macros: list[tuple[str, str | None]] = [ 18 + ("PY_SSIZE_T_CLEAN", None), 19 + ("TREE_SITTER_HIDE_SYMBOLS", None), 20 + ] 21 + if limited_api := not get_config_var("Py_GIL_DISABLED"): 22 + macros.append(("Py_LIMITED_API", "0x030A0000")) 23 + 24 + if system() != "Windows": 25 + cflags = ["-std=c11", "-fvisibility=hidden"] 26 + else: 27 + cflags = ["/std:c11", "/utf-8"] 28 + 29 + 30 + class Build(build): 31 + def run(self): 32 + if path.isdir("queries"): 33 + dest = path.join(self.build_lib, "tree_sitter_confindent", "queries") 34 + self.copy_tree("queries", dest) 35 + super().run() 36 + 37 + 38 + class BdistWheel(bdist_wheel): 39 + def get_tag(self): 40 + python, abi, platform = super().get_tag() 41 + if python.startswith("cp"): 42 + python, abi = "cp310", "abi3" 43 + return python, abi, platform 44 + 45 + 46 + class EggInfo(egg_info): 47 + def find_sources(self): 48 + super().find_sources() 49 + self.filelist.recursive_include("queries", "*.scm") 50 + self.filelist.include("src/tree_sitter/*.h") 51 + 52 + 53 + setup( 54 + packages=find_packages("bindings/python"), 55 + package_dir={"": "bindings/python"}, 56 + package_data={ 57 + "tree_sitter_confindent": ["*.pyi", "py.typed"], 58 + "tree_sitter_confindent.queries": ["*.scm"], 59 + }, 60 + ext_package="tree_sitter_confindent", 61 + ext_modules=[ 62 + Extension( 63 + name="_binding", 64 + sources=sources, 65 + extra_compile_args=cflags, 66 + define_macros=macros, 67 + include_dirs=["src"], 68 + py_limited_api=limited_api, 69 + ) 70 + ], 71 + cmdclass={ 72 + "build": Build, 73 + "bdist_wheel": BdistWheel, 74 + "egg_info": EggInfo, 75 + }, 76 + zip_safe=False 77 + )
+40
tree-sitter.json
··· 1 + { 2 + "$schema": "https://tree-sitter.github.io/tree-sitter/assets/schemas/config.schema.json", 3 + "grammars": [ 4 + { 5 + "name": "confindent", 6 + "camelcase": "Confindent", 7 + "title": "Confindent", 8 + "scope": "source.confindent", 9 + "file-types": [ 10 + "confindent" 11 + ], 12 + "injection-regex": "^confindent$", 13 + "class-name": "TreeSitterConfindent" 14 + } 15 + ], 16 + "metadata": { 17 + "version": "0.1.0", 18 + "license": "ISC", 19 + "description": "tree-sitter implementation for the Confindent configuration language", 20 + "authors": [ 21 + { 22 + "name": "Devon Sawatsky", 23 + "email": "devon@nove.dev", 24 + "url": "https://nove.dev/" 25 + } 26 + ], 27 + "links": { 28 + "repository": "https://tangled.org/@nove.dev/tree-sitter-confindent" 29 + } 30 + }, 31 + "bindings": { 32 + "c": true, 33 + "go": true, 34 + "node": true, 35 + "python": true, 36 + "rust": true, 37 + "swift": true, 38 + "zig": false 39 + } 40 + }