aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/expand/rust-macro-expand.h
diff options
context:
space:
mode:
authorArthur Cohen <arthur.cohen@embecosm.com>2022-02-22 09:32:52 +0100
committerArthur Cohen <arthur.cohen@embecosm.com>2022-02-23 10:13:06 +0100
commit1f546e5e3addda01c5c449833642be8fcdf5dcdc (patch)
treee0ec05beebb6bcd83042d385920d79f38420d4aa /gcc/rust/expand/rust-macro-expand.h
parent6db51e39363a4500dd8d3e04d87f682f9ef11f26 (diff)
downloadgcc-1f546e5e3addda01c5c449833642be8fcdf5dcdc.zip
gcc-1f546e5e3addda01c5c449833642be8fcdf5dcdc.tar.gz
gcc-1f546e5e3addda01c5c449833642be8fcdf5dcdc.tar.bz2
match_repetition: Set the correct amount of matches for each fragment
Co-authored-by: philberty <philip.herron@embecosm.com>
Diffstat (limited to 'gcc/rust/expand/rust-macro-expand.h')
-rw-r--r--gcc/rust/expand/rust-macro-expand.h12
1 files changed, 11 insertions, 1 deletions
diff --git a/gcc/rust/expand/rust-macro-expand.h b/gcc/rust/expand/rust-macro-expand.h
index 51e5ad1..f3cb36d 100644
--- a/gcc/rust/expand/rust-macro-expand.h
+++ b/gcc/rust/expand/rust-macro-expand.h
@@ -57,11 +57,21 @@ struct MatchedFragment
size_t match_amount;
MatchedFragment (std::string identifier, size_t token_offset_begin,
- size_t token_offset_end, size_t match_amount = 0)
+ size_t token_offset_end, size_t match_amount = 1)
: fragment_ident (identifier), token_offset_begin (token_offset_begin),
token_offset_end (token_offset_end), match_amount (match_amount)
{}
+ /**
+ * Create a valid fragment matched zero times. This is useful for repetitions
+ * which allow the absence of a fragment, such as * and ?
+ */
+ static MatchedFragment zero (std::string identifier)
+ {
+ // We don't need offsets since there is "no match"
+ return MatchedFragment (identifier, 0, 0, 0);
+ }
+
std::string as_string () const
{
return fragment_ident + "=" + std::to_string (token_offset_begin) + ":"