Browse Source

feat!: regenerate parser and bindings with ABI 15

pull/264/head
Christian Clason 1 year ago
committed by Will Lillis
parent
commit
8c4aefef79
10 changed files with 210 additions and 37 deletions
  1. +1
    -1
      .gitattributes
  2. +7
    -0
      .gitignore
  3. +8
    -3
      CMakeLists.txt
  4. +1
    -1
      Makefile
  5. +1
    -1
      Package.swift
  6. +0
    -0
      bindings/c/tree_sitter/tree-sitter-c.h
  7. +11
    -3
      bindings/python/tree_sitter_c/binding.c
  8. +3
    -3
      pyproject.toml
  9. +38
    -22
      setup.py
  10. +140
    -3
      src/parser.c

+ 1
- 1
.gitattributes View File

@ -6,7 +6,7 @@ src/parser.c linguist-generated
src/tree_sitter/* linguist-generated
# C bindings
bindings/c/* linguist-generated
bindings/c/** linguist-generated
CMakeLists.txt linguist-generated
Makefile linguist-generated

+ 7
- 0
.gitignore View File

@ -25,6 +25,13 @@ dist/
*.dylib
*.dll
*.pc
*.exp
*.lib
# Zig artifacts
.zig-cache/
zig-cache/
zig-out/
# Example dirs
/examples/*/

+ 8
- 3
CMakeLists.txt View File

