From 7413e052148f6ee2c7cfa724d2b893b6458246de Mon Sep 17 00:00:00 2001 From: Nate Whetsell Date: Sat, 5 Oct 2024 07:34:19 -0400 Subject: [PATCH] Generate parser with Tree-sitter 0.24.1 --- package.json | 23 ++-------- src/grammar.json | 1 + src/node-types.json | 1 + src/tree_sitter/alloc.h | 8 ++-- tree-sitter.json | 45 +++++++++++++++++++ .../update_builtins.py => update_builtins.py | 2 +- 6 files changed, 55 insertions(+), 25 deletions(-) create mode 100644 tree-sitter.json rename queries/update_builtins.py => update_builtins.py (99%) diff --git a/package.json b/package.json index 3a34c39..a7a5546 100644 --- a/package.json +++ b/package.json @@ -37,29 +37,12 @@ }, "devDependencies": { "prebuildify": "^6.0.0", - "tree-sitter-cli": "^0.23.2" + "tree-sitter-cli": "^0.24.1" }, "scripts": { "install": "node-gyp-build", "prestart": "tree-sitter build --wasm", "start": "tree-sitter playground", "test": "node --test bindings/node/*_test.js" - }, - "tree-sitter": [ - { - "scope": "source.lilypond", - "file-types": [ - "ily", - "ly" - ], - "highlights": [ - "queries/highlights.scm", - "queries/highlights-builtins.scm", - "tree-sitter-lilypond-scheme/queries/highlights.scm", - "tree-sitter-lilypond-scheme/queries/highlights-builtins.scm", - "tree-sitter-lilypond-scheme/queries/highlights-lilypond-builtins.scm" - ], - "injection-regex": "^l(?:ilypond|y)$" - } - ] -} + } +} \ No newline at end of file diff --git a/src/grammar.json b/src/grammar.json index fa29d20..621fb07 100644 --- a/src/grammar.json +++ b/src/grammar.json @@ -1,4 +1,5 @@ { + "$schema": "https://tree-sitter.github.io/tree-sitter/assets/schemas/grammar.schema.json", "name": "lilypond", "rules": { "lilypond_program": { diff --git a/src/node-types.json b/src/node-types.json index c06859b..6cbbab8 100644 --- a/src/node-types.json +++ b/src/node-types.json @@ -296,6 +296,7 @@ { "type": "lilypond_program", "named": true, + "root": true, "fields": {}, "children": { "multiple": true, diff --git a/src/tree_sitter/alloc.h b/src/tree_sitter/alloc.h index 1f4466d..1abdd12 100644 --- a/src/tree_sitter/alloc.h +++ b/src/tree_sitter/alloc.h @@ -12,10 +12,10 @@ extern "C" { // Allow clients to override allocation functions #ifdef TREE_SITTER_REUSE_ALLOCATOR -extern void *(*ts_current_malloc)(size_t); -extern void *(*ts_current_calloc)(size_t, size_t); -extern void *(*ts_current_realloc)(void *, size_t); -extern void (*ts_current_free)(void *); +extern void *(*ts_current_malloc)(size_t size); +extern void *(*ts_current_calloc)(size_t count, size_t size); +extern void *(*ts_current_realloc)(void *ptr, size_t size); +extern void (*ts_current_free)(void *ptr); #ifndef ts_malloc #define ts_malloc ts_current_malloc diff --git a/tree-sitter.json b/tree-sitter.json new file mode 100644 index 0000000..4558df6 --- /dev/null +++ b/tree-sitter.json @@ -0,0 +1,45 @@ +{ + "grammars": [ + { + "name": "lilypond", + "camelcase": "LilyPond", + "scope": "source.lilypond", + "path": ".", + "file-types": [ + "ily", + "ly" + ], + "highlights": [ + "queries/highlights.scm", + "queries/highlights-builtins.scm", + "tree-sitter-lilypond-scheme/queries/highlights.scm", + "tree-sitter-lilypond-scheme/queries/highlights-builtins.scm", + "tree-sitter-lilypond-scheme/queries/highlights-lilypond-builtins.scm" + ], + "injection-regex": "^l(?:ilypond|y)$" + } + ], + "metadata": { + "version": "0.0.0", + "license": "MIT", + "description": "LilyPond grammar for Tree-sitter", + "authors": [ + { + "name": "Nathan Whetsell", + "email": "nathan.whetsell@gmail.com" + } + ], + "links": { + "repository": "https://github.com/nwhetsell/tree-sitter-lilypond.git", + "homepage": "https://github.com/nwhetsell/tree-sitter-lilypond" + } + }, + "bindings": { + "c": true, + "go": true, + "node": true, + "python": true, + "rust": true, + "swift": true + } +} diff --git a/queries/update_builtins.py b/update_builtins.py similarity index 99% rename from queries/update_builtins.py rename to update_builtins.py index 43cc70c..d0ab951 100644 --- a/queries/update_builtins.py +++ b/update_builtins.py @@ -50,7 +50,7 @@ for keyword in ['markup', 'markuplist', 'override', 'score']: _lilypond_builtins.markup_commands.remove(keyword) -with open('highlights-builtins.scm', 'w') as file: +with open('queries/highlights-builtins.scm', 'w') as file: backslash_prefix = r'^\\\\' for list_and_selector in [ (_lilypond_builtins.keywords, 'keyword'),