Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions src/CommandInvocationParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,7 @@ namespace cmake::language
tl::expected<Token, Error> ParseIdentifier(Range r)
{
auto newRange = IgnoreSpaces(r);
auto identifier = Parser<ElementType::Identifier>{}.Parse(newRange);
if (identifier)
{
// Make sure we take into account the spaces
identifier->range.begin = r.begin;
}
return identifier;
return Parser<ElementType::Identifier>{}.Parse(newRange);
}

//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -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;
}
}
3 changes: 3 additions & 0 deletions tests/CommandInvocationParser_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
8 changes: 8 additions & 0 deletions tests/IdentifierParser_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down