From 23a07b1a0f9f168c785ae9932f617aa16897337f Mon Sep 17 00:00:00 2001 From: Sean Barag Date: Wed, 29 May 2019 16:32:21 -0700 Subject: [PATCH] fix(lex): Allow single-word #elseif and #endif (#249) 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. --- src/lexer/Lexer.ts | 6 ++++++ test/lexer/Lexer.test.js | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/lexer/Lexer.ts b/src/lexer/Lexer.ts index d61f28ca5..c823beb50 100644 --- a/src/lexer/Lexer.ts +++ b/src/lexer/Lexer.ts @@ -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; diff --git a/test/lexer/Lexer.test.js b/test/lexer/Lexer.test.js index 0c9b8ec3d..0770043cd 100644 --- a/test/lexer/Lexer.test.js +++ b/test/lexer/Lexer.test.js @@ -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, ]); });