Skip to content

Commit 1517cff

Browse files
committed
Factor out scan_template_chars
1 parent 6aac031 commit 1517cff

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

common/scanner.h

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,27 @@ enum TokenType {
1010

1111
static void advance(TSLexer *lexer) { lexer->advance(lexer, false); }
1212

13+
static bool scan_template_chars(TSLexer *lexer) {
14+
lexer->result_symbol = TEMPLATE_CHARS;
15+
for (bool has_content = false;; has_content = true) {
16+
lexer->mark_end(lexer);
17+
switch (lexer->lookahead) {
18+
case '`':
19+
return has_content;
20+
case '\0':
21+
return false;
22+
case '$':
23+
advance(lexer);
24+
if (lexer->lookahead == '{') return has_content;
25+
break;
26+
case '\\':
27+
return has_content;
28+
default:
29+
advance(lexer);
30+
}
31+
}
32+
}
33+
1334
static bool scan_whitespace_and_comments(TSLexer *lexer) {
1435
for (;;) {
1536
while (iswspace(lexer->lookahead)) {
@@ -49,26 +70,7 @@ static bool scan_whitespace_and_comments(TSLexer *lexer) {
4970
static inline bool external_scanner_scan(void *payload, TSLexer *lexer, const bool *valid_symbols) {
5071
if (valid_symbols[TEMPLATE_CHARS]) {
5172
if (valid_symbols[AUTOMATIC_SEMICOLON]) return false;
52-
lexer->result_symbol = TEMPLATE_CHARS;
53-
for (bool notfirst = false;; notfirst = true) {
54-
lexer->mark_end(lexer);
55-
switch (lexer->lookahead) {
56-
case '`':
57-
return notfirst;
58-
case '\0':
59-
return false;
60-
case '$':
61-
advance(lexer);
62-
if (lexer->lookahead == '{') return notfirst;
63-
break;
64-
case '\\':
65-
advance(lexer);
66-
advance(lexer);
67-
break;
68-
default:
69-
advance(lexer);
70-
}
71-
}
73+
return scan_template_chars(lexer);
7274
} else if (
7375
valid_symbols[AUTOMATIC_SEMICOLON] ||
7476
valid_symbols[FUNCTION_SIGNATURE_AUTOMATIC_SEMICOLON]

0 commit comments

Comments
 (0)