diff --git a/grammar.js b/grammar.js index 5312f8b..45d59b2 100644 --- a/grammar.js +++ b/grammar.js @@ -219,7 +219,7 @@ module.exports = grammar({ // [+U]uNonSurrogate // [~U]uHex4Digits // [+U]u{CodePoint} - group_name: _ => /[A-Za-z0-9]+/, + group_name: _ => /[A-Za-z_][A-Za-z0-9_]*/, decimal_digits: _ => /\d+/, }, diff --git a/src/grammar.json b/src/grammar.json index 28ced0a..2ddcffb 100644 --- a/src/grammar.json +++ b/src/grammar.json @@ -743,7 +743,7 @@ }, "group_name": { "type": "PATTERN", - "value": "[A-Za-z0-9]+" + "value": "[A-Za-z_][A-Za-z0-9_]*" }, "decimal_digits": { "type": "PATTERN", diff --git a/src/parser.c b/src/parser.c index 8aea575..f9d660d 100644 --- a/src/parser.c +++ b/src/parser.c @@ -683,8 +683,9 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { if (lookahead == '=') ADVANCE(36); if (lookahead == '>') ADVANCE(54); if (lookahead == '}') ADVANCE(61); - if (('0' <= lookahead && lookahead <= '9') || - ('A' <= lookahead && lookahead <= 'Z') || + if (('0' <= lookahead && lookahead <= '9')) ADVANCE(75); + if (('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || ('a' <= lookahead && lookahead <= 'z')) ADVANCE(74); END_STATE(); case 5: @@ -704,7 +705,6 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { case 8: if (lookahead == '\n') SKIP(8); if (lookahead == '\r') SKIP(7); - if (('0' <= lookahead && lookahead <= '9')) ADVANCE(75); if (('A' <= lookahead && lookahead <= 'Z') || ('a' <= lookahead && lookahead <= 'z')) ADVANCE(46); END_STATE(); @@ -1062,6 +1062,7 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { ACCEPT_TOKEN(sym_group_name); if (('0' <= lookahead && lookahead <= '9') || ('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || ('a' <= lookahead && lookahead <= 'z')) ADVANCE(74); END_STATE(); case 75: @@ -1150,9 +1151,9 @@ static const TSLexMode ts_lex_modes[STATE_COUNT] = { [73] = {.lex_state = 0}, [74] = {.lex_state = 4}, [75] = {.lex_state = 4}, - [76] = {.lex_state = 8}, + [76] = {.lex_state = 4}, [77] = {.lex_state = 0}, - [78] = {.lex_state = 8}, + [78] = {.lex_state = 4}, [79] = {.lex_state = 0}, [80] = {.lex_state = 0}, [81] = {.lex_state = 8}, diff --git a/test/corpus/main.txt b/test/corpus/main.txt index 55e72a2..e2e5d09 100644 --- a/test/corpus/main.txt +++ b/test/corpus/main.txt @@ -452,7 +452,7 @@ hello (.*) ================================================================================ named capturing groups ================================================================================ -(?.*) +(?.*) -------------------------------------------------------------------------------- (pattern @@ -467,7 +467,7 @@ named capturing groups ================================================================================ named capturing groups - backreferences ================================================================================ -(?.*)\kworld +(?.*)\kthe_world -------------------------------------------------------------------------------- (pattern