diff options
author | Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com> | 2024-05-21 17:45:34 +0200 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2025-03-17 16:35:34 +0100 |
commit | cc7ec3925c3371deca5fa891e0a7a82950956c54 (patch) | |
tree | cac2e8fa3678325493ca7c1d9fc21550edd9de4a /gcc/rust/parse | |
parent | ea32c9b17fa6485a0a53f12984a976650725a48e (diff) | |
download | gcc-cc7ec3925c3371deca5fa891e0a7a82950956c54.zip gcc-cc7ec3925c3371deca5fa891e0a7a82950956c54.tar.gz gcc-cc7ec3925c3371deca5fa891e0a7a82950956c54.tar.bz2 |
gccrs: Parse exclusive range pattern
Exclusive range pattern were not handled by the parser as this an
experimental feature.
gcc/rust/ChangeLog:
* ast/rust-pattern.cc (tokenid_to_rangekind): Add a new function to
get a range kind from the current token type.
(RangePattern::as_string): Change the string representation for range
pattern in order to handle excluded ranges.
* ast/rust-pattern.h (enum class): Add new enum class to differentiate
range kinds.
(tokenid_to_rangekind): New prototype for a function that converts a
token id to it's corresponding range kind.
(class RangePattern): Change the class to accept a range kind instead
of an ellipsis boolean.
* hir/rust-ast-lower-pattern.cc (ASTLoweringPattern::visit): Abort
when an excluded pattern has been found as we do not handle their
lowering yet.
* parse/rust-parse-impl.h (Parser::parse_literal_or_range_pattern):
Parse excluded range patterns.
(Parser::parse_pattern_no_alt): Likewise.
(Parser::parse_ident_leading_pattern): Likewise.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Diffstat (limited to 'gcc/rust/parse')
-rw-r--r-- | gcc/rust/parse/rust-parse-impl.h | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index 91f09f6..cabfb5b 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -10261,8 +10261,10 @@ Parser<ManagedTokenSource>::parse_literal_or_range_pattern () } const_TokenPtr next = lexer.peek_token (); - if (next->get_id () == DOT_DOT_EQ || next->get_id () == ELLIPSIS) + if (next->get_id () == DOT_DOT_EQ || next->get_id () == ELLIPSIS + || next->get_id () == DOT_DOT) { + AST::RangeKind kind = AST::tokenid_to_rangekind (next->get_id ()); // range pattern lexer.skip_token (); std::unique_ptr<AST::RangePatternBound> lower ( @@ -10283,7 +10285,7 @@ Parser<ManagedTokenSource>::parse_literal_or_range_pattern () } return std::unique_ptr<AST::RangePattern> ( - new AST::RangePattern (std::move (lower), std::move (upper), + new AST::RangePattern (std::move (lower), std::move (upper), kind, range_lower->get_locus ())); } else @@ -10532,11 +10534,12 @@ Parser<ManagedTokenSource>::parse_pattern_no_alt () = parse_qualified_path_in_expression (); if (lexer.peek_token ()->get_id () == DOT_DOT_EQ - || lexer.peek_token ()->get_id () == ELLIPSIS) + || lexer.peek_token ()->get_id () == ELLIPSIS + || lexer.peek_token ()->get_id () == DOT_DOT) { // qualified range pattern bound, so parse rest of range pattern - bool has_ellipsis_syntax - = lexer.peek_token ()->get_id () == ELLIPSIS; + AST::RangeKind kind + = AST::tokenid_to_rangekind (lexer.peek_token ()->get_id ()); lexer.skip_token (); std::unique_ptr<AST::RangePatternBoundQualPath> lower_bound ( @@ -10546,8 +10549,8 @@ Parser<ManagedTokenSource>::parse_pattern_no_alt () return std::unique_ptr<AST::RangePattern> ( new AST::RangePattern (std::move (lower_bound), - std::move (upper_bound), t->get_locus (), - has_ellipsis_syntax)); + std::move (upper_bound), kind, + t->get_locus ())); } else { @@ -10569,10 +10572,10 @@ Parser<ManagedTokenSource>::parse_pattern_no_alt () switch (next->get_id ()) { case DOT_DOT_EQ: + case DOT_DOT: case ELLIPSIS: { // qualified range pattern bound, so parse rest of range pattern - bool has_ellipsis_syntax - = lexer.peek_token ()->get_id () == ELLIPSIS; + AST::RangeKind kind = AST::tokenid_to_rangekind (next->get_id ()); lexer.skip_token (); std::unique_ptr<AST::RangePatternBoundPath> lower_bound ( @@ -10582,8 +10585,8 @@ Parser<ManagedTokenSource>::parse_pattern_no_alt () return std::unique_ptr<AST::RangePattern> ( new AST::RangePattern (std::move (lower_bound), - std::move (upper_bound), - UNKNOWN_LOCATION, has_ellipsis_syntax)); + std::move (upper_bound), kind, + UNKNOWN_LOCATION)); } case EXCLAM: return parse_macro_invocation_partial (std::move (path), @@ -11093,9 +11096,11 @@ Parser<ManagedTokenSource>::parse_ident_leading_pattern () std::move (elems))); } case DOT_DOT_EQ: + case DOT_DOT: case ELLIPSIS: { // range - bool has_ellipsis_syntax = lexer.peek_token ()->get_id () == ELLIPSIS; + AST::RangeKind kind + = AST::tokenid_to_rangekind (lexer.peek_token ()->get_id ()); lexer.skip_token (); @@ -11106,8 +11111,8 @@ Parser<ManagedTokenSource>::parse_ident_leading_pattern () return std::unique_ptr<AST::RangePattern> ( new AST::RangePattern (std::move (lower_bound), - std::move (upper_bound), UNKNOWN_LOCATION, - has_ellipsis_syntax)); + std::move (upper_bound), kind, + UNKNOWN_LOCATION)); } case PATTERN_BIND: { // only allow on single-segment paths |