1
0
Fork 0
mirror of https://github.com/pnx/tree-sitter-dotenv synced 2026-06-16 14:04:57 +02:00

Compare commits

..

No commits in common. "main" and "v0.0.3" have entirely different histories.
main ... v0.0.3

30 changed files with 188 additions and 629 deletions

4
.gitattributes vendored
View file

@ -9,7 +9,3 @@ binding.gyp linguist-generated
setup.py linguist-generated setup.py linguist-generated
Makefile linguist-generated Makefile linguist-generated
Package.swift linguist-generated Package.swift linguist-generated
# Zig bindings
build.zig linguist-generated
build.zig.zon linguist-generated

View file

@ -1,81 +0,0 @@
version: 2
updates:
- package-ecosystem: github-actions
directory: /
schedule:
interval: weekly
day: sunday
commit-message:
prefix: ci
labels:
- dependencies
groups:
actions:
patterns: ["*"]
- package-ecosystem: npm
versioning-strategy: increase
directory: /
schedule:
interval: weekly
day: sunday
commit-message:
prefix: build(deps)
labels:
- dependencies
groups:
npm:
patterns: ["*"]
- package-ecosystem: cargo
directory: /
schedule:
interval: weekly
day: sunday
commit-message:
prefix: build(deps)
labels:
- dependencies
groups:
cargo:
patterns: ["*"]
- package-ecosystem: pip
directory: /
schedule:
interval: weekly
day: sunday
commit-message:
prefix: build(deps)
labels:
- dependencies
groups:
pip:
patterns: ["*"]
- package-ecosystem: swift
directory: /
schedule:
interval: weekly
day: sunday
commit-message:
prefix: build(deps)
labels:
- dependencies
groups:
swift:
patterns: ["*"]
- package-ecosystem: gomod
directory: /
schedule:
interval: weekly
day: sunday
commit-message:
prefix: build(deps)
labels:
- dependencies
groups:
go:
patterns: ["*"]

View file

