Skip to content

Commit

Permalink
Fix nested code block in parser (#53)
Browse files Browse the repository at this point in the history
- By using 'blockComment' instead of 'BlockCommentStart' when nesting is allowed,
nested comments would require a nested closing block comment token. This isn't
how any languages I know of actually work - additional BlockCommentStarts should
be ignored.
  • Loading branch information
cbush authored Mar 1, 2021
1 parent f274b65 commit c115c34
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/bluehawk/parser/RootParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ blockCommand
: (LineComment)? CommandStart (commandAttribute)? Newline (chunk)* (LineComment)* CommandEnd
blockComment
: BlockCommentStart (command | LineComment | NewLine | blockComment†)* BlockCommentEnd
: BlockCommentStart (command | LineComment | NewLine | BlockCommentStart†)* BlockCommentEnd
chunk
: (command | blockComment | lineComment | pushParser | StringLiteral)* (Newline | EOF)††
Expand Down Expand Up @@ -192,9 +192,8 @@ export class RootParser extends CstParser {
{ ALT: () => this.CONSUME(LineComment) },
{ ALT: () => this.CONSUME(Newline) },
{
// Only if explicitly set to `false` does this forbid nesting
GATE: () => startToken.payload?.canNest !== false,
ALT: () => this.SUBRULE(this.blockComment),
ALT: () => this.CONSUME1(BlockCommentStart),
},
])
);
Expand Down

0 comments on commit c115c34

Please sign in to comment.