more real world exampls; fix scanner when scanning empty character in lexer

This commit is contained in:
mhoffm
2021-06-21 19:40:27 +02:00
parent 3bc4153bc2
commit a7f23cc579
2020 changed files with 64141 additions and 10630 deletions

View File

@@ -25,6 +25,10 @@
{
"type": "SYMBOL",
"name": "block"
},
{
"type": "SYMBOL",
"name": "object"
}
]
}
@@ -587,8 +591,17 @@
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "get_attr"
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "get_attr"
},
{
"type": "SYMBOL",
"name": "index"
}
]
}
}
]

View File

@@ -10,6 +10,10 @@
{
"type": "get_attr",
"named": true
},
{
"type": "index",
"named": true
}
]
}
@@ -126,6 +130,10 @@
{
"type": "block",
"named": true
},
{
"type": "object",
"named": true
}
]
}

21222
src/parser.c

File diff suppressed because it is too large Load Diff

View File

@@ -90,9 +90,10 @@ void scanner_exit_quoted_context(Scanner *scanner) {
bool scanner_scan(Scanner *scanner, TSLexer *lexer, const bool *valid_symbols) {
// print_debug_info(scanner, lexer, valid_symbols);
while (iswspace(lexer->lookahead) && !scanner->in_quoted_context) {
while (iswspace(lexer->lookahead)) {
skip(lexer);
}
if (lexer->lookahead == '\0') return false;
// manage quoted context
if (
@@ -134,7 +135,11 @@ bool scanner_scan(Scanner *scanner, TSLexer *lexer, const bool *valid_symbols) {
return accept_inplace(lexer, TEMPLATE_LITERAL_CHUNK);
}
}
if (valid_symbols[TEMPLATE_INTERPOLATION_END] && lexer->lookahead == '}') {
if (
valid_symbols[TEMPLATE_INTERPOLATION_END] &&
lexer->lookahead == '}' &&
scanner->in_template_interpolation
) {
scanner_exit_interpolation_context(scanner);
return accept_and_advance(lexer, TEMPLATE_INTERPOLATION_END);
}
@@ -144,6 +149,7 @@ bool scanner_scan(Scanner *scanner, TSLexer *lexer, const bool *valid_symbols) {
// handle template literal chunks in quoted contexts
//
// they may not contain newlines and may contain escape sequences
if (valid_symbols[TEMPLATE_LITERAL_CHUNK] && scanner->in_quoted_context) {
switch (lexer->lookahead) {
case '\\':
@@ -183,7 +189,6 @@ bool scanner_scan(Scanner *scanner, TSLexer *lexer, const bool *valid_symbols) {
advance(lexer);
if (lexer->lookahead == '{') {
// unescaped template interpolation
skip(lexer);
return false;
}
if (lexer->lookahead == '$') {
@@ -203,7 +208,6 @@ bool scanner_scan(Scanner *scanner, TSLexer *lexer, const bool *valid_symbols) {
}
// probably not handled by the external scanner
return false;
}