Skip to content

Commit

Permalink
fix: properly lex imports in OPL
Browse files Browse the repository at this point in the history
  • Loading branch information
hperl authored and zepatrik committed Sep 29, 2022
1 parent 3724528 commit f2ad058
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[
"'import'",
"{",
"'Foo'",
",",
"'Bar'",
",",
"'Baz'",
"}",
"'from'",
"'@ory/keto-...'",
"EOF"
]
2 changes: 1 addition & 1 deletion internal/schema/lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
2 changes: 1 addition & 1 deletion internal/schema/lexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -117,7 +118,6 @@ func TestLexer(t *testing.T) {
}
if item.Typ == itemEOF {
t.Fatal("reached EOF, but expected error")
break
}
}
l.next()
Expand Down
2 changes: 2 additions & 0 deletions internal/schema/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
Expand Down

0 comments on commit f2ad058

Please sign in to comment.