private Token ReadNumericLiteral(int firstChar)
{
// We need to keep track of the column and possibly capture the input into a string.
var reader = new LexerReader(this);
NumberParser.ParseCoreStatus status;
double result = NumberParser.ParseCore(reader, (char)firstChar, out status);
// Handle various error cases.
switch (status)
{
case NumberParser.ParseCoreStatus.NoDigits:
// If the number consists solely of a period, return that as a token.
return PunctuatorToken.Dot;
case NumberParser.ParseCoreStatus.NoExponent:
throw new JavaScriptException(this.engine, ErrorType.SyntaxError, "Invalid number.", this.lineNumber, this.Source.Path);
case NumberParser.ParseCoreStatus.InvalidHexLiteral:
throw new JavaScriptException(this.engine, ErrorType.SyntaxError, "Invalid hexidecimal literal.", this.lineNumber, this.Source.Path);
case NumberParser.ParseCoreStatus.ES3OctalLiteral:
// ES3 octal literals are not supported in strict mode.
if (this.StrictMode)
throw new JavaScriptException(this.engine, ErrorType.SyntaxError, "Octal numbers are not allowed in strict mode.", this.lineNumber, this.Source.Path);
break;
case NumberParser.ParseCoreStatus.InvalidOctalLiteral:
throw new JavaScriptException(this.engine, ErrorType.SyntaxError, "Invalid octal literal.", this.lineNumber, this.Source.Path);
case NumberParser.ParseCoreStatus.InvalidBinaryLiteral:
throw new JavaScriptException(this.engine, ErrorType.SyntaxError, "Invalid binary literal.", this.lineNumber, this.Source.Path);
}
// Return the result as an integer if possible, otherwise return it as a double.
if (result == (double)(int)result)
return new LiteralToken((int)result);
return new LiteralToken(result);
}