mirror of
https://github.com/pnx/tree-sitter-dotenv
synced 2026-06-16 01:54:56 +02:00
update outdated files via tree-sitter init -u
This commit is contained in:
parent
940f387a98
commit
58608e4796
11 changed files with 137 additions and 27 deletions
4
.gitattributes
vendored
4
.gitattributes
vendored
|
|
@ -9,3 +9,7 @@ binding.gyp linguist-generated
|
|||
setup.py linguist-generated
|
||||
Makefile linguist-generated
|
||||
Package.swift linguist-generated
|
||||
|
||||
# Zig bindings
|
||||
build.zig linguist-generated
|
||||
build.zig.zon linguist-generated
|
||||
|
|
|
|||
15
.gitignore
vendored
15
.gitignore
vendored
|
|
@ -1,11 +1,12 @@
|
|||
# Rust artifacts
|
||||
target/
|
||||
Cargo.lock
|
||||
|
||||
# Node artifacts
|
||||
build/
|
||||
prebuilds/
|
||||
node_modules/
|
||||
*.tgz
|
||||
package-lock.json
|
||||
|
||||
# Swift artifacts
|
||||
.build/
|
||||
|
|
@ -27,6 +28,13 @@ dist/
|
|||
*.dylib
|
||||
*.dll
|
||||
*.pc
|
||||
*.exp
|
||||
*.lib
|
||||
|
||||
# Zig artifacts
|
||||
.zig-cache/
|
||||
zig-cache/
|
||||
zig-out/
|
||||
|
||||
# Example dirs
|
||||
/examples/*/
|
||||
|
|
@ -35,3 +43,8 @@ dist/
|
|||
*.wasm
|
||||
*.obj
|
||||
*.o
|
||||
|
||||
# Archives
|
||||
*.tar.gz
|
||||
*.tgz
|
||||
*.zip
|
||||
|
|
|
|||
66
CMakeLists.txt
Normal file
66
CMakeLists.txt
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
cmake_minimum_required(VERSION 3.13)
|
||||
|
||||
project(tree-sitter-dotenv
|
||||
VERSION "0.0.4"
|
||||
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")
|
||||
2
Makefile
generated
2
Makefile
generated
|
|
@ -90,7 +90,7 @@ $(PARSER): $(SRC_DIR)/grammar.json
|
|||
|
||||
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 bindings/c/tree_sitter/$(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)
|
||||
|
|
|
|||
2
Package.swift
generated
2
Package.swift
generated
|
|
@ -7,7 +7,7 @@ let package = Package(
|
|||
.library(name: "TreeSitterDotenv", targets: ["TreeSitterDotenv"]),
|
||||
],
|
||||
dependencies: [
|
||||
.package(url: "https://github.com/ChimeHQ/SwiftTreeSitter", from: "0.8.0"),
|
||||
.package(name: "SwiftTreeSitter", url: "https://github.com/tree-sitter/swift-tree-sitter", from: "0.8.0"),
|
||||
],
|
||||
targets: [
|
||||
.target(
|
||||
|
|
|
|||
6
bindings/node/index.js
generated
6
bindings/node/index.js
generated
|
|
@ -1,6 +1,10 @@
|
|||
const root = require("path").join(__dirname, "..", "..");
|
||||
|
||||
module.exports = require("node-gyp-build")(root);
|
||||
module.exports =
|
||||
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 {
|
||||
module.exports.nodeTypeInfo = require("../../src/node-types.json");
|
||||
|
|
|
|||
2
bindings/python/tests/test_binding.py
generated
2
bindings/python/tests/test_binding.py
generated
|
|
@ -6,6 +6,6 @@ import tree_sitter, tree_sitter_dotenv
|
|||
class TestLanguage(TestCase):
|
||||
def test_can_load_grammar(self):
|
||||
try:
|
||||
tree_sitter.Language(tree_sitter_dotenv.language())
|
||||
Parser(Language(tree_sitter_dotenv.language()))
|
||||
except Exception:
|
||||
self.fail("Error loading Dotenv grammar")
|
||||
|
|
|
|||
14
bindings/python/tree_sitter_dotenv/binding.c
generated
14
bindings/python/tree_sitter_dotenv/binding.c
generated
|
|
@ -8,6 +8,13 @@ static PyObject* _binding_language(PyObject *Py_UNUSED(self), PyObject *Py_UNUSE
|
|||
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[] = {
|
||||
{"language", _binding_language, METH_NOARGS,
|
||||
"Get the tree-sitter language for this grammar."},
|
||||
|
|
@ -18,10 +25,11 @@ static struct PyModuleDef module = {
|
|||
.m_base = PyModuleDef_HEAD_INIT,
|
||||
.m_name = "_binding",
|
||||
.m_doc = NULL,
|
||||
.m_size = -1,
|
||||
.m_methods = methods
|
||||
.m_size = 0,
|
||||
.m_methods = methods,
|
||||
.m_slots = slots,
|
||||
};
|
||||
|
||||
PyMODINIT_FUNC PyInit__binding(void) {
|
||||
return PyModule_Create(&module);
|
||||
return PyModuleDef_Init(&module);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ classifiers = [
|
|||
"Topic :: Text Processing :: Linguistic",
|
||||
"Typing :: Typed"
|
||||
]
|
||||
requires-python = ">=3.9"
|
||||
requires-python = ">=3.10"
|
||||
license.text = "MIT"
|
||||
readme = "README.md"
|
||||
|
||||
|
|
@ -22,8 +22,8 @@ readme = "README.md"
|
|||
Homepage = "https://github.com/pnx/tree-sitter-dotenv"
|
||||
|
||||
[project.optional-dependencies]
|
||||
core = ["tree-sitter~=0.22"]
|
||||
core = ["tree-sitter~=0.24"]
|
||||
|
||||
[tool.cibuildwheel]
|
||||
build = "cp39-*"
|
||||
build = "cp310-*"
|
||||
build-frontend = "build"
|
||||
|
|
|
|||
47
setup.py
generated
47
setup.py
generated
|
|
@ -1,27 +1,49 @@
|
|||
from os.path import isdir, join
|
||||
from platform import system
|
||||
from os import path
|
||||
from sysconfig import get_config_var
|
||||
|
||||
from setuptools import Extension, find_packages, setup
|
||||
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
|
||||
|
||||
|
||||
class Build(build):
|
||||
def run(self):
|
||||
if isdir("queries"):
|
||||
dest = join(self.build_lib, "tree_sitter_dotenv", "queries")
|
||||
if path.isdir("queries"):
|
||||
dest = path.join(self.build_lib, "tree_sitter_dotenv", "queries")
|
||||
self.copy_tree("queries", dest)
|
||||
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):
|
||||
def get_tag(self):
|
||||
python, abi, platform = super().get_tag()
|
||||
if python.startswith("cp"):
|
||||
python, abi = "cp39", "abi3"
|
||||
python, abi = "cp310", "abi3"
|
||||
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(
|
||||
packages=find_packages("bindings/python"),
|
||||
package_dir={"": "bindings/python"},
|
||||
|
|
@ -36,27 +58,20 @@ setup(
|
|||
sources=[
|
||||
"bindings/python/tree_sitter_dotenv/binding.c",
|
||||
"src/parser.c",
|
||||
# NOTE: if your language uses an external scanner, add it here.
|
||||
],
|
||||
extra_compile_args=[
|
||||
"-std=c11",
|
||||
"-fvisibility=hidden",
|
||||
] if system() != "Windows" else [
|
||||
"/std:c11",
|
||||
"/utf-8",
|
||||
],
|
||||
define_macros=[
|
||||
("Py_LIMITED_API", "0x03090000"),
|
||||
("PY_SSIZE_T_CLEAN", None),
|
||||
("TREE_SITTER_HIDE_SYMBOLS", None),
|
||||
],
|
||||
include_dirs=["src"],
|
||||
py_limited_api=True,
|
||||
py_limited_api=not get_config_var("Py_GIL_DISABLED"),
|
||||
)
|
||||
],
|
||||
cmdclass={
|
||||
"build": Build,
|
||||
"bdist_wheel": BdistWheel
|
||||
"build_ext": BuildExt,
|
||||
"bdist_wheel": BdistWheel,
|
||||
"egg_info": EggInfo,
|
||||
},
|
||||
zip_safe=False
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue