From 5e62fbb519b608dfd856000fdc66536304c414de Mon Sep 17 00:00:00 2001 From: Amaan Qureshi Date: Sun, 10 Mar 2024 10:59:28 -0400 Subject: [PATCH] fix: unescaped curly brace in regex and invert query precedence for test --- grammar.js | 5 +++-- package.json | 5 ++++- queries/highlights.scm | 8 ++++++-- src/grammar.json | 3 +-- src/parser.c | 9 ++++++--- src/tree_sitter/parser.h | 10 ++++++++-- 6 files changed, 28 insertions(+), 12 deletions(-) diff --git a/grammar.js b/grammar.js index bfda731..6be88e1 100644 --- a/grammar.js +++ b/grammar.js @@ -203,7 +203,7 @@ module.exports = grammar({ /[0-7]{1,3}/, /x[0-9a-fA-F]{2}/, /u[0-9a-fA-F]{4}/, - /u{[0-9a-fA-F]+}/ + /u\{[0-9a-fA-F]+\}/ ))), null_literal: _ => 'null', @@ -512,7 +512,8 @@ module.exports = grammar({ seq( $._unannotated_type, choice($.identifier, $._reserved_identifier) - )), + ) + ), underscore_pattern: $ => '_', diff --git a/package.json b/package.json index 073a606..848941d 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "nan": "^2.14.1" }, "devDependencies": { - "tree-sitter-cli": "^0.20.6" + "tree-sitter-cli": "^0.21.0" }, "scripts": { "build": "tree-sitter generate && node-gyp rebuild", @@ -34,6 +34,9 @@ "scope": "source.java", "file-types": [ "java" + ], + "highlights": [ + "queries/highlights.scm" ] } ] diff --git a/queries/highlights.scm b/queries/highlights.scm index 301245b..9f5b7d6 100644 --- a/queries/highlights.scm +++ b/queries/highlights.scm @@ -1,3 +1,7 @@ +; Variables + +(identifier) @variable + ; Methods (method_declaration @@ -50,12 +54,12 @@ (void_type) ] @type.builtin -; Variables +; Constants ((identifier) @constant (#match? @constant "^_*[A-Z][A-Z\\d_]+$")) -(identifier) @variable +; Builtins (this) @variable.builtin diff --git a/src/grammar.json b/src/grammar.json index 914a2b9..8c77b2b 100644 --- a/src/grammar.json +++ b/src/grammar.json @@ -1442,7 +1442,7 @@ }, { "type": "PATTERN", - "value": "u{[0-9a-fA-F]+}" + "value": "u\\{[0-9a-fA-F]+\\}" } ] } @@ -7873,4 +7873,3 @@ "module_directive" ] } - diff --git a/src/parser.c b/src/parser.c index d63d9b8..c076e28 100644 --- a/src/parser.c +++ b/src/parser.c @@ -1,7 +1,6 @@ #include "tree_sitter/parser.h" #if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wmissing-field-initializers" #endif @@ -6858,6 +6857,7 @@ static inline bool sym_identifier_character_set_4(int32_t c) { static bool ts_lex(TSLexer *lexer, TSStateId state) { START_LEXER(); + eof = lexer->eof(lexer); switch (state) { case 0: if (eof) ADVANCE(69); @@ -8125,6 +8125,7 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { static bool ts_lex_keywords(TSLexer *lexer, TSStateId state) { START_LEXER(); + eof = lexer->eof(lexer); switch (state) { case 0: if (lookahead == '_') ADVANCE(1); @@ -78394,10 +78395,12 @@ static const TSParseActionEntry ts_parse_actions[] = { extern "C" { #endif #ifdef _WIN32 -#define extern __declspec(dllexport) +#define TS_PUBLIC __declspec(dllexport) +#else +#define TS_PUBLIC __attribute__((visibility("default"))) #endif -extern const TSLanguage *tree_sitter_java(void) { +TS_PUBLIC const TSLanguage *tree_sitter_java() { static const TSLanguage language = { .version = LANGUAGE_VERSION, .symbol_count = SYMBOL_COUNT, diff --git a/src/tree_sitter/parser.h b/src/tree_sitter/parser.h index d210325..17b4fde 100644 --- a/src/tree_sitter/parser.h +++ b/src/tree_sitter/parser.h @@ -129,9 +129,16 @@ struct TSLanguage { * Lexer Macros */ +#ifdef _MSC_VER +#define UNUSED __pragma(warning(suppress : 4101)) +#else +#define UNUSED __attribute__((unused)) +#endif + #define START_LEXER() \ bool result = false; \ bool skip = false; \ + UNUSED \ bool eof = false; \ int32_t lookahead; \ goto start; \ @@ -139,8 +146,7 @@ struct TSLanguage { lexer->advance(lexer, skip); \ start: \ skip = false; \ - lookahead = lexer->lookahead; \ - eof = lexer->eof(lexer); + lookahead = lexer->lookahead; #define ADVANCE(state_value) \ { \