@ -28,7 +28,11 @@ add_library(tree-sitter-c src/parser.c)
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/src/scanner.c)
target_sources(tree-sitter-c PRIVATE src/scanner.c)
endif()
target_include_directories(tree-sitter-c PRIVATE src)
target_include_directories(tree-sitter-c
PRIVATE src
INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/bindings/c>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
target_compile_definitions(tree-sitter-c PRIVATE
$<$<BOOL:${TREE_SITTER_REUSE_ALLOCATOR}>:TREE_SITTER_REUSE_ALLOCATOR>
@ -46,8 +50,9 @@ configure_file(bindings/c/tree-sitter-c.pc.in
include(GNUInstallDirs)
install(FILES bindings/c/tree-sitter-c.h
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/tree_sitter")
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-c.pc"
DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig")
install(TARGETS tree-sitter-c

+ 1
- 1
Makefile View File

@ -70,7 +70,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)

+ 1
- 1
Package.swift View File

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

bindings/c/tree-sitter-c.h → bindings/c/tree_sitter/tree-sitter-c.h View File


+ 11
- 3
bindings/python/tree_sitter_c/binding.c View File

@ -8,6 +8,13 @@ static PyObject* _binding_language(PyObject *Py_UNUSED(self), PyObject *Py_UNUSE
return PyCapsule_New(tree_sitter_c(), "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);
}

+ 3
- 3
pyproject.toml View File

@ -18,7 +18,7 @@ authors = [
{ name = "Max Brunsfeld", email = "maxbrunsfeld@gmail.com" },
{ name = "Amaan Qureshi", email = "amaanq12@gmail.com" },
]
requires-python = ">=3.9"
requires-python = ">=3.10"
license.text = "MIT"
readme = "README.md"
@ -26,8 +26,8 @@ readme = "README.md"
Homepage = "https://github.com/tree-sitter/tree-sitter-c"
[project.optional-dependencies]
core = ["tree-sitter~=0.22"]
core = ["tree-sitter~=0.24"]
[tool.cibuildwheel]
build = "cp39-*"
build = "cp310-*"
build-frontend = "build"

+ 38
- 22
setup.py View File

@ -1,15 +1,36 @@
from os.path import isdir, join
from os import path
from platform import system
from sysconfig import get_config_var
from setuptools import Extension, find_packages, setup
from setuptools.command.build import build
from setuptools.command.egg_info import egg_info
from wheel.bdist_wheel import bdist_wheel
sources = [
"bindings/python/tree_sitter_c/binding.c",
"src/parser.c",
]
if path.exists("src/scanner.c"):
sources.append("src/scanner.c")
macros: list[tuple[str, str | None]] = [
("PY_SSIZE_T_CLEAN", None),
("TREE_SITTER_HIDE_SYMBOLS", None),
]
if limited_api := not get_config_var("Py_GIL_DISABLED"):
macros.append(("Py_LIMITED_API", "0x030A0000"))
if system() != "Windows":
cflags = ["-std=c11", "-fvisibility=hidden"]
else:
cflags = ["/std:c11", "/utf-8"]
class Build(build):
def run(self):
if isdir("queries"):
dest = join(self.build_lib, "tree_sitter_c", "queries")
if path.isdir("queries"):
dest = path.join(self.build_lib, "tree_sitter_c", "queries")
self.copy_tree("queries", dest)
super().run()
@ -18,10 +39,17 @@ 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"},
@ -33,29 +61,17 @@ setup(
ext_modules=[
Extension(
name="_binding",
sources=[
"bindings/python/tree_sitter_c/binding.c",
"src/parser.c",
],
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),
],
sources=sources,
extra_compile_args=cflags,
define_macros=macros,
include_dirs=["src"],
py_limited_api=True,
py_limited_api=limited_api,
)
],
cmdclass={
"build": Build,
"bdist_wheel": BdistWheel
"bdist_wheel": BdistWheel,
"egg_info": EggInfo,
},
zip_safe=False
)

+ 140
- 3
src/parser.c View File

@ -14,7 +14,7 @@
#pragma GCC optimize ("O0")
#endif
#define LANGUAGE_VERSION 14
#define LANGUAGE_VERSION 15
#define STATE_COUNT 2015
#define LARGE_STATE_COUNT 455
#define SYMBOL_COUNT 360
@ -25,7 +25,7 @@
#define MAX_ALIAS_SEQUENCE_LENGTH 9
#define MAX_RESERVED_WORD_SET_SIZE 0
#define PRODUCTION_ID_COUNT 131
#define SUPERTYPE_COUNT 0
#define SUPERTYPE_COUNT 7
enum ts_symbol_identifiers {
sym_identifier = 1,
@ -5262,6 +5262,132 @@ static const TSStateId ts_primary_state_ids[STATE_COUNT] = {
[2014] = 1809,
};
static const TSSymbol ts_supertype_symbols[SUPERTYPE_COUNT] = {
sym__abstract_declarator,
sym__declarator,
sym__field_declarator,
sym__type_declarator,
sym_expression,
sym_statement,
sym_type_specifier,
};
static const TSMapSlice ts_supertype_map_slices[] = {
[sym__abstract_declarator] = {.index = 0, .length = 4},
[sym__declarator] = {.index = 4, .length = 6},
[sym__field_declarator] = {.index = 10, .length = 18},
[sym__type_declarator] = {.index = 28, .length = 19},
[sym_expression] = {.index = 47, .length = 26},
[sym_statement] = {.index = 73, .length = 16},
[sym_type_specifier] = {.index = 89, .length = 7},
};
static const TSSymbol ts_supertype_map_entries[] = {
[0] =
sym_abstract_array_declarator,
sym_abstract_function_declarator,
sym_abstract_parenthesized_declarator,
sym_abstract_pointer_declarator,
[4] =
sym_array_declarator,
sym_attributed_declarator,
sym_function_declarator,
sym_identifier,
sym_parenthesized_declarator,
sym_pointer_declarator,
[10] =
alias_sym_field_identifier,
sym__function_declaration_declarator,
sym__old_style_function_declarator,
sym_array_declarator,
sym_array_field_declarator,
sym_array_type_declarator,
sym_attributed_declarator,
sym_attributed_field_declarator,
sym_attributed_type_declarator,
sym_function_declarator,
sym_function_field_declarator,
sym_function_type_declarator,
sym_parenthesized_declarator,
sym_parenthesized_field_declarator,
sym_parenthesized_type_declarator,
sym_pointer_declarator,
sym_pointer_field_declarator,
sym_pointer_type_declarator,
[28] =
alias_sym_type_identifier,
sym__function_declaration_declarator,
sym__old_style_function_declarator,
sym_array_declarator,
sym_array_field_declarator,
sym_array_type_declarator,
sym_attributed_declarator,
sym_attributed_field_declarator,
sym_attributed_type_declarator,
sym_function_declarator,
sym_function_field_declarator,
sym_function_type_declarator,
sym_parenthesized_declarator,
sym_parenthesized_field_declarator,
sym_parenthesized_type_declarator,
sym_pointer_declarator,
sym_pointer_field_declarator,
sym_pointer_type_declarator,
sym_primitive_type,
[47] =
sym_alignof_expression,
sym_assignment_expression,
sym_binary_expression,
sym_call_expression,
sym_cast_expression,
sym_char_literal,
sym_compound_literal_expression,
sym_concatenated_string,
sym_conditional_expression,
sym_extension_expression,
sym_false,
sym_field_expression,
sym_generic_expression,
sym_gnu_asm_expression,
sym_identifier,
sym_null,
sym_number_literal,
sym_offsetof_expression,
sym_parenthesized_expression,
sym_pointer_expression,
sym_sizeof_expression,
sym_string_literal,
sym_subscript_expression,
sym_true,
sym_unary_expression,
sym_update_expression,
[73] =
sym_attributed_statement,
sym_break_statement,
sym_case_statement,
sym_compound_statement,
sym_continue_statement,
sym_do_statement,
sym_expression_statement,
sym_for_statement,
sym_goto_statement,
sym_if_statement,
sym_labeled_statement,
sym_return_statement,
sym_seh_leave_statement,
sym_seh_try_statement,
sym_switch_statement,
sym_while_statement,
[89] =
alias_sym_type_identifier,
sym_enum_specifier,
sym_macro_type_specifier,
sym_primitive_type,
sym_sized_type_specifier,
sym_struct_specifier,
sym_union_specifier,
};
static const TSCharacterRange sym_number_literal_character_set_13[] = {
{'0', '9'}, {'B', 'B'}, {'D', 'D'}, {'F', 'F'}, {'L', 'L'}, {'U', 'U'}, {'W', 'W'}, {'b', 'b'},
{'d', 'd'}, {'f', 'f'}, {'l', 'l'}, {'u', 'u'}, {'w', 'w'},
@ -9535,7 +9661,7 @@ static bool ts_lex_keywords(TSLexer *lexer, TSStateId state) {
}
}
static const TSLexMode ts_lex_modes[STATE_COUNT] = {
static const TSLexerMode ts_lex_modes[STATE_COUNT] = {
[0] = {.lex_state = 0},
[1] = {.lex_state = 120},
[2] = {.lex_state = 45},
@ -118708,6 +118834,7 @@ TS_PUBLIC const TSLanguage *tree_sitter_c(void) {
.state_count = STATE_COUNT,
.large_state_count = LARGE_STATE_COUNT,
.production_id_count = PRODUCTION_ID_COUNT,
.supertype_count = SUPERTYPE_COUNT,
.field_count = FIELD_COUNT,
.max_alias_sequence_length = MAX_ALIAS_SEQUENCE_LENGTH,
.parse_table = &ts_parse_table[0][0],
@ -118718,6 +118845,9 @@ TS_PUBLIC const TSLanguage *tree_sitter_c(void) {
.field_names = ts_field_names,
.field_map_slices = ts_field_map_slices,
.field_map_entries = ts_field_map_entries,
.supertype_map_slices = ts_supertype_map_slices,
.supertype_map_entries = ts_supertype_map_entries,
.supertype_symbols = ts_supertype_symbols,
.symbol_metadata = ts_symbol_metadata,
.public_symbol_map = ts_symbol_map,
.alias_map = ts_non_terminal_alias_map,
@ -118727,6 +118857,13 @@ TS_PUBLIC const TSLanguage *tree_sitter_c(void) {
.keyword_lex_fn = ts_lex_keywords,
.keyword_capture_token = sym_identifier,
.primary_state_ids = ts_primary_state_ids,
.name = "c",
.max_reserved_word_set_size = 0,
.metadata = {
.major_version = 0,
.minor_version = 23,
.patch_version = 6,
},
};
return &language;
}

Loading…
Cancel
Save