Skip to content

Commit

Permalink
NumberLiteral: fix for the case when the decimal separator is not a dot
Browse files Browse the repository at this point in the history
- QuickParse: fix the case when the NumberLiteral begins with a single digit immediately followed by the decimal separator (which is not a dot)
- ReadPrefix: fix the case when the NumberLiteral begins with the '0' digit immediately followed by the decimal separator (which is not a dot), and the "0" string is being registered as prefix for octal numbers
  • Loading branch information
davidnemeti authored and yallie committed Jan 27, 2023
1 parent 601c5b1 commit ffee522
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Irony/Parsing/Terminals/NumberLiteral.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ protected override Token QuickParse(ParsingContext context, ISourceStream source
char current = source.PreviewChar;
//it must be a digit followed by a whitespace or delimiter
if (!char.IsDigit(current)) return null;
if (!Grammar.IsWhitespaceOrDelimiter(source.NextPreviewChar))
if (!Grammar.IsWhitespaceOrDelimiter(source.NextPreviewChar) || source.NextPreviewChar == DecimalSeparator)
return null;
int iValue = current - '0';
object value = null;
Expand All @@ -159,7 +159,7 @@ protected override void InitDetails(ParsingContext context, CompoundTokenDetails
protected override void ReadPrefix(ISourceStream source, CompoundTokenDetails details) {
//check that is not a 0 followed by dot;
//this may happen in Python for number "0.123" - we can mistakenly take "0" as octal prefix
if (source.PreviewChar == '0' && source.NextPreviewChar == '.') return;
if (source.PreviewChar == '0' && source.NextPreviewChar == DecimalSeparator) return;
base.ReadPrefix(source, details);
}//method

Expand Down

0 comments on commit ffee522

Please sign in to comment.