Skip to content

Commit

Permalink
fix: unescaped curly brace in regex and invert query precedence for test
Browse files Browse the repository at this point in the history
  • Loading branch information
amaanq committed Mar 10, 2024
1 parent 99b29f1 commit 6178233
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 12 deletions.
5 changes: 3 additions & 2 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -512,7 +512,8 @@ module.exports = grammar({
seq(
$._unannotated_type,
choice($.identifier, $._reserved_identifier)
)),
)
),

underscore_pattern: $ => '_',

Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -34,6 +34,9 @@
"scope": "source.java",
"file-types": [
"java"
],
"highlights": [
"queries/highlights.scm"
]
}
]
Expand Down
8 changes: 6 additions & 2 deletions queries/highlights.scm
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
; Variables

(identifier) @variable

; Methods

(method_declaration
Expand Down Expand Up @@ -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

Expand Down
3 changes: 1 addition & 2 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -1442,7 +1442,7 @@
},
{
"type": "PATTERN",
"value": "u{[0-9a-fA-F]+}"
"value": "u\\{[0-9a-fA-F]+\\}"
}
]
}
Expand Down Expand Up @@ -7873,4 +7873,3 @@
"module_directive"
]
}

9 changes: 6 additions & 3 deletions src/parser.c
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 8 additions & 2 deletions src/tree_sitter/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,18 +129,24 @@ 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; \
next_state: \
lexer->advance(lexer, skip); \
start: \
skip = false; \
lookahead = lexer->lookahead; \
eof = lexer->eof(lexer);
lookahead = lexer->lookahead;

#define ADVANCE(state_value) \
{ \
Expand Down

0 comments on commit 6178233

Please sign in to comment.