improve operator lookahead
@@ -72,6 +72,10 @@ struct Scanner {
return c >= 'a' && c <= 'z';
}
+ bool is_alpha(char c) {
+ return is_upcase_char(c) || is_downcase_char(c);
+ }
+
bool is_sigil_char(char c) {
return memchr(&SIGIL_CHARS, c, sizeof(SIGIL_CHARS)) != NULL;
}
@@ -132,6 +136,18 @@ struct Scanner {
}
}
+ bool is_operator_next(TSLexer *lexer) {
+ if (memchr(&OPERATORS, lexer->lookahead, sizeof(OPERATORS)) != NULL) {
+ if (lexer->lookahead == ':') {
+ advance(lexer);
+ return !is_alpha(lexer->lookahead);
+ }
+
+ return true;
+ }
+ return false;
+ }
+
bool scan_sigil_start(TSLexer *lexer) {
bool quote = false;
bool allows_interpolation = false;
@@ -296,11 +312,10 @@ struct Scanner {
is_newline(lexer->lookahead)) {
skip(lexer);
while (is_whitespace(lexer->lookahead) || is_newline(lexer->lookahead)) skip(lexer);
- if (memchr(&OPERATORS, lexer->lookahead, sizeof(OPERATORS)) != NULL) {
- skip(lexer);
+ lexer->mark_end(lexer);
+ if (is_operator_next(lexer)) {
return false;
} else {
- lexer->mark_end(lexer);
lexer->result_symbol = LINE_BREAK;
return true;
}
