From a178a07e4322fca9bd3c4b12d3d1da32bedfe198 Mon Sep 17 00:00:00 2001 From: Pierre-Emmanuel Patry Date: Tue, 21 May 2024 17:45:34 +0200 Subject: 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 --- gcc/rust/hir/rust-ast-lower-pattern.cc | 3 +++ 1 file changed, 3 insertions(+) (limited to 'gcc/rust/hir') diff --git a/gcc/rust/hir/rust-ast-lower-pattern.cc b/gcc/rust/hir/rust-ast-lower-pattern.cc index 138e4b7..784c29a 100644 --- a/gcc/rust/hir/rust-ast-lower-pattern.cc +++ b/gcc/rust/hir/rust-ast-lower-pattern.cc @@ -18,6 +18,7 @@ #include "rust-ast-lower-pattern.h" #include "rust-ast-lower-expr.h" +#include "rust-system.h" namespace Rust { namespace HIR { @@ -253,6 +254,8 @@ ASTLoweringPattern::visit (AST::LiteralPattern &pattern) void ASTLoweringPattern::visit (AST::RangePattern &pattern) { + if (pattern.get_range_kind () == AST::RangeKind::EXCLUDED) + rust_unreachable (); // Not supported yet auto upper_bound = lower_range_pattern_bound (pattern.get_upper_bound ()); auto lower_bound = lower_range_pattern_bound (pattern.get_lower_bound ()); -- cgit v1.1