From 36f9d6e0fd71eabd00933977b9e95fc53982f9f9 Mon Sep 17 00:00:00 2001 From: hperl <34397+hperl@users.noreply.github.com> Date: Thu, 29 Sep 2022 14:07:42 +0200 Subject: [PATCH] fix: properly lex imports in OPL --- .../TestLexer-suite=snapshots-import_statement.json | 13 +++++++++++++ internal/schema/lexer.go | 2 +- internal/schema/lexer_test.go | 2 +- internal/schema/parser_test.go | 2 ++ 4 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 internal/schema/.snapshots/TestLexer-suite=snapshots-import_statement.json 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..76172c712 100644 --- a/internal/schema/lexer.go +++ b/internal/schema/lexer.go @@ -307,7 +307,7 @@ func lexBlockComment(l *lexer) stateFn { func lexStringLiteral(l *lexer) stateFn { r := l.next() l.ignore() - l.acceptRun(digits + letters) + l.acceptRun(digits + letters + "@/-") if l.peek() != r { return l.errorf("unclosed string literal") } diff --git a/internal/schema/lexer_test.go b/internal/schema/lexer_test.go index f9955986b..60087dc54 100644 --- a/internal/schema/lexer_test.go +++ b/internal/schema/lexer_test.go @@ -15,6 +15,7 @@ var lexingErrorTestCases = []struct{ name, input string }{ 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 +118,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[]