Skip to content

Commit

Permalink
fix(lex): Allow single-word #elseif and #endif (#249)
Browse files Browse the repository at this point in the history
The two-word variants `#else if` and `#end if` were already supported,
but I didn't realize the single-word versions were valid in RBI!  Now
they're valid here too.
  • Loading branch information
sjbarag authored May 29, 2019
1 parent 3a6f30b commit 23a07b1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/lexer/Lexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,12 @@ export class Lexer {
case "#else":
addToken(Lexeme.HashElse);
return;
case "#elseif":
addToken(Lexeme.HashElseIf);
return;
case "#endif":
addToken(Lexeme.HashEndIf);
return;
case "#const":
addToken(Lexeme.HashConst);
return;
Expand Down
4 changes: 3 additions & 1 deletion test/lexer/Lexer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,12 +341,14 @@ describe("lexer", () => {
});

it("reads conditional directives", () => {
let { tokens } = Lexer.scan("#if #else if #else #end if");
let { tokens } = Lexer.scan("#if #else if #elseif #else #end if #endif");
expect(tokens.map(t => t.kind)).toEqual([
Lexeme.HashIf,
Lexeme.HashElseIf,
Lexeme.HashElseIf,
Lexeme.HashElse,
Lexeme.HashEndIf,
Lexeme.HashEndIf,
Lexeme.Eof,
]);
});
Expand Down

0 comments on commit 23a07b1

Please sign in to comment.