From 449d3f5793dcf5a92d551daf7dcf6516aec7dfa8 Mon Sep 17 00:00:00 2001 From: Pierre-Emmanuel Patry Date: Wed, 3 May 2023 12:38:06 +0200 Subject: [PATCH] gccrs: converter: Add punct conversion function Add the implementation of the Punct conversion function to tokens. gcc/rust/ChangeLog: * util/rust-token-converter.cc (from_punct): Add conversion implementation. Signed-off-by: Pierre-Emmanuel Patry --- gcc/rust/util/rust-token-converter.cc | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/gcc/rust/util/rust-token-converter.cc b/gcc/rust/util/rust-token-converter.cc index 711c89d08257..8e289e9084bc 100644 --- a/gcc/rust/util/rust-token-converter.cc +++ b/gcc/rust/util/rust-token-converter.cc @@ -14,6 +14,7 @@ // along with GCC; see the file COPYING3. If not see // . +#include "rust-lex.h" #include "rust-token-converter.h" #include "libproc_macro/proc_macro.h" @@ -310,13 +311,27 @@ from_literal (ProcMacro::Literal literal, std::vector &result) {} /** + * Accumulate through successive calls multiple Punct until one is tagged + * "Alone", then append the formed token to a given result vector. * + * @param punct Reference to the Punct to convert. * @param acc Reference to an accumulator for joined Punct. + * @param result Reference to the output token vector. */ static void from_punct (const ProcMacro::Punct &punct, std::vector &acc, std::vector &result) -{} +{ + acc.push_back (punct.ch); + if (ProcMacro::ALONE == punct.spacing) /* Last punct of a chain */ + { + // TODO: UTF-8 string + std::string whole (acc.begin (), acc.end ()); + auto lexer = Lexer (whole); + result.push_back (lexer.peek_token ()); + acc.clear (); + } +} /** * Iterate over a Group and append all inner tokens to a vector enclosed by its -- 2.47.2