@ -1,87 +0,0 @@
name: CI
on:
push:
paths:
- grammar.js
- src/**
- test/**
- bindings/**
- tree-sitter.json
pull_request:
paths:
- grammar.js
- src/**
- test/**
- bindings/**
- tree-sitter.json
concurrency:
group: ${{github.workflow}}-${{github.ref}}
cancel-in-progress: true
jobs:
test:
name: Test parser
runs-on: ${{matrix.os}}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Set up tree-sitter
uses: tree-sitter/setup-action/cli@v2
- name: Run parser and binding tests
uses: tree-sitter/parser-test-action@v2
with:
test-rust: true
- name: Parse sample files
uses: tree-sitter/parse-action@v4
id: parse-files
with:
files: examples/**
- name: Upload failures artifact
uses: actions/upload-artifact@v7
if: "!cancelled() && steps.parse-files.outcome == 'failure'"
with:
name: failures-${{runner.os}}
path: ${{steps.parse-files.outputs.failures}}
fuzz:
name: Fuzz scanner
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
fetch-depth: 2
- name: Check for scanner changes
id: scanner-check
run: |-
if git diff --quiet HEAD^ -- src/scanner.c; then
printf 'changed=false\n' >> "$GITHUB_OUTPUT"
else
printf 'changed=true\n' >> "$GITHUB_OUTPUT"
fi
- name: Run the fuzzer
uses: tree-sitter/fuzz-action@v4
if: steps.scanner-check.outputs.changed == 'true'
query:
name: Validate queries
runs-on: ubuntu-latest
steps:
- name: Set up repository
uses: actions/checkout@v6
- name: Set up tree-sitter
uses: tree-sitter/setup-action/cli@v2
- name: Build parser
run: tree-sitter build
- name: Set up ts_query_ls
run: curl -fL https://github.com/ribru17/ts_query_ls/releases/latest/download/ts_query_ls-x86_64-unknown-linux-gnu.tar.gz | tar -xz
- name: Check queries
run: ./ts_query_ls check -f queries/

View file

@ -1,17 +0,0 @@
name: Regenerate parser
on:
pull_request:
permissions:
contents: write
pull-requests: write
concurrency:
group: ${{github.workflow}}-${{github.ref}}
cancel-in-progress: true
jobs:
regenerate:
uses: tree-sitter/workflows/.github/workflows/regenerate.yml@main
if: github.actor == 'dependabot[bot]'

View file

@ -1,18 +0,0 @@
name: Create release
on:
push:
tags: ["*"]
concurrency:
group: ${{github.workflow}}-${{github.ref}}
cancel-in-progress: true
permissions:
contents: write
id-token: write
attestations: write
jobs:
release:
uses: tree-sitter/workflows/.github/workflows/release.yml@main

15
.gitignore vendored
View file

@ -1,12 +1,11 @@
# Rust artifacts # Rust artifacts
target/ target/
Cargo.lock
# Node artifacts # Node artifacts
build/ build/
prebuilds/ prebuilds/
node_modules/ node_modules/
package-lock.json *.tgz
# Swift artifacts # Swift artifacts
.build/ .build/
@ -28,13 +27,6 @@ dist/
*.dylib *.dylib
*.dll *.dll
*.pc *.pc
*.exp
*.lib
# Zig artifacts
.zig-cache/
zig-cache/
zig-out/
# Example dirs # Example dirs
/examples/*/ /examples/*/
@ -43,8 +35,3 @@ zig-out/
*.wasm *.wasm
*.obj *.obj
*.o *.o
# Archives
*.tar.gz
*.tgz
*.zip

View file

@ -1,4 +0,0 @@
{
"$schema": "https://raw.githubusercontent.com/ribru17/ts_query_ls/refs/heads/master/schemas/config.json",
"parser_install_directories": ["."]
}

View file

@ -1,66 +0,0 @@
cmake_minimum_required(VERSION 3.13)
project(tree-sitter-dotenv
VERSION "0.0.7"
DESCRIPTION "Dotenv grammar for tree-sitter"
HOMEPAGE_URL "https://github.com/pnx/tree-sitter-dotenv"
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()
include(GNUInstallDirs)
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-dotenv src/parser.c)
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/src/scanner.c)
target_sources(tree-sitter-dotenv PRIVATE src/scanner.c)
endif()
target_include_directories(tree-sitter-dotenv
PRIVATE src
INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/bindings/c>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
target_compile_definitions(tree-sitter-dotenv PRIVATE
$<$<BOOL:${TREE_SITTER_REUSE_ALLOCATOR}>:TREE_SITTER_REUSE_ALLOCATOR>
$<$<CONFIG:Debug>:TREE_SITTER_DEBUG>)
set_target_properties(tree-sitter-dotenv
PROPERTIES
C_STANDARD 11
POSITION_INDEPENDENT_CODE ON
SOVERSION "${TREE_SITTER_ABI_VERSION}.${PROJECT_VERSION_MAJOR}"
DEFINE_SYMBOL "")
configure_file(bindings/c/tree-sitter-dotenv.pc.in
"${CMAKE_CURRENT_BINARY_DIR}/tree-sitter-dotenv.pc" @ONLY)
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-dotenv.pc"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
install(TARGETS tree-sitter-dotenv
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}")
file(GLOB QUERIES queries/*.scm)
install(FILES ${QUERIES}
DESTINATION "${CMAKE_INSTALL_DATADIR}/tree-sitter/queries/dotenv")
add_custom_target(ts-test "${TREE_SITTER_CLI}" test
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
COMMENT "tree-sitter test")

View file

@ -1,7 +1,7 @@
[package] [package]
name = "tree-sitter-dotenv" name = "tree-sitter-dotenv"
description = "Dotenv grammar for tree-sitter" description = "Dotenv grammar for tree-sitter"
version = "0.0.7" version = "0.0.1"
license = "MIT" license = "MIT"
readme = "README.md" readme = "README.md"
keywords = ["incremental", "parsing", "tree-sitter", "dotenv"] keywords = ["incremental", "parsing", "tree-sitter", "dotenv"]
@ -23,4 +23,4 @@ tree-sitter-language = "0.1"
cc = "1.0.87" cc = "1.0.87"
[dev-dependencies] [dev-dependencies]
tree-sitter = "0.26.5" tree-sitter = "0.23"

4
Makefile generated
View file

@ -2,7 +2,7 @@ ifeq ($(OS),Windows_NT)
$(error Windows is not supported) $(error Windows is not supported)
endif endif
VERSION := 0.0.7 VERSION := 0.0.1
LANGUAGE_NAME := tree-sitter-dotenv LANGUAGE_NAME := tree-sitter-dotenv
@ -90,7 +90,7 @@ $(PARSER): $(SRC_DIR)/grammar.json
install: all install: all
install -d '$(DESTDIR)$(INCLUDEDIR)'/tree_sitter '$(DESTDIR)$(PCLIBDIR)' '$(DESTDIR)$(LIBDIR)' install -d '$(DESTDIR)$(INCLUDEDIR)'/tree_sitter '$(DESTDIR)$(PCLIBDIR)' '$(DESTDIR)$(LIBDIR)'
install -m644 bindings/c/tree_sitter/$(LANGUAGE_NAME).h '$(DESTDIR)$(INCLUDEDIR)'/tree_sitter/$(LANGUAGE_NAME).h 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 $(LANGUAGE_NAME).pc '$(DESTDIR)$(PCLIBDIR)'/$(LANGUAGE_NAME).pc
install -m644 lib$(LANGUAGE_NAME).a '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).a install -m644 lib$(LANGUAGE_NAME).a '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).a
install -m755 lib$(LANGUAGE_NAME).$(SOEXT) '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXTVER) install -m755 lib$(LANGUAGE_NAME).$(SOEXT) '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXTVER)

2
Package.swift generated
View file

@ -7,7 +7,7 @@ let package = Package(
.library(name: "TreeSitterDotenv", targets: ["TreeSitterDotenv"]), .library(name: "TreeSitterDotenv", targets: ["TreeSitterDotenv"]),
], ],
dependencies: [ dependencies: [
.package(name: "SwiftTreeSitter", url: "https://github.com/tree-sitter/swift-tree-sitter", from: "0.8.0"), .package(url: "https://github.com/ChimeHQ/SwiftTreeSitter", from: "0.8.0"),
], ],
targets: [ targets: [
.target( .target(

View file

@ -1,10 +1,6 @@
const root = require("path").join(__dirname, "..", ".."); const root = require("path").join(__dirname, "..", "..");
module.exports = module.exports = require("node-gyp-build")(root);
typeof process.versions.bun === "string"
// Support `bun build --compile` by being statically analyzable enough to find the .node file at build-time
? require(`../../prebuilds/${process.platform}-${process.arch}/tree-sitter-dotenv.node`)
: require("node-gyp-build")(root);
try { try {
module.exports.nodeTypeInfo = require("../../src/node-types.json"); module.exports.nodeTypeInfo = require("../../src/node-types.json");

View file

@ -6,6 +6,6 @@ import tree_sitter, tree_sitter_dotenv
class TestLanguage(TestCase): class TestLanguage(TestCase):
def test_can_load_grammar(self): def test_can_load_grammar(self):
try: try:
Parser(Language(tree_sitter_dotenv.language())) tree_sitter.Language(tree_sitter_dotenv.language())
except Exception: except Exception:
self.fail("Error loading Dotenv grammar") self.fail("Error loading Dotenv grammar")

View file

@ -8,13 +8,6 @@ static PyObject* _binding_language(PyObject *Py_UNUSED(self), PyObject *Py_UNUSE
return PyCapsule_New(tree_sitter_dotenv(), "tree_sitter.Language", NULL); return PyCapsule_New(tree_sitter_dotenv(), "tree_sitter.Language", NULL);
} }
static struct PyModuleDef_Slot slots[] = {
#ifdef Py_GIL_DISABLED
{Py_mod_gil, Py_MOD_GIL_NOT_USED},
#endif
{0, NULL}
};
static PyMethodDef methods[] = { static PyMethodDef methods[] = {
{"language", _binding_language, METH_NOARGS, {"language", _binding_language, METH_NOARGS,
"Get the tree-sitter language for this grammar."}, "Get the tree-sitter language for this grammar."},
@ -25,11 +18,10 @@ static struct PyModuleDef module = {
.m_base = PyModuleDef_HEAD_INIT, .m_base = PyModuleDef_HEAD_INIT,
.m_name = "_binding", .m_name = "_binding",
.m_doc = NULL, .m_doc = NULL,
.m_size = 0, .m_size = -1,
.m_methods = methods, .m_methods = methods
.m_slots = slots,
}; };
PyMODINIT_FUNC PyInit__binding(void) { PyMODINIT_FUNC PyInit__binding(void) {
return PyModuleDef_Init(&module); return PyModule_Create(&module);
} }

4
go.mod
View file

@ -1,7 +1,7 @@
module github.com/pnx/tree-sitter-dotenv module github.com/pnx/tree-sitter-dotenv
go 1.23 go 1.22
require github.com/tree-sitter/go-tree-sitter v0.25.0 require github.com/tree-sitter/go-tree-sitter v0.24.0
require github.com/mattn/go-pointer v0.0.1 // indirect require github.com/mattn/go-pointer v0.0.1 // indirect

56
go.sum
View file

@ -4,33 +4,33 @@ github.com/mattn/go-pointer v0.0.1 h1:n+XhsuGeVO6MEAp7xyEukFINEa+Quek5psIR/ylA6o
github.com/mattn/go-pointer v0.0.1/go.mod h1:2zXcozF6qYGgmsG+SeTZz3oAbFLdD3OWqnUbNvJZAlc= github.com/mattn/go-pointer v0.0.1/go.mod h1:2zXcozF6qYGgmsG+SeTZz3oAbFLdD3OWqnUbNvJZAlc=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/tree-sitter/go-tree-sitter v0.25.0 h1:sx6kcg8raRFCvc9BnXglke6axya12krCJF5xJ2sftRU= github.com/tree-sitter/go-tree-sitter v0.24.0 h1:kRZb6aBNfcI/u0Qh8XEt3zjNVnmxTisDBN+kXK0xRYQ=
github.com/tree-sitter/go-tree-sitter v0.25.0/go.mod h1:r77ig7BikoZhHrrsjAnv8RqGti5rtSyvDHPzgTPsUuU= github.com/tree-sitter/go-tree-sitter v0.24.0/go.mod h1:x681iFVoLMEwOSIHA1chaLkXlroXEN7WY+VHGFaoDbk=
github.com/tree-sitter/tree-sitter-c v0.23.4 h1:nBPH3FV07DzAD7p0GfNvXM+Y7pNIoPenQWBpvM++t4c= github.com/tree-sitter/tree-sitter-c v0.21.5-0.20240818205408-927da1f210eb h1:A8425heRM8mylnv4H58FPUiH+aYivyitre0PzxrfmWs=
github.com/tree-sitter/tree-sitter-c v0.23.4/go.mod h1:MkI5dOiIpeN94LNjeCp8ljXN/953JCwAby4bClMr6bw= github.com/tree-sitter/tree-sitter-c v0.21.5-0.20240818205408-927da1f210eb/go.mod h1:dOF6gtQiF9UwNh995T5OphYmtIypkjsp3ap7r9AN/iA=
github.com/tree-sitter/tree-sitter-cpp v0.23.4 h1:LaWZsiqQKvR65yHgKmnaqA+uz6tlDJTJFCyFIeZU/8w= github.com/tree-sitter/tree-sitter-cpp v0.22.4-0.20240818224355-b1a4e2b25148 h1:AfFPZwtwGN01BW1jDdqBVqscTwetvMpydqYZz57RSlc=
github.com/tree-sitter/tree-sitter-cpp v0.23.4/go.mod h1:doqNW64BriC7WBCQ1klf0KmJpdEvfxyXtoEybnBo6v8= github.com/tree-sitter/tree-sitter-cpp v0.22.4-0.20240818224355-b1a4e2b25148/go.mod h1:Bh6U3viD57rFXRYIQ+kmiYtr+1Bx0AceypDLJJSyi9s=
github.com/tree-sitter/tree-sitter-embedded-template v0.23.2 h1:nFkkH6Sbe56EXLmZBqHHcamTpmz3TId97I16EnGy4rg= github.com/tree-sitter/tree-sitter-embedded-template v0.21.1-0.20240819044651-ffbf64942c33 h1:TwqSV3qLp3tKSqirGLRHnjFk9Tc2oy57LIl+FQ4GjI4=
github.com/tree-sitter/tree-sitter-embedded-template v0.23.2/go.mod h1:HNPOhN0qF3hWluYLdxWs5WbzP/iE4aaRVPMsdxuzIaQ= github.com/tree-sitter/tree-sitter-embedded-template v0.21.1-0.20240819044651-ffbf64942c33/go.mod h1:CvCKCt3v04Ufos1zZnNCelBDeCGRpPucaN8QczoUsN4=
github.com/tree-sitter/tree-sitter-go v0.23.4 h1:yt5KMGnTHS+86pJmLIAZMWxukr8W7Ae1STPvQUuNROA= github.com/tree-sitter/tree-sitter-go v0.21.3-0.20240818010209-8c0f0e7a6012 h1:Xvxck3tE5FW7F7bTS97iNM2ADMyCMJztVqn5HYKdJGo=
github.com/tree-sitter/tree-sitter-go v0.23.4/go.mod h1:Jrx8QqYN0v7npv1fJRH1AznddllYiCMUChtVjxPK040= github.com/tree-sitter/tree-sitter-go v0.21.3-0.20240818010209-8c0f0e7a6012/go.mod h1:T40D0O1cPvUU/+AmiXVXy1cncYQT6wem4Z0g4SfAYvY=
github.com/tree-sitter/tree-sitter-html v0.23.2 h1:1UYDV+Yd05GGRhVnTcbP58GkKLSHHZwVaN+lBZV11Lc= github.com/tree-sitter/tree-sitter-html v0.20.5-0.20240818004741-d11201a263d0 h1:c46K6uh5Dz00zJeU9BfjXdb8I+E4RkUdfnWJpQADXFo=
github.com/tree-sitter/tree-sitter-html v0.23.2/go.mod h1:gpUv/dG3Xl/eebqgeYeFMt+JLOY9cgFinb/Nw08a9og= github.com/tree-sitter/tree-sitter-html v0.20.5-0.20240818004741-d11201a263d0/go.mod h1:hcNt/kOJHcIcuMvouE7LJcYdeFUFbVpBJ6d4wmOA+tU=
github.com/tree-sitter/tree-sitter-java v0.23.5 h1:J9YeMGMwXYlKSP3K4Us8CitC6hjtMjqpeOf2GGo6tig= github.com/tree-sitter/tree-sitter-java v0.21.1-0.20240824015150-576d8097e495 h1:jrt4qbJVEFs4H93/ITxygHc6u0TGqAkkate7TQ4wFSA=
github.com/tree-sitter/tree-sitter-java v0.23.5/go.mod h1:NRKlI8+EznxA7t1Yt3xtraPk1Wzqh3GAIC46wxvc320= github.com/tree-sitter/tree-sitter-java v0.21.1-0.20240824015150-576d8097e495/go.mod h1:oyaR7fLnRV0hT9z6qwE9GkaeTom/hTDwK3H2idcOJFc=
github.com/tree-sitter/tree-sitter-javascript v0.23.1 h1:1fWupaRC0ArlHJ/QJzsfQ3Ibyopw7ZfQK4xXc40Zveo= github.com/tree-sitter/tree-sitter-javascript v0.21.5-0.20240818005344-15887341e5b5 h1:om4X9AVg3asL8gxNJDcz4e/Wp+VpQj1PY3uJXKr6EOg=
github.com/tree-sitter/tree-sitter-javascript v0.23.1/go.mod h1:lmGD1EJdCA+v0S1u2fFgepMg/opzSg/4pgFym2FPGAs= github.com/tree-sitter/tree-sitter-javascript v0.21.5-0.20240818005344-15887341e5b5/go.mod h1:nNqgPoV/h9uYWk6kYEFdEAhNVOacpfpRW5SFmdaP4tU=
github.com/tree-sitter/tree-sitter-json v0.24.8 h1:tV5rMkihgtiOe14a9LHfDY5kzTl5GNUYe6carZBn0fQ= github.com/tree-sitter/tree-sitter-json v0.21.1-0.20240818005659-bdd69eb8c8a5 h1:pfV3G3k7NCKqKk8THBmyuh2zA33lgYHS3GVrzRR8ry4=
github.com/tree-sitter/tree-sitter-json v0.24.8/go.mod h1:F351KK0KGvCaYbZ5zxwx/gWWvZhIDl0eMtn+1r+gQbo= github.com/tree-sitter/tree-sitter-json v0.21.1-0.20240818005659-bdd69eb8c8a5/go.mod h1:GbMKRjLfk0H+PI7nLi1Sx5lHf5wCpLz9al8tQYSxpEk=
github.com/tree-sitter/tree-sitter-php v0.23.11 h1:iHewsLNDmznh8kgGyfWfujsZxIz1YGbSd2ZTEM0ZiP8= github.com/tree-sitter/tree-sitter-php v0.22.9-0.20240819002312-a552625b56c1 h1:ZXZMDwE+IhUtGug4Brv6NjJWUU3rfkZBKpemf6RY8/g=
github.com/tree-sitter/tree-sitter-php v0.23.11/go.mod h1:T/kbfi+UcCywQfUNAJnGTN/fMSUjnwPXA8k4yoIks74= github.com/tree-sitter/tree-sitter-php v0.22.9-0.20240819002312-a552625b56c1/go.mod h1:UKCLuYnJ312Mei+3cyTmGOHzn0YAnaPRECgJmHtzrqs=
github.com/tree-sitter/tree-sitter-python v0.23.6 h1:qHnWFR5WhtMQpxBZRwiaU5Hk/29vGju6CVtmvu5Haas= github.com/tree-sitter/tree-sitter-python v0.21.1-0.20240818005537-55a9b8a4fbfb h1:EXEM82lFM7JjJb6qiKZXkpIDaCcbV2obNn82ghwj9lw=
github.com/tree-sitter/tree-sitter-python v0.23.6/go.mod h1:cpdthSy/Yoa28aJFBscFHlGiU+cnSiSh1kuDVtI8YeM= github.com/tree-sitter/tree-sitter-python v0.21.1-0.20240818005537-55a9b8a4fbfb/go.mod h1:lXCF1nGG5Dr4J3BTS0ObN4xJCCICiSu/b+Xe/VqMV7g=
github.com/tree-sitter/tree-sitter-ruby v0.23.1 h1:T/NKHUA+iVbHM440hFx+lzVOzS4dV6z8Qw8ai+72bYo= github.com/tree-sitter/tree-sitter-ruby v0.21.1-0.20240818211811-7dbc1e2d0e2d h1:fcYCvoXdcP1uRQYXqJHRy6Hec+uKScQdKVtMwK9JeCI=
github.com/tree-sitter/tree-sitter-ruby v0.23.1/go.mod h1:kUS4kCCQloFcdX6sdpr8p6r2rogbM6ZjTox5ZOQy8cA= github.com/tree-sitter/tree-sitter-ruby v0.21.1-0.20240818211811-7dbc1e2d0e2d/go.mod h1:T1nShQ4v5AJtozZ8YyAS4uzUtDAJj/iv4YfwXSbUHzg=
github.com/tree-sitter/tree-sitter-rust v0.23.2 h1:6AtoooCW5GqNrRpfnvl0iUhxTAZEovEmLKDbyHlfw90= github.com/tree-sitter/tree-sitter-rust v0.21.3-0.20240818005432-2b43eafe6447 h1:o9alBu1J/WjrcTKEthYtXmdkDc5OVXD+PqlvnEZ0Lzc=
github.com/tree-sitter/tree-sitter-rust v0.23.2/go.mod h1:hfeGWic9BAfgTrc7Xf6FaOAguCFJRo3RBbs7QJ6D7MI= github.com/tree-sitter/tree-sitter-rust v0.21.3-0.20240818005432-2b43eafe6447/go.mod h1:1Oh95COkkTn6Ezp0vcMbvfhRP5gLeqqljR0BYnBzWvc=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

50
package-lock.json generated
View file

@ -1,21 +1,21 @@
{ {
"name": "tree-sitter-dotenv", "name": "tree-sitter-dotenv",
"version": "0.0.7", "version": "0.0.1",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "tree-sitter-dotenv", "name": "tree-sitter-dotenv",
"version": "0.0.7", "version": "0.0.1",
"hasInstallScript": true, "hasInstallScript": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"node-addon-api": "^8.8.0", "node-addon-api": "^8.0.0",
"node-gyp-build": "^4.8.1" "node-gyp-build": "^4.8.1"
}, },
"devDependencies": { "devDependencies": {
"prebuildify": "^6.0.1", "prebuildify": "^6.0.1",
"tree-sitter-cli": "^0.26.9" "tree-sitter-cli": "^0.23.2"
}, },
"peerDependencies": { "peerDependencies": {
"tree-sitter": "^0.21.1" "tree-sitter": "^0.21.1"
@ -92,9 +92,9 @@
"license": "ISC" "license": "ISC"
}, },
"node_modules/end-of-stream": { "node_modules/end-of-stream": {
"version": "1.4.5", "version": "1.4.4",
"resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.5.tgz", "resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.4.tgz",
"integrity": "sha512-ooEGc6HP26xXq/N+GCGOT0JKCLDGrq2bQUZrQ7gyrJiZANJ/8YDTxTpQBXGMn+WbIQXNVpyWymm7KYVICQnyOg==", "integrity": "sha512-+uw1inIHVPQoaVuHzRyXd21icM+cnt4CzD5rW+NC1wjOUSTOs+Te7FOv7AhN7vS9x/oIyhLP5PR1H+phQAHu5Q==",
"dev": true, "dev": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
@ -154,9 +154,9 @@
"license": "MIT" "license": "MIT"
}, },
"node_modules/node-abi": { "node_modules/node-abi": {
"version": "3.87.0", "version": "3.71.0",
"resolved": "https://registry.npmjs.org/node-abi/-/node-abi-3.87.0.tgz", "resolved": "https://registry.npmjs.org/node-abi/-/node-abi-3.71.0.tgz",
"integrity": "sha512-+CGM1L1CgmtheLcBuleyYOn7NWPVu0s0EJH2C4puxgEZb9h8QpR9G2dBfZJOAUhi7VQxuBPMd0hiISWcTyiYyQ==", "integrity": "sha512-SZ40vRiy/+wRTf21hxkkEjPJZpARzUMVcJoQse2EF8qkUWbbO2z7vd5oA/H6bVH6SZQ5STGcu0KRDS7biNRfxw==",
"dev": true, "dev": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
@ -167,9 +167,9 @@
} }
}, },
"node_modules/node-addon-api": { "node_modules/node-addon-api": {
"version": "8.8.0", "version": "8.3.0",
"resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-8.8.0.tgz", "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-8.3.0.tgz",
"integrity": "sha512-c5Ko1fZJIJmzhFIkhRN76WTq+fC6tWnGy9CXA0fA+XygsWZmEwG8vmbkNqxMyoaa0Tin4djul49NzdVcJJcjeA==", "integrity": "sha512-8VOpLHFrOQlAH+qA0ZzuGRlALRA6/LVh8QJldbrC4DY0hXoMP0l4Acq8TzFC018HztWiRqyCEj2aTWY2UvnJUg==",
"license": "MIT", "license": "MIT",
"engines": { "engines": {
"node": "^18 || ^20 || >= 21" "node": "^18 || ^20 || >= 21"
@ -238,9 +238,9 @@
} }
}, },
"node_modules/pump": { "node_modules/pump": {
"version": "3.0.3", "version": "3.0.2",
"resolved": "https://registry.npmjs.org/pump/-/pump-3.0.3.tgz", "resolved": "https://registry.npmjs.org/pump/-/pump-3.0.2.tgz",
"integrity": "sha512-todwxLMY7/heScKmntwQG8CXVkWUOdYxIvY2s0VWAAMh/nd8SoYiRaKjlr7+iCs984f2P8zvrfWcDDYVb73NfA==", "integrity": "sha512-tUPXtzlGM8FE3P0ZL6DVs/3P58k9nk8/jZeQCurTJylQA8qFYzHFfhBJkuqyE0FifOsQ0uKWekiZ5g8wtr28cw==",
"dev": true, "dev": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
@ -285,9 +285,9 @@
"license": "MIT" "license": "MIT"
}, },
"node_modules/semver": { "node_modules/semver": {
"version": "7.7.4", "version": "7.6.3",
"resolved": "https://registry.npmjs.org/semver/-/semver-7.7.4.tgz", "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.3.tgz",
"integrity": "sha512-vFKC2IEtQnVhpT78h1Yp8wzwrf8CM+MzKMHGJZfBtzhZNycRFnXsHk6E5TxIkkMsgNS7mdX3AGB7x2QM2di4lA==", "integrity": "sha512-oVekP1cKtI+CTDvHWYFUcMtsK/00wmAEfyqKfNdARm8u1wNVhSgaX7A8d4UuIlUI5e84iEwOhs7ZPYRmzU9U6A==",
"dev": true, "dev": true,
"license": "ISC", "license": "ISC",
"bin": { "bin": {
@ -308,9 +308,9 @@
} }
}, },
"node_modules/tar-fs": { "node_modules/tar-fs": {
"version": "2.1.4", "version": "2.1.1",
"resolved": "https://registry.npmjs.org/tar-fs/-/tar-fs-2.1.4.tgz", "resolved": "https://registry.npmjs.org/tar-fs/-/tar-fs-2.1.1.tgz",
"integrity": "sha512-mDAjwmZdh7LTT6pNleZ05Yt65HC3E+NiQzl672vQG38jIrehtJk/J3mNwIg+vShQPcLF/LV7CMnDW6vjj6sfYQ==", "integrity": "sha512-V0r2Y9scmbDRLCNex/+hYzvp/zyYjvFbHPNgVTKfQvVrb6guiE/fxP+XblDNR011utopbkex2nM4dHNV6GDsng==",
"dev": true, "dev": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
@ -338,9 +338,9 @@
} }
}, },
"node_modules/tree-sitter-cli": { "node_modules/tree-sitter-cli": {
"version": "0.26.9", "version": "0.23.2",
"resolved": "https://registry.npmjs.org/tree-sitter-cli/-/tree-sitter-cli-0.26.9.tgz", "resolved": "https://registry.npmjs.org/tree-sitter-cli/-/tree-sitter-cli-0.23.2.tgz",
"integrity": "sha512-7l+U1RmazPVe+yA/JiX80GFOILnL/j24GbawamIzNQC8UlINrcyECbaWGaG1wuq4j/m0DQTx7Uu4r0iW9Ao1BQ==", "integrity": "sha512-kPPXprOqREX+C/FgUp2Qpt9jd0vSwn+hOgjzVv/7hapdoWpa+VeWId53rf4oNNd29ikheF12BYtGD/W90feMbA==",
"dev": true, "dev": true,
"hasInstallScript": true, "hasInstallScript": true,
"license": "MIT", "license": "MIT",

View file

@ -1,6 +1,6 @@
{ {
"name": "tree-sitter-dotenv", "name": "tree-sitter-dotenv",
"version": "0.0.7", "version": "0.0.1",
"description": "Dotenv grammar for tree-sitter", "description": "Dotenv grammar for tree-sitter",
"repository": "github:pnx/tree-sitter-dotenv", "repository": "github:pnx/tree-sitter-dotenv",
"license": "MIT", "license": "MIT",
@ -22,12 +22,12 @@
"*.wasm" "*.wasm"
], ],
"dependencies": { "dependencies": {
"node-addon-api": "^8.8.0", "node-addon-api": "^8.0.0",
"node-gyp-build": "^4.8.1" "node-gyp-build": "^4.8.1"
}, },
"devDependencies": { "devDependencies": {
"prebuildify": "^6.0.1", "prebuildify": "^6.0.1",
"tree-sitter-cli": "^0.26.9" "tree-sitter-cli": "^0.23.2"
}, },
"peerDependencies": { "peerDependencies": {
"tree-sitter": "^0.21.1" "tree-sitter": "^0.21.1"

View file

@ -1,11 +1,11 @@
[build-system] [build-system]
requires = ["setuptools>=82.0.1", "wheel"] requires = ["setuptools>=42", "wheel"]
build-backend = "setuptools.build_meta" build-backend = "setuptools.build_meta"
[project] [project]
name = "tree-sitter-dotenv" name = "tree-sitter-dotenv"
description = "Dotenv grammar for tree-sitter" description = "Dotenv grammar for tree-sitter"
version = "0.0.7" version = "0.0.1"
keywords = ["incremental", "parsing", "tree-sitter", "dotenv"] keywords = ["incremental", "parsing", "tree-sitter", "dotenv"]
classifiers = [ classifiers = [
"Intended Audience :: Developers", "Intended Audience :: Developers",
@ -14,7 +14,7 @@ classifiers = [
"Topic :: Text Processing :: Linguistic", "Topic :: Text Processing :: Linguistic",
"Typing :: Typed" "Typing :: Typed"
] ]
requires-python = ">=3.10" requires-python = ">=3.9"
license.text = "MIT" license.text = "MIT"
readme = "README.md" readme = "README.md"
@ -22,8 +22,8 @@ readme = "README.md"
Homepage = "https://github.com/pnx/tree-sitter-dotenv" Homepage = "https://github.com/pnx/tree-sitter-dotenv"
[project.optional-dependencies] [project.optional-dependencies]
core = ["tree-sitter~=0.25"] core = ["tree-sitter~=0.22"]
[tool.cibuildwheel] [tool.cibuildwheel]
build = "cp310-*" build = "cp39-*"
build-frontend = "build" build-frontend = "build"

View file

@ -1,16 +1,7 @@
"=" @operator "=" @operator
(comment) @comment
(boolean) @constant (boolean) @constant
(number) @number (number) @number
(string) @string
[ [(identifier) (variable)] @variable
(string) (value) @string
(value) (comment) @comment
] @string
[
(identifier)
(variable)
] @variable

47
setup.py generated
View file

@ -1,49 +1,27 @@
from os import path from os.path import isdir, join
from sysconfig import get_config_var from platform import system
from setuptools import Extension, find_packages, setup from setuptools import Extension, find_packages, setup
from setuptools.command.build import build from setuptools.command.build import build
from setuptools.command.build_ext import build_ext
from setuptools.command.egg_info import egg_info
from wheel.bdist_wheel import bdist_wheel from wheel.bdist_wheel import bdist_wheel
class Build(build): class Build(build):
def run(self): def run(self):
if path.isdir("queries"): if isdir("queries"):
dest = path.join(self.build_lib, "tree_sitter_dotenv", "queries") dest = join(self.build_lib, "tree_sitter_dotenv", "queries")
self.copy_tree("queries", dest) self.copy_tree("queries", dest)
super().run() super().run()
class BuildExt(build_ext):
def build_extension(self, ext: Extension):
if self.compiler.compiler_type != "msvc":
ext.extra_compile_args = ["-std=c11", "-fvisibility=hidden"]
else:
ext.extra_compile_args = ["/std:c11", "/utf-8"]
if path.exists("src/scanner.c"):
ext.sources.append("src/scanner.c")
if ext.py_limited_api:
ext.define_macros.append(("Py_LIMITED_API", "0x030A0000"))
super().build_extension(ext)
class BdistWheel(bdist_wheel): class BdistWheel(bdist_wheel):
def get_tag(self): def get_tag(self):
python, abi, platform = super().get_tag() python, abi, platform = super().get_tag()
if python.startswith("cp"): if python.startswith("cp"):
python, abi = "cp310", "abi3" python, abi = "cp39", "abi3"
return python, abi, platform return python, abi, platform
class EggInfo(egg_info):
def find_sources(self):
super().find_sources()
self.filelist.recursive_include("queries", "*.scm")
self.filelist.include("src/tree_sitter/*.h")
setup( setup(
packages=find_packages("bindings/python"), packages=find_packages("bindings/python"),
package_dir={"": "bindings/python"}, package_dir={"": "bindings/python"},
@ -58,20 +36,27 @@ setup(
sources=[ sources=[
"bindings/python/tree_sitter_dotenv/binding.c", "bindings/python/tree_sitter_dotenv/binding.c",
"src/parser.c", "src/parser.c",
# NOTE: if your language uses an external scanner, add it here.
],
extra_compile_args=[
"-std=c11",
"-fvisibility=hidden",
] if system() != "Windows" else [
"/std:c11",
"/utf-8",
], ],
define_macros=[ define_macros=[
("Py_LIMITED_API", "0x03090000"),
("PY_SSIZE_T_CLEAN", None), ("PY_SSIZE_T_CLEAN", None),
("TREE_SITTER_HIDE_SYMBOLS", None), ("TREE_SITTER_HIDE_SYMBOLS", None),
], ],
include_dirs=["src"], include_dirs=["src"],
py_limited_api=not get_config_var("Py_GIL_DISABLED"), py_limited_api=True,
) )
], ],
cmdclass={ cmdclass={
"build": Build, "build": Build,
"build_ext": BuildExt, "bdist_wheel": BdistWheel
"bdist_wheel": BdistWheel,
"egg_info": EggInfo,
}, },
zip_safe=False zip_safe=False
) )

6
src/grammar.json generated
View file

@ -1,5 +1,4 @@
{ {
"$schema": "https://tree-sitter.github.io/tree-sitter/assets/schemas/grammar.schema.json",
"name": "dotenv", "name": "dotenv",
"rules": { "rules": {
"document": { "document": {
@ -294,6 +293,5 @@
} }
], ],
"inline": [], "inline": [],
"supertypes": [], "supertypes": []
"reserved": {} }
}

1
src/node-types.json generated
View file

@ -44,7 +44,6 @@
{ {
"type": "document", "type": "document",
"named": true, "named": true,
"root": true,
"fields": {}, "fields": {},
"children": { "children": {
"multiple": true, "multiple": true,

28
src/parser.c generated
View file

@ -1,12 +1,10 @@
/* Automatically @generated by tree-sitter */
#include "tree_sitter/parser.h" #include "tree_sitter/parser.h"
#if defined(__GNUC__) || defined(__clang__) #if defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic ignored "-Wmissing-field-initializers" #pragma GCC diagnostic ignored "-Wmissing-field-initializers"
#endif #endif
#define LANGUAGE_VERSION 15 #define LANGUAGE_VERSION 14
#define STATE_COUNT 32 #define STATE_COUNT 32
#define LARGE_STATE_COUNT 3 #define LARGE_STATE_COUNT 3
#define SYMBOL_COUNT 28 #define SYMBOL_COUNT 28
@ -15,9 +13,7 @@
#define EXTERNAL_TOKEN_COUNT 1 #define EXTERNAL_TOKEN_COUNT 1
#define FIELD_COUNT 2 #define FIELD_COUNT 2
#define MAX_ALIAS_SEQUENCE_LENGTH 4 #define MAX_ALIAS_SEQUENCE_LENGTH 4
#define MAX_RESERVED_WORD_SET_SIZE 0
#define PRODUCTION_ID_COUNT 3 #define PRODUCTION_ID_COUNT 3
#define SUPERTYPE_COUNT 0
enum ts_symbol_identifiers { enum ts_symbol_identifiers {
anon_sym_EQ = 1, anon_sym_EQ = 1,
@ -237,7 +233,7 @@ static const char * const ts_field_names[] = {
[field_value] = "value", [field_value] = "value",
}; };
static const TSMapSlice ts_field_map_slices[PRODUCTION_ID_COUNT] = { static const TSFieldMapSlice ts_field_map_slices[PRODUCTION_ID_COUNT] = {
[1] = {.index = 0, .length = 1}, [1] = {.index = 0, .length = 1},
[2] = {.index = 1, .length = 2}, [2] = {.index = 1, .length = 2},
}; };
@ -637,7 +633,7 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) {
} }
} }
static const TSLexerMode ts_lex_modes[STATE_COUNT] = { static const TSLexMode ts_lex_modes[STATE_COUNT] = {
[0] = {.lex_state = 0, .external_lex_state = 1}, [0] = {.lex_state = 0, .external_lex_state = 1},
[1] = {.lex_state = 8}, [1] = {.lex_state = 8},
[2] = {.lex_state = 1, .external_lex_state = 1}, [2] = {.lex_state = 1, .external_lex_state = 1},
@ -673,7 +669,7 @@ static const TSLexerMode ts_lex_modes[STATE_COUNT] = {
}; };
static const uint16_t ts_parse_table[LARGE_STATE_COUNT][SYMBOL_COUNT] = { static const uint16_t ts_parse_table[LARGE_STATE_COUNT][SYMBOL_COUNT] = {
[STATE(0)] = { [0] = {
[ts_builtin_sym_end] = ACTIONS(1), [ts_builtin_sym_end] = ACTIONS(1),
[anon_sym_EQ] = ACTIONS(1), [anon_sym_EQ] = ACTIONS(1),
[sym_comment] = ACTIONS(1), [sym_comment] = ACTIONS(1),
@ -689,7 +685,7 @@ static const uint16_t ts_parse_table[LARGE_STATE_COUNT][SYMBOL_COUNT] = {
[sym_boolean] = ACTIONS(1), [sym_boolean] = ACTIONS(1),
[sym__end_of_assignment] = ACTIONS(1), [sym__end_of_assignment] = ACTIONS(1),
}, },
[STATE(1)] = { [1] = {
[sym_document] = STATE(15), [sym_document] = STATE(15),
[sym_assignment] = STATE(4), [sym_assignment] = STATE(4),
[aux_sym_document_repeat1] = STATE(4), [aux_sym_document_repeat1] = STATE(4),
@ -697,7 +693,7 @@ static const uint16_t ts_parse_table[LARGE_STATE_COUNT][SYMBOL_COUNT] = {
[sym_comment] = ACTIONS(5), [sym_comment] = ACTIONS(5),
[sym_identifier] = ACTIONS(7), [sym_identifier] = ACTIONS(7),
}, },
[STATE(2)] = { [2] = {
[sym_variable] = STATE(19), [sym_variable] = STATE(19),
[sym__value] = STATE(19), [sym__value] = STATE(19),
[sym_string] = STATE(19), [sym_string] = STATE(19),
@ -978,7 +974,7 @@ void tree_sitter_dotenv_external_scanner_deserialize(void *, const char *, unsig
TS_PUBLIC const TSLanguage *tree_sitter_dotenv(void) { TS_PUBLIC const TSLanguage *tree_sitter_dotenv(void) {
static const TSLanguage language = { static const TSLanguage language = {
.abi_version = LANGUAGE_VERSION, .version = LANGUAGE_VERSION,
.symbol_count = SYMBOL_COUNT, .symbol_count = SYMBOL_COUNT,
.alias_count = ALIAS_COUNT, .alias_count = ALIAS_COUNT,
.token_count = TOKEN_COUNT, .token_count = TOKEN_COUNT,
@ -986,7 +982,6 @@ TS_PUBLIC const TSLanguage *tree_sitter_dotenv(void) {
.state_count = STATE_COUNT, .state_count = STATE_COUNT,
.large_state_count = LARGE_STATE_COUNT, .large_state_count = LARGE_STATE_COUNT,
.production_id_count = PRODUCTION_ID_COUNT, .production_id_count = PRODUCTION_ID_COUNT,
.supertype_count = SUPERTYPE_COUNT,
.field_count = FIELD_COUNT, .field_count = FIELD_COUNT,
.max_alias_sequence_length = MAX_ALIAS_SEQUENCE_LENGTH, .max_alias_sequence_length = MAX_ALIAS_SEQUENCE_LENGTH,
.parse_table = &ts_parse_table[0][0], .parse_table = &ts_parse_table[0][0],
@ -1001,7 +996,7 @@ TS_PUBLIC const TSLanguage *tree_sitter_dotenv(void) {
.public_symbol_map = ts_symbol_map, .public_symbol_map = ts_symbol_map,
.alias_map = ts_non_terminal_alias_map, .alias_map = ts_non_terminal_alias_map,
.alias_sequences = &ts_alias_sequences[0][0], .alias_sequences = &ts_alias_sequences[0][0],
.lex_modes = (const void*)ts_lex_modes, .lex_modes = ts_lex_modes,
.lex_fn = ts_lex, .lex_fn = ts_lex,
.external_scanner = { .external_scanner = {
&ts_external_scanner_states[0][0], &ts_external_scanner_states[0][0],
@ -1013,13 +1008,6 @@ TS_PUBLIC const TSLanguage *tree_sitter_dotenv(void) {
tree_sitter_dotenv_external_scanner_deserialize, tree_sitter_dotenv_external_scanner_deserialize,
}, },
.primary_state_ids = ts_primary_state_ids, .primary_state_ids = ts_primary_state_ids,
.name = "dotenv",
.max_reserved_word_set_size = 0,
.metadata = {
.major_version = 0,
.minor_version = 0,
.patch_version = 7,
},
}; };
return &language; return &language;
} }

View file

@ -18,7 +18,7 @@ unsigned tree_sitter_dotenv_external_scanner_serialize(void *payload, char *buff
void tree_sitter_dotenv_external_scanner_deserialize(void *payload, const char *buffer, unsigned length) {} void tree_sitter_dotenv_external_scanner_deserialize(void *payload, const char *buffer, unsigned length) {}
void static advanceWS(TSLexer *lexer) { void advanceWS(TSLexer *lexer) {
while (lexer->lookahead == ' ' || lexer->lookahead == '\t') { while (lexer->lookahead == ' ' || lexer->lookahead == '\t') {
lexer->advance(lexer, true); lexer->advance(lexer, true);
} }

View file

@ -12,10 +12,10 @@ extern "C" {
// Allow clients to override allocation functions // Allow clients to override allocation functions
#ifdef TREE_SITTER_REUSE_ALLOCATOR #ifdef TREE_SITTER_REUSE_ALLOCATOR
extern void *(*ts_current_malloc)(size_t size); extern void *(*ts_current_malloc)(size_t);
extern void *(*ts_current_calloc)(size_t count, size_t size); extern void *(*ts_current_calloc)(size_t, size_t);
extern void *(*ts_current_realloc)(void *ptr, size_t size); extern void *(*ts_current_realloc)(void *, size_t);
extern void (*ts_current_free)(void *ptr); extern void (*ts_current_free)(void *);
#ifndef ts_malloc #ifndef ts_malloc
#define ts_malloc ts_current_malloc #define ts_malloc ts_current_malloc

184
src/tree_sitter/array.h generated
View file

@ -14,7 +14,6 @@ extern "C" {
#include <string.h> #include <string.h>
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4101) #pragma warning(disable : 4101)
#elif defined(__GNUC__) || defined(__clang__) #elif defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic push #pragma GCC diagnostic push
@ -52,96 +51,67 @@ extern "C" {
/// Reserve `new_capacity` elements of space in the array. If `new_capacity` is /// 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. /// less than the array's current capacity, this function has no effect.
#define array_reserve(self, new_capacity) \ #define array_reserve(self, new_capacity) \
((self)->contents = _array__reserve( \ _array__reserve((Array *)(self), array_elem_size(self), new_capacity)
(void *)(self)->contents, &(self)->capacity, \
array_elem_size(self), new_capacity) \
)
/// Free any memory allocated for this array. Note that this does not free any /// Free any memory allocated for this array. Note that this does not free any
/// memory allocated for the array's contents. /// memory allocated for the array's contents.
#define array_delete(self) \ #define array_delete(self) _array__delete((Array *)(self))
do { \
if ((self)->contents) ts_free((self)->contents); \
(self)->contents = NULL; \
(self)->size = 0; \
(self)->capacity = 0; \
} while (0)
/// Push a new `element` onto the end of the array. /// Push a new `element` onto the end of the array.
#define array_push(self, element) \ #define array_push(self, element) \
do { \ (_array__grow((Array *)(self), 1, array_elem_size(self)), \
(self)->contents = _array__grow( \ (self)->contents[(self)->size++] = (element))
(void *)(self)->contents, (self)->size, &(self)->capacity, \
1, array_elem_size(self) \
); \
(self)->contents[(self)->size++] = (element); \
} while(0)
/// Increase the array's size by `count` elements. /// Increase the array's size by `count` elements.
/// New elements are zero-initialized. /// New elements are zero-initialized.
#define array_grow_by(self, count) \ #define array_grow_by(self, count) \
do { \ do { \
if ((count) == 0) break; \ if ((count) == 0) break; \
(self)->contents = _array__grow( \ _array__grow((Array *)(self), count, array_elem_size(self)); \
(self)->contents, (self)->size, &(self)->capacity, \
count, array_elem_size(self) \
); \
memset((self)->contents + (self)->size, 0, (count) * array_elem_size(self)); \ memset((self)->contents + (self)->size, 0, (count) * array_elem_size(self)); \
(self)->size += (count); \ (self)->size += (count); \
} while (0) } while (0)
/// Append all elements from one array to the end of another. /// Append all elements from one array to the end of another.
#define array_push_all(self, other) \ #define array_push_all(self, other) \
array_extend((self), (other)->size, (other)->contents) array_extend((self), (other)->size, (other)->contents)
/// Append `count` elements to the end of the array, reading their values from the /// Append `count` elements to the end of the array, reading their values from the
/// `contents` pointer. /// `contents` pointer.
#define array_extend(self, count, other_contents) \ #define array_extend(self, count, contents) \
(self)->contents = _array__splice( \ _array__splice( \
(void*)(self)->contents, &(self)->size, &(self)->capacity, \ (Array *)(self), array_elem_size(self), (self)->size, \
array_elem_size(self), (self)->size, 0, count, other_contents \ 0, count, contents \
) )
/// Remove `old_count` elements from the array starting at the given `index`. At /// 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 /// the same index, insert `new_count` new elements, reading their values from the
/// `new_contents` pointer. /// `new_contents` pointer.
#define array_splice(self, _index, old_count, new_count, new_contents) \ #define array_splice(self, _index, old_count, new_count, new_contents) \
(self)->contents = _array__splice( \ _array__splice( \
(void *)(self)->contents, &(self)->size, &(self)->capacity, \ (Array *)(self), array_elem_size(self), _index, \
array_elem_size(self), _index, old_count, new_count, new_contents \ old_count, new_count, new_contents \
) )
/// Insert one `element` into the array at the given `index`. /// Insert one `element` into the array at the given `index`.
#define array_insert(self, _index, element) \ #define array_insert(self, _index, element) \
(self)->contents = _array__splice( \ _array__splice((Array *)(self), array_elem_size(self), _index, 0, 1, &(element))
(void *)(self)->contents, &(self)->size, &(self)->capacity, \
array_elem_size(self), _index, 0, 1, &(element) \
)
/// Remove one element from the array at the given `index`. /// Remove one element from the array at the given `index`.
#define array_erase(self, _index) \ #define array_erase(self, _index) \
_array__erase((void *)(self)->contents, &(self)->size, array_elem_size(self), _index) _array__erase((Array *)(self), array_elem_size(self), _index)
/// Pop the last element off the array, returning the element by value. /// Pop the last element off the array, returning the element by value.
#define array_pop(self) ((self)->contents[--(self)->size]) #define array_pop(self) ((self)->contents[--(self)->size])
/// Assign the contents of one array to another, reallocating if necessary. /// Assign the contents of one array to another, reallocating if necessary.
#define array_assign(self, other) \ #define array_assign(self, other) \
(self)->contents = _array__assign( \ _array__assign((Array *)(self), (const Array *)(other), array_elem_size(self))
(void *)(self)->contents, &(self)->size, &(self)->capacity, \
(const void *)(other)->contents, (other)->size, array_elem_size(self) \
)
/// Swap one array with another /// Swap one array with another
#define array_swap(self, other) \ #define array_swap(self, other) \
do { \ _array__swap((Array *)(self), (Array *)(other))
void *_array_swap_tmp = (void *)(self)->contents; \
(self)->contents = (other)->contents; \
(other)->contents = _array_swap_tmp; \
_array__swap(&(self)->size, &(self)->capacity, \
&(other)->size, &(other)->capacity); \
} while (0)
/// Get the size of the array contents /// Get the size of the array contents
#define array_elem_size(self) (sizeof *(self)->contents) #define array_elem_size(self) (sizeof *(self)->contents)
@ -186,90 +156,82 @@ extern "C" {
// Private // Private
// Pointers to individual `Array` fields (rather than the entire `Array` itself) typedef Array(void) Array;
// are passed to the various `_array__*` functions below to address strict aliasing
// violations that arises when the _entire_ `Array` struct is passed as `Array(void)*`. /// This is not what you're looking for, see `array_delete`.
// static inline void _array__delete(Array *self) {
// The `Array` type itself was not altered as a solution in order to avoid breakage if (self->contents) {
// with existing consumers (in particular, parsers with external scanners). ts_free(self->contents);
self->contents = NULL;
self->size = 0;
self->capacity = 0;
}
}
/// This is not what you're looking for, see `array_erase`. /// This is not what you're looking for, see `array_erase`.
static inline void _array__erase(void* self_contents, uint32_t *size, static inline void _array__erase(Array *self, size_t element_size,
size_t element_size, uint32_t index) { uint32_t index) {
assert(index < *size); assert(index < self->size);
char *contents = (char *)self_contents; char *contents = (char *)self->contents;
memmove(contents + index * element_size, contents + (index + 1) * element_size, memmove(contents + index * element_size, contents + (index + 1) * element_size,
(*size - index - 1) * element_size); (self->size - index - 1) * element_size);
(*size)--; self->size--;
} }
/// This is not what you're looking for, see `array_reserve`. /// This is not what you're looking for, see `array_reserve`.
static inline void *_array__reserve(void *contents, uint32_t *capacity, static inline void _array__reserve(Array *self, size_t element_size, uint32_t new_capacity) {
size_t element_size, uint32_t new_capacity) { if (new_capacity > self->capacity) {
void *new_contents = contents; if (self->contents) {
if (new_capacity > *capacity) { self->contents = ts_realloc(self->contents, new_capacity * element_size);
if (contents) {
new_contents = ts_realloc(contents, new_capacity * element_size);
} else { } else {
new_contents = ts_malloc(new_capacity * element_size); self->contents = ts_malloc(new_capacity * element_size);
} }
*capacity = new_capacity; self->capacity = new_capacity;
} }
return new_contents;
} }
/// This is not what you're looking for, see `array_assign`. /// This is not what you're looking for, see `array_assign`.
static inline void *_array__assign(void* self_contents, uint32_t *self_size, uint32_t *self_capacity, static inline void _array__assign(Array *self, const Array *other, size_t element_size) {
const void *other_contents, uint32_t other_size, size_t element_size) { _array__reserve(self, element_size, other->size);
void *new_contents = _array__reserve(self_contents, self_capacity, element_size, other_size); self->size = other->size;
*self_size = other_size; memcpy(self->contents, other->contents, self->size * element_size);
memcpy(new_contents, other_contents, *self_size * element_size);
return new_contents;
} }
/// This is not what you're looking for, see `array_swap`. /// This is not what you're looking for, see `array_swap`.
static inline void _array__swap(uint32_t *self_size, uint32_t *self_capacity, static inline void _array__swap(Array *self, Array *other) {
uint32_t *other_size, uint32_t *other_capacity) { Array swap = *other;
uint32_t tmp_size = *self_size; *other = *self;
uint32_t tmp_capacity = *self_capacity; *self = swap;
*self_size = *other_size;
*self_capacity = *other_capacity;
*other_size = tmp_size;
*other_capacity = tmp_capacity;
} }
/// This is not what you're looking for, see `array_push` or `array_grow_by`. /// This is not what you're looking for, see `array_push` or `array_grow_by`.
static inline void *_array__grow(void *contents, uint32_t size, uint32_t *capacity, static inline void _array__grow(Array *self, uint32_t count, size_t element_size) {
uint32_t count, size_t element_size) { uint32_t new_size = self->size + count;
void *new_contents = contents; if (new_size > self->capacity) {
uint32_t new_size = size + count; uint32_t new_capacity = self->capacity * 2;
if (new_size > *capacity) {
uint32_t new_capacity = *capacity * 2;
if (new_capacity < 8) new_capacity = 8; if (new_capacity < 8) new_capacity = 8;
if (new_capacity < new_size) new_capacity = new_size; if (new_capacity < new_size) new_capacity = new_size;
new_contents = _array__reserve(contents, capacity, element_size, new_capacity); _array__reserve(self, element_size, new_capacity);
} }
return new_contents;
} }
/// This is not what you're looking for, see `array_splice`. /// This is not what you're looking for, see `array_splice`.
static inline void *_array__splice(void *self_contents, uint32_t *size, uint32_t *capacity, static inline void _array__splice(Array *self, size_t element_size,
size_t element_size,
uint32_t index, uint32_t old_count, uint32_t index, uint32_t old_count,
uint32_t new_count, const void *elements) { uint32_t new_count, const void *elements) {
uint32_t new_size = *size + new_count - old_count; uint32_t new_size = self->size + new_count - old_count;
uint32_t old_end = index + old_count; uint32_t old_end = index + old_count;
uint32_t new_end = index + new_count; uint32_t new_end = index + new_count;
assert(old_end <= *size); assert(old_end <= self->size);
void *new_contents = _array__reserve(self_contents, capacity, element_size, new_size); _array__reserve(self, element_size, new_size);
char *contents = (char *)new_contents; char *contents = (char *)self->contents;
if (*size > old_end) { if (self->size > old_end) {
memmove( memmove(
contents + new_end * element_size, contents + new_end * element_size,
contents + old_end * element_size, contents + old_end * element_size,
(*size - old_end) * element_size (self->size - old_end) * element_size
); );
} }
if (new_count > 0) { if (new_count > 0) {
@ -287,9 +249,7 @@ static inline void *_array__splice(void *self_contents, uint32_t *size, uint32_t
); );
} }
} }
*size += new_count - old_count; self->size += new_count - old_count;
return new_contents;
} }
/// A binary search routine, based on Rust's `std::slice::binary_search_by`. /// A binary search routine, based on Rust's `std::slice::binary_search_by`.
@ -318,7 +278,7 @@ static inline void *_array__splice(void *self_contents, uint32_t *size, uint32_t
#define _compare_int(a, b) ((int)*(a) - (int)(b)) #define _compare_int(a, b) ((int)*(a) - (int)(b))
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(pop) #pragma warning(default : 4101)
#elif defined(__GNUC__) || defined(__clang__) #elif defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic pop #pragma GCC diagnostic pop
#endif #endif

View file

@ -18,11 +18,6 @@ typedef uint16_t TSStateId;
typedef uint16_t TSSymbol; typedef uint16_t TSSymbol;
typedef uint16_t TSFieldId; typedef uint16_t TSFieldId;
typedef struct TSLanguage TSLanguage; typedef struct TSLanguage TSLanguage;
typedef struct TSLanguageMetadata {
uint8_t major_version;
uint8_t minor_version;
uint8_t patch_version;
} TSLanguageMetadata;
#endif #endif
typedef struct { typedef struct {
@ -31,11 +26,10 @@ typedef struct {
bool inherited; bool inherited;
} TSFieldMapEntry; } TSFieldMapEntry;
// Used to index the field and supertype maps.
typedef struct { typedef struct {
uint16_t index; uint16_t index;
uint16_t length; uint16_t length;
} TSMapSlice; } TSFieldMapSlice;
typedef struct { typedef struct {
bool visible; bool visible;
@ -85,12 +79,6 @@ typedef struct {
uint16_t external_lex_state; uint16_t external_lex_state;
} TSLexMode; } TSLexMode;
typedef struct {
uint16_t lex_state;
uint16_t external_lex_state;
uint16_t reserved_word_set_id;
} TSLexerMode;
typedef union { typedef union {
TSParseAction action; TSParseAction action;
struct { struct {
@ -105,7 +93,7 @@ typedef struct {
} TSCharacterRange; } TSCharacterRange;
struct TSLanguage { struct TSLanguage {
uint32_t abi_version; uint32_t version;
uint32_t symbol_count; uint32_t symbol_count;
uint32_t alias_count; uint32_t alias_count;
uint32_t token_count; uint32_t token_count;
@ -121,13 +109,13 @@ struct TSLanguage {
const TSParseActionEntry *parse_actions; const TSParseActionEntry *parse_actions;
const char * const *symbol_names; const char * const *symbol_names;
const char * const *field_names; const char * const *field_names;
const TSMapSlice *field_map_slices; const TSFieldMapSlice *field_map_slices;
const TSFieldMapEntry *field_map_entries; const TSFieldMapEntry *field_map_entries;
const TSSymbolMetadata *symbol_metadata; const TSSymbolMetadata *symbol_metadata;
const TSSymbol *public_symbol_map; const TSSymbol *public_symbol_map;
const uint16_t *alias_map; const uint16_t *alias_map;
const TSSymbol *alias_sequences; const TSSymbol *alias_sequences;
const TSLexerMode *lex_modes; const TSLexMode *lex_modes;
bool (*lex_fn)(TSLexer *, TSStateId); bool (*lex_fn)(TSLexer *, TSStateId);
bool (*keyword_lex_fn)(TSLexer *, TSStateId); bool (*keyword_lex_fn)(TSLexer *, TSStateId);
TSSymbol keyword_capture_token; TSSymbol keyword_capture_token;
@ -141,23 +129,15 @@ struct TSLanguage {
void (*deserialize)(void *, const char *, unsigned); void (*deserialize)(void *, const char *, unsigned);
} external_scanner; } external_scanner;
const TSStateId *primary_state_ids; 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) { static inline bool set_contains(TSCharacterRange *ranges, uint32_t len, int32_t lookahead) {
uint32_t index = 0; uint32_t index = 0;
uint32_t size = len - index; uint32_t size = len - index;
while (size > 1) { while (size > 1) {
uint32_t half_size = size / 2; uint32_t half_size = size / 2;
uint32_t mid_index = index + half_size; uint32_t mid_index = index + half_size;
const TSCharacterRange *range = &ranges[mid_index]; TSCharacterRange *range = &ranges[mid_index];
if (lookahead >= range->start && lookahead <= range->end) { if (lookahead >= range->start && lookahead <= range->end) {
return true; return true;
} else if (lookahead > range->end) { } else if (lookahead > range->end) {
@ -165,7 +145,7 @@ static inline bool set_contains(const TSCharacterRange *ranges, uint32_t len, in
} }
size -= half_size; size -= half_size;
} }
const TSCharacterRange *range = &ranges[index]; TSCharacterRange *range = &ranges[index];
return (lookahead >= range->start && lookahead <= range->end); return (lookahead >= range->start && lookahead <= range->end);
} }

View file

@ -1,40 +0,0 @@
{
"$schema": "https://tree-sitter.github.io/tree-sitter/assets/schemas/config.schema.json",
"grammars": [
{
"name": "dotenv",
"camelcase": "Dotenv",
"title": "Dotenv",
"scope": "source.dotenv",
"file-types": [
"dotenv"
],
"injection-regex": "^dotenv$",
"class-name": "TreeSitterDotenv",
"highlights": "queries/highlights.scm"
}
],
"metadata": {
"version": "0.0.7",
"license": "MIT",
"description": "Dotenv grammar for tree-sitter",
"authors": [
{
"name": "Henrik Hautakoski",
"email": "henrik.hautakoski@gmail.com"
}
],
"links": {
"repository": "https://github.com/pnx/tree-sitter-dotenv"
}
},
"bindings": {
"c": true,
"go": true,
"node": true,
"python": true,
"rust": true,
"swift": true,
"zig": false
}
}