diff --git a/internal/schema/.snapshots/TestLexer-suite=snapshots-import_statement.json b/internal/schema/.snapshots/TestLexer-suite=snapshots-import_statement.json new file mode 100644 index 000000000..4d561cf29 --- /dev/null +++ b/internal/schema/.snapshots/TestLexer-suite=snapshots-import_statement.json @@ -0,0 +1,13 @@ +[ + "'import'", + "{", + "'Foo'", + ",", + "'Bar'", + ",", + "'Baz'", + "}", + "'from'", + "'@ory/keto-...'", + "EOF" +] diff --git a/internal/schema/lexer.go b/internal/schema/lexer.go index 3b55edcc5..afbb36169 100644 --- a/internal/schema/lexer.go +++ b/internal/schema/lexer.go @@ -307,9 +307,16 @@ func lexBlockComment(l *lexer) stateFn { func lexStringLiteral(l *lexer) stateFn { r := l.next() l.ignore() - l.acceptRun(digits + letters) - if l.peek() != r { - return l.errorf("unclosed string literal") + +loop: + for { + switch l.next() { + case eof: + return l.errorf("unclosed string literal") + case r: + l.backup() + break loop + } } l.emit(itemStringLiteral) l.next() diff --git a/internal/schema/lexer_test.go b/internal/schema/lexer_test.go index f9955986b..0ac5e7a43 100644 --- a/internal/schema/lexer_test.go +++ b/internal/schema/lexer_test.go @@ -11,10 +11,12 @@ var lexingErrorTestCases = []struct{ name, input string }{ {"open comment", "/*"}, {"open string literal", "'"}, {"non-token", "ΓΌ"}, + {"mixed quotes", `"invalid_literal'`}, } var lexableTestCases = []struct{ name, input string }{ {"empty", ""}, + {"import statement", "import { Foo, Bar, Baz } from '@ory/keto-namespace-types'"}, {"single class", ` class name implements Namespace { metadata = { @@ -117,7 +119,6 @@ func TestLexer(t *testing.T) { } if item.Typ == itemEOF { t.Fatal("reached EOF, but expected error") - break } } l.next() diff --git a/internal/schema/parser_test.go b/internal/schema/parser_test.go index 781d48edc..6e282aaf2 100644 --- a/internal/schema/parser_test.go +++ b/internal/schema/parser_test.go @@ -17,6 +17,8 @@ var parserTestCases = []struct { name, input string }{ {"full example", ` + import { Namespace, SubjectSet, FooBar, Anything } from '@ory/keto-namespace-types' + class User implements Namespace { related: { manager: User[]