Skip to content

Commit

Permalink
feat: support semicolons in types (#1151)
Browse files Browse the repository at this point in the history
fixes #1135
  • Loading branch information
hperl authored Nov 30, 2022
1 parent 85e1182 commit a06eda7
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 16 deletions.
2 changes: 1 addition & 1 deletion internal/schema/itemtype_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 13 additions & 11 deletions internal/schema/lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,18 @@ const (
itemKeywordCtx

// operators
itemOperatorAnd // "&&"
itemOperatorOr // "||"
itemOperatorNot // "!"
itemOperatorAssign // "="
itemOperatorArrow // "=>"
itemOperatorDot // "."
itemOperatorColon // ":"
itemOperatorComma // ","
itemOperatorSemicolon // ";"
itemTypeUnion // "|"
itemOperatorAnd // "&&"
itemOperatorOr // "||"
itemOperatorNot // "!"
itemOperatorAssign // "="
itemOperatorArrow // "=>"
itemOperatorDot // "."
itemOperatorColon // ":"
itemOperatorComma // ","

// misc characters
itemSemicolon // ";"
itemTypeUnion // "|"

// brackets
itemParenLeft // "("
Expand Down Expand Up @@ -228,7 +230,7 @@ var oneRuneTokens = map[rune]itemType{
'>': itemAngledRight,
'=': itemOperatorAssign,
',': itemOperatorComma,
';': itemOperatorSemicolon,
';': itemSemicolon,
'|': itemTypeUnion,
'!': itemOperatorNot,
}
Expand Down
5 changes: 4 additions & 1 deletion internal/schema/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func (p *parser) parseClass() {
p.parseRelated()
case item.Val == "permits":
p.parsePermits()
case item.Typ == itemOperatorSemicolon:
case item.Typ == itemSemicolon:
continue
default:
p.addFatal(item, "expected 'permits' or 'related', got %q", item.Val)
Expand All @@ -194,6 +194,9 @@ func (p *parser) parseRelated() {
for !p.fatal {
switch item := p.next(); item.Typ {

case itemSemicolon:
continue

case itemBraceRight:
return

Expand Down
6 changes: 3 additions & 3 deletions internal/schema/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ var parserTestCases = []struct {
class User implements Namespace {
related: {
manager: User[]
manager: User[];
}
}
class Group implements Namespace {
related: {
members: (User | Group)[]
}
members: (User | Group)[];
};
}
class Folder implements Namespace {
Expand Down

0 comments on commit a06eda7

Please sign in to comment.