File tree Expand file tree Collapse file tree 2 files changed +11
-1
lines changed Expand file tree Collapse file tree 2 files changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -306,7 +306,10 @@ struct Lexer {
306
306
private mutating func lexBlockComment( ) throws -> TokenKind {
307
307
var level = 1
308
308
while true {
309
- switch try cursor. next ( ) {
309
+ guard let char = try cursor. next ( ) else {
310
+ throw cursor. unexpectedEof ( )
311
+ }
312
+ switch char {
310
313
case " ( " :
311
314
if try cursor. peek ( ) == " ; " {
312
315
// Nested comment block
Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ class LexerTests: XCTestCase {
25
25
}
26
26
27
27
func testLexComment( ) {
28
+ XCTAssertEqual ( try collectToken ( " (; foo ;) " ) , [ . blockComment] )
28
29
try XCTAssertEqual (
29
30
collectToken (
30
31
"""
@@ -40,6 +41,12 @@ class LexerTests: XCTestCase {
40
41
41
42
}
42
43
44
+ func testLexBrokenComment( ) {
45
+ XCTAssertThrowsError ( try collectToken ( " (;) " ) )
46
+ XCTAssertThrowsError ( try collectToken ( " (; foo ) " ) )
47
+ XCTAssertThrowsError ( try collectToken ( " ;) " ) )
48
+ }
49
+
43
50
func testLexIdAndString( ) throws {
44
51
try XCTAssertEqual ( collectToken ( " $foo " ) , [ . id] )
45
52
try XCTAssertEqual ( collectToken ( " \" foo \" " ) , [ . string( Array ( " foo " . utf8) ) ] )
You can’t perform that action at this time.
0 commit comments