From 591cf11517f42730b2e2ac8aca9a0518d9c251c4 Mon Sep 17 00:00:00 2001 From: Florian CHEVASSU Date: Sun, 19 Apr 2020 16:04:17 +0200 Subject: [PATCH] The CommandInvocationParser should not change the range of the Identifier The CommandInvocation range should contain the precending spaces, but the underlying Identifier should not. --- src/CommandInvocationParser.cpp | 10 ++-------- tests/CommandInvocationParser_tests.cpp | 3 +++ tests/IdentifierParser_tests.cpp | 8 ++++++++ 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/CommandInvocationParser.cpp b/src/CommandInvocationParser.cpp index 024eb28..f6f51c2 100644 --- a/src/CommandInvocationParser.cpp +++ b/src/CommandInvocationParser.cpp @@ -23,13 +23,7 @@ namespace cmake::language tl::expected ParseIdentifier(Range r) { auto newRange = IgnoreSpaces(r); - auto identifier = Parser{}.Parse(newRange); - if (identifier) - { - // Make sure we take into account the spaces - identifier->range.begin = r.begin; - } - return identifier; + return Parser{}.Parse(newRange); } //----------------------------------------------------------------------------- @@ -98,7 +92,7 @@ namespace cmake::language } result.children.push_back(*args); - result.range = Range{ identifier->range.begin, args->range.end }; + result.range = Range{ r.begin, args->range.end }; return result; } } diff --git a/tests/CommandInvocationParser_tests.cpp b/tests/CommandInvocationParser_tests.cpp index 0589abf..1263e1c 100644 --- a/tests/CommandInvocationParser_tests.cpp +++ b/tests/CommandInvocationParser_tests.cpp @@ -47,6 +47,9 @@ TEST_CASE("CommandInvocationParser", "[Parser]") Range r{ script.begin(), script.end() }; auto result = parser.Parse(r); REQUIRE(result); + REQUIRE(result->children.size() > 0); + REQUIRE(result->children[0].type == ElementType::Identifier); + REQUIRE(result->children[0].range == Range{ script.begin() + 1, script.begin() + 4 }); REQUIRE(result.value().range == r); } diff --git a/tests/IdentifierParser_tests.cpp b/tests/IdentifierParser_tests.cpp index 1ac4e90..11dd38c 100644 --- a/tests/IdentifierParser_tests.cpp +++ b/tests/IdentifierParser_tests.cpp @@ -34,6 +34,14 @@ TEST_CASE("IdentifierParser", "[Parser]") REQUIRE(!result); } + SECTION("Start with some spaces") + { + auto script = "\nbad"sv; + Range r{ script.begin(), script.end() }; + auto result = parser.Parse(r); + REQUIRE(!result); + } + SECTION("Use special characters") { auto script = "dollar_$_is_not_valid"sv;