@@ -36,7 +36,7 @@ static bool scan_template_chars(TSLexer *lexer) {
36
36
}
37
37
}
38
38
39
- static bool scan_whitespace_and_comments (TSLexer * lexer ) {
39
+ static bool scan_whitespace_and_comments (TSLexer * lexer , bool * scanned_comment ) {
40
40
for (;;) {
41
41
while (iswspace (lexer -> lookahead )) {
42
42
skip (lexer );
@@ -50,6 +50,7 @@ static bool scan_whitespace_and_comments(TSLexer *lexer) {
50
50
while (lexer -> lookahead != 0 && lexer -> lookahead != '\n' ) {
51
51
skip (lexer );
52
52
}
53
+ * scanned_comment = true;
53
54
} else if (lexer -> lookahead == '*' ) {
54
55
skip (lexer );
55
56
while (lexer -> lookahead != 0 ) {
@@ -72,7 +73,7 @@ static bool scan_whitespace_and_comments(TSLexer *lexer) {
72
73
}
73
74
}
74
75
75
- static bool scan_automatic_semicolon (TSLexer * lexer , const bool * valid_symbols ) {
76
+ static bool scan_automatic_semicolon (TSLexer * lexer , const bool * valid_symbols , bool * scanned_comment ) {
76
77
lexer -> result_symbol = AUTOMATIC_SEMICOLON ;
77
78
lexer -> mark_end (lexer );
78
79
@@ -96,7 +97,7 @@ static bool scan_automatic_semicolon(TSLexer *lexer, const bool *valid_symbols){
96
97
97
98
skip (lexer );
98
99
99
- if (!scan_whitespace_and_comments (lexer )) return false;
100
+ if (!scan_whitespace_and_comments (lexer , scanned_comment )) return false;
100
101
101
102
switch (lexer -> lookahead ) {
102
103
case ',' :
@@ -198,6 +199,44 @@ static bool scan_ternary_qmark(TSLexer *lexer) {
198
199
return false;
199
200
}
200
201
202
+ static bool scan_closing_comment (TSLexer * lexer ) {
203
+ while (iswspace (lexer -> lookahead ) || lexer -> lookahead == 0x2028 || lexer -> lookahead == 0x2029 ) {
204
+ skip (lexer );
205
+ }
206
+
207
+ const char * comment_start = "<!--" ;
208
+ const char * comment_end = "-->" ;
209
+
210
+ if (lexer -> lookahead == '<' ) {
211
+ for (unsigned i = 0 ; i < 4 ; i ++ ) {
212
+ if (lexer -> lookahead != comment_start [i ]) {
213
+ return false;
214
+ }
215
+ advance (lexer );
216
+ }
217
+ } else if (lexer -> lookahead == '-' ) {
218
+ for (unsigned i = 0 ; i < 3 ; i ++ ) {
219
+ if (lexer -> lookahead != comment_end [i ]) {
220
+ return false;
221
+ }
222
+ advance (lexer );
223
+ }
224
+ } else {
225
+ return false;
226
+ }
227
+
228
+ while (lexer -> lookahead != 0 && lexer -> lookahead != '\n' && lexer -> lookahead != 0x2028 &&
229
+ lexer -> lookahead != 0x2029 ) {
230
+ advance (lexer );
231
+ }
232
+
233
+ lexer -> result_symbol = HTML_COMMENT ;
234
+ lexer -> mark_end (lexer );
235
+
236
+ return true;
237
+ }
238
+
239
+
201
240
static inline bool external_scanner_scan (void * payload , TSLexer * lexer , const bool * valid_symbols ) {
202
241
if (valid_symbols [TEMPLATE_CHARS ]) {
203
242
if (valid_symbols [AUTOMATIC_SEMICOLON ]) return false;
@@ -206,15 +245,20 @@ static inline bool external_scanner_scan(void *payload, TSLexer *lexer, const bo
206
245
valid_symbols [AUTOMATIC_SEMICOLON ] ||
207
246
valid_symbols [FUNCTION_SIGNATURE_AUTOMATIC_SEMICOLON ]
208
247
) {
209
- bool ret = scan_automatic_semicolon (lexer , valid_symbols );
210
- if (!ret && valid_symbols [TERNARY_QMARK ] && lexer -> lookahead == '?' )
248
+ bool scanned_comment = false;
249
+ bool ret = scan_automatic_semicolon (lexer , valid_symbols , & scanned_comment );
250
+ if (!ret && !scanned_comment && valid_symbols [TERNARY_QMARK ] && lexer -> lookahead == '?' )
211
251
return scan_ternary_qmark (lexer );
212
252
return ret ;
213
253
}
214
254
if (valid_symbols [TERNARY_QMARK ]) {
215
255
return scan_ternary_qmark (lexer );
216
256
}
217
257
258
+ if (valid_symbols [HTML_COMMENT ] && !valid_symbols [LOGICAL_OR ] && !valid_symbols [ESCAPE_SEQUENCE ]) {
259
+ return scan_closing_comment (lexer );
260
+ }
261
+
218
262
return false;
219
263
220
264
}
0 commit comments