update regex

This commit is contained in:
JellyApple102 2021-09-29 01:35:43 -04:00
parent 00505def4e
commit 3f9d50fe9b
3 changed files with 191 additions and 82 deletions

View File

@ -32,9 +32,9 @@ module.exports = grammar({
declaration: $ => /[A-Z_0-9]+/, declaration: $ => /[A-Z_0-9]+/,
number: $ => token(prec(1, /-?[0-9]+/)), number: $ => /-?[0-9]+/,
reference: $ => /!?[A-Z_0-9]+/, reference: $ => /(?:VOLUME_mB)|(?:!?[0-9]*[A-Z][A-Z_0-9]*)/,
string: $ => /[A-Za-z \-,.'/\\=0-9]+/, string: $ => /[A-Za-z \-,.'/\\=0-9]+/,

View File

@ -105,19 +105,12 @@
"value": "[A-Z_0-9]+" "value": "[A-Z_0-9]+"
}, },
"number": { "number": {
"type": "TOKEN", "type": "PATTERN",
"content": { "value": "-?[0-9]+"
"type": "PREC",
"value": 1,
"content": {
"type": "PATTERN",
"value": "-?[0-9]+"
}
}
}, },
"reference": { "reference": {
"type": "PATTERN", "type": "PATTERN",
"value": "!?[A-Z_0-9]+" "value": "(?:VOLUME_mB)|(?:!?[0-9]*[A-Z][A-Z_0-9]*)"
}, },
"string": { "string": {
"type": "PATTERN", "type": "PATTERN",

View File

@ -152,126 +152,243 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) {
eof = lexer->eof(lexer); eof = lexer->eof(lexer);
switch (state) { switch (state) {
case 0: case 0:
if (eof) ADVANCE(6); if (eof) ADVANCE(7);
if (lookahead == '!') ADVANCE(4); if (lookahead == '-') ADVANCE(4);
if (lookahead == '-') ADVANCE(3); if (lookahead == ':') ADVANCE(28);
if (lookahead == ':') ADVANCE(16); if (lookahead == '[') ADVANCE(8);
if (lookahead == '[') ADVANCE(7); if (lookahead == ']') ADVANCE(9);
if (lookahead == ']') ADVANCE(8);
if (lookahead == '\t' || if (lookahead == '\t' ||
lookahead == '\n' || lookahead == '\n' ||
lookahead == '\r' || lookahead == '\r' ||
lookahead == ' ') SKIP(0) lookahead == ' ') SKIP(0)
if (('0' <= lookahead && lookahead <= '9')) ADVANCE(10); if (('0' <= lookahead && lookahead <= '9')) ADVANCE(10);
if (('A' <= lookahead && lookahead <= 'Z') || if (('A' <= lookahead && lookahead <= 'Z') ||
lookahead == '_') ADVANCE(9); lookahead == '_') ADVANCE(11);
END_STATE(); END_STATE();
case 1: case 1:
if (lookahead == ' ') ADVANCE(13); if (lookahead == ' ') ADVANCE(25);
if (lookahead == '!') ADVANCE(4); if (lookahead == '!') ADVANCE(5);
if (lookahead == '-') ADVANCE(14); if (lookahead == '-') ADVANCE(26);
if (lookahead == ':') ADVANCE(16); if (lookahead == ':') ADVANCE(28);
if (lookahead == ']') ADVANCE(8); if (lookahead == 'V') ADVANCE(19);
if (lookahead == '_') ADVANCE(12); if (lookahead == ']') ADVANCE(9);
if (lookahead == '\t' || if (lookahead == '\t' ||
lookahead == '\n' || lookahead == '\n' ||
lookahead == '\r') SKIP(1) lookahead == '\r') SKIP(1)
if (('0' <= lookahead && lookahead <= '9')) ADVANCE(10); if (('0' <= lookahead && lookahead <= '9')) ADVANCE(13);
if (('A' <= lookahead && lookahead <= 'Z')) ADVANCE(11); if (('A' <= lookahead && lookahead <= 'Z')) ADVANCE(21);
if (lookahead == '\'' || if (lookahead == '\'' ||
(',' <= lookahead && lookahead <= '/') || (',' <= lookahead && lookahead <= '/') ||
lookahead == '=' || lookahead == '=' ||
lookahead == '\\' || lookahead == '\\' ||
('a' <= lookahead && lookahead <= 'z')) ADVANCE(15); ('a' <= lookahead && lookahead <= 'z')) ADVANCE(27);
END_STATE(); END_STATE();
case 2: case 2:
if (lookahead == '\t' || if (lookahead == 'B') ADVANCE(15);
lookahead == '\n' ||
lookahead == '\r' ||
lookahead == ' ') SKIP(2)
if (('0' <= lookahead && lookahead <= '9') ||
('A' <= lookahead && lookahead <= 'Z') ||
lookahead == '_') ADVANCE(9);
END_STATE(); END_STATE();
case 3: case 3:
if (('0' <= lookahead && lookahead <= '9')) ADVANCE(10);
END_STATE();
case 4:
if (('0' <= lookahead && lookahead <= '9') ||
('A' <= lookahead && lookahead <= 'Z') ||
lookahead == '_') ADVANCE(12);
END_STATE();
case 5:
if (eof) ADVANCE(6);
if (lookahead == '[') ADVANCE(7);
if (lookahead == '\t' || if (lookahead == '\t' ||
lookahead == '\n' || lookahead == '\n' ||
lookahead == '\r' || lookahead == '\r' ||
lookahead == ' ') SKIP(5) lookahead == ' ') SKIP(3)
if (lookahead != 0 && if (('0' <= lookahead && lookahead <= '9') ||
lookahead != ']') ADVANCE(17); ('A' <= lookahead && lookahead <= 'Z') ||
lookahead == '_') ADVANCE(11);
END_STATE();
case 4:
if (('0' <= lookahead && lookahead <= '9')) ADVANCE(12);
END_STATE();
case 5:
if (('0' <= lookahead && lookahead <= '9')) ADVANCE(5);
if (('A' <= lookahead && lookahead <= 'Z')) ADVANCE(24);
END_STATE(); END_STATE();
case 6: case 6:
ACCEPT_TOKEN(ts_builtin_sym_end); if (eof) ADVANCE(7);
if (lookahead == '[') ADVANCE(8);
if (lookahead == '\t' ||
lookahead == '\n' ||
lookahead == '\r' ||
lookahead == ' ') SKIP(6)
if (lookahead != 0 &&
lookahead != ']') ADVANCE(29);
END_STATE(); END_STATE();
case 7: case 7:
ACCEPT_TOKEN(anon_sym_LBRACK); ACCEPT_TOKEN(ts_builtin_sym_end);
END_STATE(); END_STATE();
case 8: case 8:
ACCEPT_TOKEN(anon_sym_RBRACK); ACCEPT_TOKEN(anon_sym_LBRACK);
END_STATE(); END_STATE();
case 9: case 9:
ACCEPT_TOKEN(anon_sym_RBRACK);
END_STATE();
case 10:
ACCEPT_TOKEN(sym_declaration);
if (('0' <= lookahead && lookahead <= '9')) ADVANCE(10);
if (('A' <= lookahead && lookahead <= 'Z') ||
lookahead == '_') ADVANCE(11);
END_STATE();
case 11:
ACCEPT_TOKEN(sym_declaration); ACCEPT_TOKEN(sym_declaration);
if (('0' <= lookahead && lookahead <= '9') || if (('0' <= lookahead && lookahead <= '9') ||
('A' <= lookahead && lookahead <= 'Z') || ('A' <= lookahead && lookahead <= 'Z') ||
lookahead == '_') ADVANCE(9); lookahead == '_') ADVANCE(11);
END_STATE(); END_STATE();
case 10: case 12:
ACCEPT_TOKEN(sym_number); ACCEPT_TOKEN(sym_number);
if (('0' <= lookahead && lookahead <= '9')) ADVANCE(10); if (('0' <= lookahead && lookahead <= '9')) ADVANCE(12);
END_STATE(); END_STATE();
case 11: case 13:
ACCEPT_TOKEN(sym_reference); ACCEPT_TOKEN(sym_number);
if (lookahead == '_') ADVANCE(12); if (('0' <= lookahead && lookahead <= '9')) ADVANCE(13);
if (('A' <= lookahead && lookahead <= 'Z')) ADVANCE(21);
if (lookahead == ' ' || if (lookahead == ' ' ||
lookahead == '\'' || lookahead == '\'' ||
(',' <= lookahead && lookahead <= '/') || (',' <= lookahead && lookahead <= '/') ||
lookahead == '=' || lookahead == '=' ||
lookahead == '\\' || lookahead == '\\' ||
('a' <= lookahead && lookahead <= 'z')) ADVANCE(15); ('a' <= lookahead && lookahead <= 'z')) ADVANCE(27);
if (('0' <= lookahead && lookahead <= '9') ||
('A' <= lookahead && lookahead <= 'Z')) ADVANCE(11);
END_STATE(); END_STATE();
case 12: case 14:
ACCEPT_TOKEN(sym_number);
if (('0' <= lookahead && lookahead <= '9')) ADVANCE(14);
if (lookahead == ' ' ||
lookahead == '\'' ||
(',' <= lookahead && lookahead <= '/') ||
lookahead == '=' ||
('A' <= lookahead && lookahead <= 'Z') ||
lookahead == '\\' ||
('a' <= lookahead && lookahead <= 'z')) ADVANCE(27);
END_STATE();
case 15:
ACCEPT_TOKEN(sym_reference);
END_STATE();
case 16:
ACCEPT_TOKEN(sym_reference);
if (lookahead == 'E') ADVANCE(22);
if (lookahead == '_') ADVANCE(24);
if (lookahead == ' ' ||
lookahead == '\'' ||
(',' <= lookahead && lookahead <= '/') ||
lookahead == '=' ||
lookahead == '\\' ||
('a' <= lookahead && lookahead <= 'z')) ADVANCE(27);
if (('0' <= lookahead && lookahead <= '9') ||
('A' <= lookahead && lookahead <= 'Z')) ADVANCE(21);
END_STATE();
case 17:
ACCEPT_TOKEN(sym_reference);
if (lookahead == 'L') ADVANCE(20);
if (lookahead == '_') ADVANCE(24);
if (lookahead == ' ' ||
lookahead == '\'' ||
(',' <= lookahead && lookahead <= '/') ||
lookahead == '=' ||
lookahead == '\\' ||
('a' <= lookahead && lookahead <= 'z')) ADVANCE(27);
if (('0' <= lookahead && lookahead <= '9') ||
('A' <= lookahead && lookahead <= 'Z')) ADVANCE(21);
END_STATE();
case 18:
ACCEPT_TOKEN(sym_reference);
if (lookahead == 'M') ADVANCE(16);
if (lookahead == '_') ADVANCE(24);
if (lookahead == ' ' ||
lookahead == '\'' ||
(',' <= lookahead && lookahead <= '/') ||
lookahead == '=' ||
lookahead == '\\' ||
('a' <= lookahead && lookahead <= 'z')) ADVANCE(27);
if (('0' <= lookahead && lookahead <= '9') ||
('A' <= lookahead && lookahead <= 'Z')) ADVANCE(21);
END_STATE();
case 19:
ACCEPT_TOKEN(sym_reference);
if (lookahead == 'O') ADVANCE(17);
if (lookahead == '_') ADVANCE(24);
if (lookahead == ' ' ||
lookahead == '\'' ||
(',' <= lookahead && lookahead <= '/') ||
lookahead == '=' ||
lookahead == '\\' ||
('a' <= lookahead && lookahead <= 'z')) ADVANCE(27);
if (('0' <= lookahead && lookahead <= '9') ||
('A' <= lookahead && lookahead <= 'Z')) ADVANCE(21);
END_STATE();
case 20:
ACCEPT_TOKEN(sym_reference);
if (lookahead == 'U') ADVANCE(18);
if (lookahead == '_') ADVANCE(24);
if (lookahead == ' ' ||
lookahead == '\'' ||
(',' <= lookahead && lookahead <= '/') ||
lookahead == '=' ||
lookahead == '\\' ||
('a' <= lookahead && lookahead <= 'z')) ADVANCE(27);
if (('0' <= lookahead && lookahead <= '9') ||
('A' <= lookahead && lookahead <= 'Z')) ADVANCE(21);
END_STATE();
case 21:
ACCEPT_TOKEN(sym_reference);
if (lookahead == '_') ADVANCE(24);
if (lookahead == ' ' ||
lookahead == '\'' ||
(',' <= lookahead && lookahead <= '/') ||
lookahead == '=' ||
lookahead == '\\' ||
('a' <= lookahead && lookahead <= 'z')) ADVANCE(27);
if (('0' <= lookahead && lookahead <= '9') ||
('A' <= lookahead && lookahead <= 'Z')) ADVANCE(21);
END_STATE();
case 22:
ACCEPT_TOKEN(sym_reference);
if (lookahead == '_') ADVANCE(23);
if (lookahead == ' ' ||
lookahead == '\'' ||
(',' <= lookahead && lookahead <= '/') ||
lookahead == '=' ||
lookahead == '\\' ||
('a' <= lookahead && lookahead <= 'z')) ADVANCE(27);
if (('0' <= lookahead && lookahead <= '9') ||
('A' <= lookahead && lookahead <= 'Z')) ADVANCE(21);
END_STATE();
case 23:
ACCEPT_TOKEN(sym_reference);
if (lookahead == 'm') ADVANCE(2);
if (('0' <= lookahead && lookahead <= '9') ||
('A' <= lookahead && lookahead <= 'Z') ||
lookahead == '_') ADVANCE(24);
END_STATE();
case 24:
ACCEPT_TOKEN(sym_reference); ACCEPT_TOKEN(sym_reference);
if (('0' <= lookahead && lookahead <= '9') || if (('0' <= lookahead && lookahead <= '9') ||
('A' <= lookahead && lookahead <= 'Z') || ('A' <= lookahead && lookahead <= 'Z') ||
lookahead == '_') ADVANCE(12); lookahead == '_') ADVANCE(24);
END_STATE(); END_STATE();
case 13: case 25:
ACCEPT_TOKEN(sym_string); ACCEPT_TOKEN(sym_string);
if (lookahead == ' ') ADVANCE(13); if (lookahead == ' ') ADVANCE(25);
if (lookahead == '-') ADVANCE(14); if (lookahead == '-') ADVANCE(26);
if (('0' <= lookahead && lookahead <= '9')) ADVANCE(10); if (lookahead == 'V') ADVANCE(19);
if (('A' <= lookahead && lookahead <= 'Z')) ADVANCE(11); if (('0' <= lookahead && lookahead <= '9')) ADVANCE(13);
if (('A' <= lookahead && lookahead <= 'Z')) ADVANCE(21);
if (lookahead == '\'' || if (lookahead == '\'' ||
(',' <= lookahead && lookahead <= '/') || (',' <= lookahead && lookahead <= '/') ||
lookahead == '=' || lookahead == '=' ||
lookahead == '\\' || lookahead == '\\' ||
('a' <= lookahead && lookahead <= 'z')) ADVANCE(15); ('a' <= lookahead && lookahead <= 'z')) ADVANCE(27);
END_STATE(); END_STATE();
case 14: case 26:
ACCEPT_TOKEN(sym_string); ACCEPT_TOKEN(sym_string);
if (('0' <= lookahead && lookahead <= '9')) ADVANCE(10); if (('0' <= lookahead && lookahead <= '9')) ADVANCE(14);
if (lookahead == ' ' || if (lookahead == ' ' ||
lookahead == '\'' || lookahead == '\'' ||
(',' <= lookahead && lookahead <= '/') || (',' <= lookahead && lookahead <= '/') ||
lookahead == '=' || lookahead == '=' ||
('A' <= lookahead && lookahead <= 'Z') || ('A' <= lookahead && lookahead <= 'Z') ||
lookahead == '\\' || lookahead == '\\' ||
('a' <= lookahead && lookahead <= 'z')) ADVANCE(15); ('a' <= lookahead && lookahead <= 'z')) ADVANCE(27);
END_STATE(); END_STATE();
case 15: case 27:
ACCEPT_TOKEN(sym_string); ACCEPT_TOKEN(sym_string);
if (lookahead == ' ' || if (lookahead == ' ' ||
lookahead == '\'' || lookahead == '\'' ||
@ -279,12 +396,12 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) {
lookahead == '=' || lookahead == '=' ||
('A' <= lookahead && lookahead <= 'Z') || ('A' <= lookahead && lookahead <= 'Z') ||
lookahead == '\\' || lookahead == '\\' ||
('a' <= lookahead && lookahead <= 'z')) ADVANCE(15); ('a' <= lookahead && lookahead <= 'z')) ADVANCE(27);
END_STATE(); END_STATE();
case 16: case 28:
ACCEPT_TOKEN(sym_separator); ACCEPT_TOKEN(sym_separator);
END_STATE(); END_STATE();
case 17: case 29:
ACCEPT_TOKEN(sym_comment); ACCEPT_TOKEN(sym_comment);
if (lookahead != 0 && if (lookahead != 0 &&
lookahead != '\t' && lookahead != '\t' &&
@ -292,7 +409,7 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) {
lookahead != '\r' && lookahead != '\r' &&
lookahead != ' ' && lookahead != ' ' &&
lookahead != '[' && lookahead != '[' &&
lookahead != ']') ADVANCE(17); lookahead != ']') ADVANCE(29);
END_STATE(); END_STATE();
default: default:
return false; return false;
@ -301,18 +418,18 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) {
static const TSLexMode ts_lex_modes[STATE_COUNT] = { static const TSLexMode ts_lex_modes[STATE_COUNT] = {
[0] = {.lex_state = 0}, [0] = {.lex_state = 0},
[1] = {.lex_state = 5}, [1] = {.lex_state = 6},
[2] = {.lex_state = 1}, [2] = {.lex_state = 1},
[3] = {.lex_state = 5}, [3] = {.lex_state = 6},
[4] = {.lex_state = 5}, [4] = {.lex_state = 6},
[5] = {.lex_state = 1}, [5] = {.lex_state = 1},
[6] = {.lex_state = 1}, [6] = {.lex_state = 1},
[7] = {.lex_state = 1}, [7] = {.lex_state = 1},
[8] = {.lex_state = 1}, [8] = {.lex_state = 1},
[9] = {.lex_state = 1}, [9] = {.lex_state = 1},
[10] = {.lex_state = 1}, [10] = {.lex_state = 1},
[11] = {.lex_state = 5}, [11] = {.lex_state = 6},
[12] = {.lex_state = 2}, [12] = {.lex_state = 3},
[13] = {.lex_state = 0}, [13] = {.lex_state = 0},
[14] = {.lex_state = 0}, [14] = {.lex_state = 0},
}; };
@ -324,7 +441,6 @@ static const uint16_t ts_parse_table[LARGE_STATE_COUNT][SYMBOL_COUNT] = {
[anon_sym_RBRACK] = ACTIONS(1), [anon_sym_RBRACK] = ACTIONS(1),
[sym_declaration] = ACTIONS(1), [sym_declaration] = ACTIONS(1),
[sym_number] = ACTIONS(1), [sym_number] = ACTIONS(1),
[sym_reference] = ACTIONS(1),
[sym_separator] = ACTIONS(1), [sym_separator] = ACTIONS(1),
}, },
[1] = { [1] = {