summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibCpp/Parser.cpp
diff options
context:
space:
mode:
authorItamar <itamar8910@gmail.com>2021-07-03 11:47:41 +0300
committerAndreas Kling <kling@serenityos.org>2021-07-04 17:50:33 +0200
commit232013c05bd024efc62f23cf99bafe4f0bef1333 (patch)
treeab9bed449aed5ea8cc4f5f19584567ff86c0b5b5 /Userland/Libraries/LibCpp/Parser.cpp
parent9a31fb66730cff57a12407fab67aca3f8356c08c (diff)
downloadserenity-232013c05bd024efc62f23cf99bafe4f0bef1333.zip
LibCpp: Add Parser::tokens_in_range(start, end)
This function returns the tokens that exist in the specified range.
Diffstat (limited to 'Userland/Libraries/LibCpp/Parser.cpp')
-rw-r--r--Userland/Libraries/LibCpp/Parser.cpp16
1 files changed, 13 insertions, 3 deletions
diff --git a/Userland/Libraries/LibCpp/Parser.cpp b/Userland/Libraries/LibCpp/Parser.cpp
index 7b7d674801..136175599a 100644
--- a/Userland/Libraries/LibCpp/Parser.cpp
+++ b/Userland/Libraries/LibCpp/Parser.cpp
@@ -870,15 +870,25 @@ String Parser::text_of_node(const ASTNode& node) const
String Parser::text_in_range(Position start, Position end) const
{
+ StringBuilder builder;
+ for (auto token : tokens_in_range(start, end)) {
+ builder.append(token.text());
+ }
+ return builder.to_string();
+}
+
+Vector<Token> Parser::tokens_in_range(Position start, Position end) const
+{
auto start_token_index = index_of_token_at(start);
auto end_node_index = index_of_token_at(end);
VERIFY(start_token_index.has_value());
VERIFY(end_node_index.has_value());
- StringBuilder text;
+
+ Vector<Token> tokens;
for (size_t i = start_token_index.value(); i <= end_node_index.value(); ++i) {
- text.append(m_tokens[i].text());
+ tokens.append(m_tokens[i]);
}
- return text.build();
+ return tokens;
}
void Parser::error(StringView message)