Skip to content

Commit a27bfd2

Browse files
committed
multi line comments
1 parent a06648e commit a27bfd2

2 files changed

Lines changed: 33 additions & 7 deletions

File tree

Sources/Compiler/Parse/Lexer.swift

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ struct Lexer {
9696

9797
switch (current, peek) {
9898
case ("*", "/"): return consumeDouble(of: .starForwardSlash)
99-
case ("/", "*"): return consumeDouble(of: .forwardSlashStar)
10099
case ("<", "<"): return consumeDouble(of: .shiftLeft)
101100
case ("<", "="): return consumeDouble(of: .lte)
102101
case (">", ">"): return consumeDouble(of: .shiftRight)
@@ -105,6 +104,9 @@ struct Lexer {
105104
case ("-", "-"):
106105
skipSingleLineComment()
107106
return next()
107+
case ("/", "*"):
108+
skipMultiLineComment()
109+
return next()
108110
case ("=", "="): return consumeDouble(of: .doubleEqual)
109111
case ("!", "="): return consumeDouble(of: .notEqual)
110112
case ("<", ">"): return consumeDouble(of: .notEqual2)
@@ -407,6 +409,7 @@ struct Lexer {
407409
return double
408410
}
409411

412+
/// Will skip a single line comment like "-- The comment"
410413
private mutating func skipSingleLineComment() {
411414
advance()
412415
advance()
@@ -416,6 +419,23 @@ struct Lexer {
416419
}
417420
}
418421

422+
/// Will skip a multi line comment like "/* The comment */"
423+
private mutating func skipMultiLineComment() {
424+
advance()
425+
advance()
426+
427+
while let current {
428+
// Hit end of comment
429+
if current == "*", peek == "/" {
430+
advance()
431+
advance()
432+
return
433+
}
434+
435+
advance()
436+
}
437+
}
438+
419439
private func location(
420440
from start: Start,
421441
to upperBound: Substring.Index

Tests/CompilerTests/Compiler/CompileTableOrSubqueries.sql

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
-- TableOrSubquery seems to be the trickiest part of the AST
2-
-- and want to have lots of tests validating it matches SQLite
3-
-- even for the weird use cases.
1+
/*
2+
TableOrSubquery seems to be the trickiest part of the AST
3+
and want to have lots of tests validating it matches SQLite
4+
even for the weird use cases.
45
5-
-- Each test has a "SQLite Output" above it to show exact what SQLite
6-
-- returns when run locally as a sanity check.
6+
Each test has a "SQLite Output" above it to show exact what SQLite
7+
returns when run locally as a sanity check.
78
8-
-- https://www.sqlite.org/syntax/table-or-subquery.html
9+
https://www.sqlite.org/syntax/table-or-subquery.html
10+
*/
911

1012
CREATE TABLE foo (bar INTEGER);
1113
CREATE TABLE baz (qux INTEGER);
@@ -129,3 +131,7 @@ SELECT * FROM foo AS quux CROSS JOIN baz;
129131
-- CHECK: TABLES
130132
-- CHECK: foo
131133
SELECT quux FROM ((SELECT bar AS quux FROM foo));
134+
135+
/*
136+
Comment at the end
137+
*/

0 commit comments

Comments
 (0)