Skip to content

Commit

Permalink
switched to a stringbuilder in the tokenreader
Browse files Browse the repository at this point in the history
  • Loading branch information
pieterderycke committed Dec 14, 2019
1 parent b82e07e commit 6c30252
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions Jace/Tokenizer/TokenReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ public List<Token> Read(string formula)
{
if (IsPartOfNumeric(characters[i], true, isFormulaSubPart))
{
string buffer = "" + characters[i];
StringBuilder buffer = new StringBuilder();
buffer.Append(characters[i]);
//string buffer = "" + characters[i];
int startPosition = i;


Expand All @@ -64,31 +66,31 @@ public List<Token> Read(string formula)

if (characters[i + 1] == '-')
{
buffer += characters[i++];
buffer.Append(characters[i++]);
}
}

buffer += characters[i];
buffer.Append(characters[i]);
}

// Verify if we do not have an int
int intValue;
if (int.TryParse(buffer, out intValue))
if (int.TryParse(buffer.ToString(), out intValue))
{
tokens.Add(new Token() { TokenType = TokenType.Integer, Value = intValue, StartPosition = startPosition, Length = i - startPosition });
isFormulaSubPart = false;
}
else
{
double doubleValue;
if (double.TryParse(buffer, NumberStyles.Float | NumberStyles.AllowThousands,
if (double.TryParse(buffer.ToString(), NumberStyles.Float | NumberStyles.AllowThousands,
cultureInfo, out doubleValue))
{
tokens.Add(new Token() { TokenType = TokenType.FloatingPoint, Value = doubleValue, StartPosition = startPosition, Length = i - startPosition });
isScientific = false;
isFormulaSubPart = false;
}
else if (buffer == "-")
else if (buffer.ToString() == "-")
{
// Verify if we have a unary minus, we use the token '_' for a unary minus in the AST builder
tokens.Add(new Token() { TokenType = TokenType.Operation, Value = '_', StartPosition = startPosition, Length = 1 });
Expand Down

0 comments on commit 6c30252

Please sign in to comment.