feat: implement scientific notation parsing for number literals in wren compiler

Add support for parsing scientific notation (e.g., 2.55e2, -2.55e-2) in the
readNumber function of wren_compiler.c. The implementation handles optional
negative exponents, validates that exponent digits follow 'e'/'E', and emits
a lex error for unterminated scientific notation. Also adds comprehensive
test cases covering valid scientific literals, missing exponents, floating
exponents, missing fractional parts, and multiple exponents.
This commit is contained in:
minirop
2015-07-10 16:07:48 +00:00
parent 8d315517e5
commit dba104a696
9 changed files with 32 additions and 3 deletions
+16 -1
View File
@@ -608,7 +608,6 @@ static void readHexNumber(Parser* parser)
// Finishes lexing a number literal.
static void readNumber(Parser* parser)
{
// TODO: scientific, etc.
while (isDigit(peekChar(parser))) nextChar(parser);
// See if it has a floating point. Make sure there is a digit after the "."
@@ -618,6 +617,22 @@ static void readNumber(Parser* parser)
nextChar(parser);
while (isDigit(peekChar(parser))) nextChar(parser);
}
// See if the number is in scientific notation
if (peekChar(parser) == 'e' || peekChar(parser) == 'E')
{
nextChar(parser);
// if the exponant is negative
if(peekChar(parser) == '-') nextChar(parser);
if(!isDigit(peekChar(parser)))
{
lexError(parser, "Unterminated scientific notation.");
}
while (isDigit(peekChar(parser))) nextChar(parser);
}
makeNumber(parser, false);
}