From 172d89b927038672a8f03d582bbd6db30af6ebc9 Mon Sep 17 00:00:00 2001 From: Hazurl Date: Wed, 6 Sep 2023 20:01:48 +0200 Subject: [PATCH] [parser] Fix number parsing in interval --- src/main/java/leekscript/compiler/LexicalParser.java | 8 ++++---- src/test/java/test/TestInterval.java | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/leekscript/compiler/LexicalParser.java b/src/main/java/leekscript/compiler/LexicalParser.java index 5ad617f1..4890d70d 100644 --- a/src/main/java/leekscript/compiler/LexicalParser.java +++ b/src/main/java/leekscript/compiler/LexicalParser.java @@ -187,13 +187,13 @@ private boolean tryParseNumber(ErrorReporter error) throws LeekCompilerException } if (c == '.') { - if (stream.getSubStringSince(startingPoint).contains(".")) { - error.report(new AnalyzeError(new Token(TokenType.NOTHING, ".", aiFile, stream.getLineCounter(), stream.getCharCounter() + 1), AnalyzeErrorLevel.ERROR, Error.INVALID_CHAR)); + // We don't eat the dot if it's followed by another dot + if (stream.peek(1) == '.') { break; } - // We don't eat the dot if it's not followed by another dot - if (stream.peek(1) == '.') { + if (stream.getSubStringSince(startingPoint).contains(".")) { + error.report(new AnalyzeError(new Token(TokenType.NOTHING, ".", aiFile, stream.getLineCounter(), stream.getCharCounter() + 1), AnalyzeErrorLevel.ERROR, Error.INVALID_CHAR)); break; } diff --git a/src/test/java/test/TestInterval.java b/src/test/java/test/TestInterval.java index cc4c1ea9..449b39b4 100644 --- a/src/test/java/test/TestInterval.java +++ b/src/test/java/test/TestInterval.java @@ -9,7 +9,7 @@ public void run() throws Exception { section("Interval.constructor()"); code("return [..]").equals("[..]"); code("return [1..2]").equals("[1..2]"); - DISABLED_code("return [1.0..2.0]").equals("[1.0..2.0]"); + code("return [1.0..2.0]").equals("[1.0..2.0]"); code_v1("return [1.0 .. 2.0]").equals("[1..2]"); code_v2_("return [1.0 .. 2.0]").equals("[1.0..2.0]"); code("return [-10..-2]").equals("[-10..-2]");