diff --git a/source/tlang/commandline/lexer.d b/source/tlang/commandline/lexer.d index aa1945e..dc3f0f5 100644 --- a/source/tlang/commandline/lexer.d +++ b/source/tlang/commandline/lexer.d @@ -61,12 +61,12 @@ public final class Lexer /* Check if we need to do combinators (e.g. for ||, &&) */ /* TODO: Second operand in condition out of bounds */ - if(currentChar == '|' && sourceCode[position+1] == '|') + if(currentChar == '|' && (position+1) != sourceCode.length && sourceCode[position+1] == '|') { splitterToken = "||"; position += 2; } - else if(currentChar == '&' && sourceCode[position+1] == '&') + else if(currentChar == '&' && (position+1) != sourceCode.length && sourceCode[position+1] == '&') { splitterToken = "&&"; position += 2; @@ -185,6 +185,17 @@ unittest assert(currentLexer.getTokens() == ["hello", "\"world\"","||"]); } +/* Test input: `hello "world"|` */ +unittest +{ + import std.algorithm.comparison; + string sourceCode = "hello \"world\";|"; + Lexer currentLexer = new Lexer(sourceCode); + currentLexer.performLex(); + gprintln("Collected "~to!(string)(currentLexer.getTokens())); + assert(currentLexer.getTokens() == ["hello", "\"world\"",";", "|"]); +} + /* Test input: ` hello` */ unittest {