From 05e7c2aff2e459afff7a6a077668891aafe7a834 Mon Sep 17 00:00:00 2001 From: Tomas Babej Date: Sun, 24 Jan 2021 01:29:34 -0500 Subject: [PATCH] Lexer: Do not allow leading zero for two and more digit integers --- src/Lexer.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Lexer.cpp b/src/Lexer.cpp index 9da16cd2c..b42d5f3ef 100644 --- a/src/Lexer.cpp +++ b/src/Lexer.cpp @@ -687,17 +687,25 @@ bool Lexer::isNumber (std::string& token, Lexer::Type& type) //////////////////////////////////////////////////////////////////////////////// // Lexer::Type::number -// \d+ +// 0 +// [1-9]\d* +// Integers do not start with a leading 0, unless they are zero. bool Lexer::isInteger (std::string& token, Lexer::Type& type) { std::size_t marker = _cursor; + bool leading_zero = (_text[marker] == '0'); + if (unicodeLatinDigit (_text[marker])) { ++marker; while (unicodeLatinDigit (_text[marker])) utf8_next_char (_text, marker); + // Leading zero is only allowed in the case of number 0 + if (leading_zero and marker - _cursor > 1) + return false; + token = _text.substr (_cursor, marker - _cursor); type = Lexer::Type::number; _cursor = marker;