From: Pierre-Emmanuel Patry Date: Wed, 3 May 2023 10:38:06 +0000 (+0200) Subject: gccrs: converter: Add punct conversion function X-Git-Tag: basepoints/gcc-15~2555 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=449d3f5793dcf5a92d551daf7dcf6516aec7dfa8;p=thirdparty%2Fgcc.git 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 --- 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