From ffee5221c70944273da47f8dfed4056a9760d389 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20N=C3=A9meti?= Date: Thu, 26 Jan 2023 17:45:23 +0100 Subject: [PATCH] NumberLiteral: fix for the case when the decimal separator is not a dot - 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 --- Irony/Parsing/Terminals/NumberLiteral.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Irony/Parsing/Terminals/NumberLiteral.cs b/Irony/Parsing/Terminals/NumberLiteral.cs index 3dfa53d..f79bcae 100644 --- a/Irony/Parsing/Terminals/NumberLiteral.cs +++ b/Irony/Parsing/Terminals/NumberLiteral.cs @@ -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; @@ -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