Skip to content

Commit

Permalink
fix: allow comments in more places in OPL (#1117)
Browse files Browse the repository at this point in the history
Fixes #1116
  • Loading branch information
hperl committed Nov 8, 2022
1 parent 305f10b commit 5f89fcf
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
7 changes: 7 additions & 0 deletions internal/schema/lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,13 @@ func (l *lexer) nextItem() item {
}
}

// nextNonCommentItem returns the next item from the input that is not a comment.
func (l *lexer) nextNonCommentItem() (item item) {
for item = l.nextItem(); item.Typ == itemComment; item = l.nextItem() {
}
return
}

// scanIdentifier scans an identifier.
func (l *lexer) scanIdentifier() bool {
if !l.accept(letters) {
Expand Down
6 changes: 2 additions & 4 deletions internal/schema/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,14 @@ func (p *parser) next() (item item) {
item = *p.lookahead
p.lookahead = nil
} else {
// Get next non-comment token.
for item = p.lexer.nextItem(); item.Typ == itemComment; item = p.lexer.nextItem() {
}
return p.lexer.nextNonCommentItem()
}
return
}

func (p *parser) peek() item {
if p.lookahead == nil {
i := p.lexer.nextItem()
i := p.lexer.nextNonCommentItem()
p.lookahead = &i
return i
}
Expand Down
8 changes: 4 additions & 4 deletions internal/schema/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ var parserTestCases = []struct {
permits = {
view: (ctx: Context): boolean =>
(
this.related.parents.traverse((p) =>
this.related.parents.traverse((p) /* comment */ =>
p.related.viewers.includes(ctx.subject),
) &&
) && // comment
this.related.parents.traverse(p => p.permits.view(ctx)) ) ||
(this.related.viewers.includes(ctx.subject) ||
this.related.viewers.includes(ctx.subject) ||
(this.related.viewers.includes(ctx.subject) || // some comment
this.related.viewers.includes(ctx.subject) || /* another comment */
this.related.viewers.includes(ctx.subject) ) ||
this.related.owners.includes(ctx.subject),
Expand Down

0 comments on commit 5f89fcf

Please sign in to comment.