diff --git a/src/scanner.c b/src/scanner.c index caed63a..0324364 100644 --- a/src/scanner.c +++ b/src/scanner.c @@ -224,6 +224,16 @@ static bool scan_multiline_comment(TSLexer *lexer) { } break; case '\0': + // Accept unterminated block comments at EOF rather than rejecting them. + // This matches JetBrains PSI behavior which recognizes unclosed /* as a + // BLOCK_COMMENT token (plus an error element). Without this, the scanner + // returns false and tree-sitter tries to parse the comment delimiters + // as operators/expressions. + if (lexer->eof(lexer)) { + lexer->result_symbol = MULTILINE_COMMENT; + lexer->mark_end(lexer); + return true; + } return false; default: advance(lexer); diff --git a/test/corpus/jetbrains/BlockCommentAtBeginningOfFile1.txt b/test/corpus/jetbrains/BlockCommentAtBeginningOfFile1.txt new file mode 100644 index 0000000..01b300f --- /dev/null +++ b/test/corpus/jetbrains/BlockCommentAtBeginningOfFile1.txt @@ -0,0 +1,12 @@ +================== +BlockCommentAtBeginningOfFile1 +================== + +// COMPILATION_ERRORS + +/* +--- + +(source_file + (line_comment) + (multiline_comment)) diff --git a/test/corpus/jetbrains/BlockCommentAtBeginningOfFile2.txt b/test/corpus/jetbrains/BlockCommentAtBeginningOfFile2.txt new file mode 100644 index 0000000..3e8c6a1 --- /dev/null +++ b/test/corpus/jetbrains/BlockCommentAtBeginningOfFile2.txt @@ -0,0 +1,13 @@ +================== +BlockCommentAtBeginningOfFile2 +================== + +// COMPILATION_ERRORS + +/* +/* +--- + +(source_file + (line_comment) + (multiline_comment)) diff --git a/test/corpus/jetbrains/BlockCommentAtBeginningOfFile3.txt b/test/corpus/jetbrains/BlockCommentAtBeginningOfFile3.txt new file mode 100644 index 0000000..5f58f03 --- /dev/null +++ b/test/corpus/jetbrains/BlockCommentAtBeginningOfFile3.txt @@ -0,0 +1,14 @@ +================== +BlockCommentAtBeginningOfFile3 +================== + +// COMPILATION_ERRORS + +/* + +fooo +--- + +(source_file + (line_comment) + (multiline_comment)) diff --git a/test/corpus/jetbrains/BlockCommentAtBeginningOfFile4.txt b/test/corpus/jetbrains/BlockCommentAtBeginningOfFile4.txt new file mode 100644 index 0000000..5bea7b5 --- /dev/null +++ b/test/corpus/jetbrains/BlockCommentAtBeginningOfFile4.txt @@ -0,0 +1,16 @@ +================== +BlockCommentAtBeginningOfFile4 +================== + +// COMPILATION_ERRORS + +/* + +/*foo*/ + +asdfas +--- + +(source_file + (line_comment) + (multiline_comment)) diff --git a/tools/cross-validation/excluded.txt b/tools/cross-validation/excluded.txt index aa7d8b0..6980b3a 100644 --- a/tools/cross-validation/excluded.txt +++ b/tools/cross-validation/excluded.txt @@ -20,13 +20,9 @@ # 3. Run: npm test (to verify the new corpus test passes) # ============================================================================= -# MISMATCH: Grammar produces wrong AST structure (26 files) +# MISMATCH: Grammar produces wrong AST structure (24 files) # ============================================================================= -# --- unterminated_block_comment (tree-sitter limitation) --- -BlockCommentAtBeginningOfFile3 -BlockCommentAtBeginningOfFile4 - # --- duplicate_accessor (error recovery difference) --- DuplicateAccessor @@ -88,8 +84,6 @@ AbsentInnerType AnnotatedIntersections AssertNotNull BackslashInString -BlockCommentAtBeginningOfFile1 -BlockCommentAtBeginningOfFile2 CallsInWhen CollectionLiterals CommentsBinding