Fixed bug whereby `isNumericalStr()` returned true for empty strings.
This fixes problems whereby if the current build up was empty and a field accessor was being attempted then lexing would fail.
This commit is contained in:
parent
3d54c4deee
commit
806814f01c
|
@ -172,7 +172,7 @@ public final class Lexer
|
||||||
|
|
||||||
/* Enable floating point mode and go to next iteration*/
|
/* Enable floating point mode and go to next iteration*/
|
||||||
floatMode = true;
|
floatMode = true;
|
||||||
gprintln("Halo");
|
gprintln("Float mode just got enabled: Current build up: \""~currentToken~"\"");
|
||||||
column++;
|
column++;
|
||||||
position++;
|
position++;
|
||||||
continue;
|
continue;
|
||||||
|
@ -583,8 +583,25 @@ public final class Lexer
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Given a string return true if all characters
|
||||||
|
* are digits, false otherwise and false if
|
||||||
|
* the string is empty
|
||||||
|
*/
|
||||||
private static bool isNumericalStr(string input)
|
private static bool isNumericalStr(string input)
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* If the given input is empty then return false
|
||||||
|
*/
|
||||||
|
if(input.length == 0)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If there are any characters in the string then
|
||||||
|
* check if all are digits
|
||||||
|
*/
|
||||||
for(ulong i = 0; i < input.length; i++)
|
for(ulong i = 0; i < input.length; i++)
|
||||||
{
|
{
|
||||||
char character = input[i];
|
char character = input[i];
|
||||||
|
@ -784,4 +801,15 @@ unittest
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Test input: `1.5` */
|
||||||
|
unittest
|
||||||
|
{
|
||||||
|
import std.algorithm.comparison;
|
||||||
|
string sourceCode = "1.5";
|
||||||
|
Lexer currentLexer = new Lexer(sourceCode);
|
||||||
|
currentLexer.performLex();
|
||||||
|
gprintln("Collected "~to!(string)(currentLexer.getTokens()));
|
||||||
|
assert(currentLexer.getTokens() == [new Token("1.5", 0, 0)]);
|
||||||
|
}
|
||||||
|
|
||||||
/* TODO: Add more tests */
|
/* TODO: Add more tests */
|
Loading…
Reference in New Issue