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 {
306306 private mutating func lexBlockComment( ) throws -> TokenKind {
307307 var level = 1
308308 while true {
309- switch try cursor. next ( ) {
309+ guard let char = try cursor. next ( ) else {
310+ throw cursor. unexpectedEof ( )
311+ }
312+ switch char {
310313 case " ( " :
311314 if try cursor. peek ( ) == " ; " {
312315 // Nested comment block
Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ class LexerTests: XCTestCase {
2525 }
2626
2727 func testLexComment( ) {
28+ XCTAssertEqual ( try collectToken ( " (; foo ;) " ) , [ . blockComment] )
2829 try XCTAssertEqual (
2930 collectToken (
3031 """
@@ -40,6 +41,12 @@ class LexerTests: XCTestCase {
4041
4142 }
4243
44+ func testLexBrokenComment( ) {
45+ XCTAssertThrowsError ( try collectToken ( " (;) " ) )
46+ XCTAssertThrowsError ( try collectToken ( " (; foo ) " ) )
47+ XCTAssertThrowsError ( try collectToken ( " ;) " ) )
48+ }
49+
4350 func testLexIdAndString( ) throws {
4451 try XCTAssertEqual ( collectToken ( " $foo " ) , [ . id] )
4552 try XCTAssertEqual ( collectToken ( " \" foo \" " ) , [ . string( Array ( " foo " . utf8) ) ] )
You can’t perform that action at this time.
0 commit comments