From a3e8257c4f77f197c9be2dbae7aaddb81257abb2 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Fri, 19 Aug 2016 10:27:38 +0800 Subject: Patterns - Support tuples with .. (fully) --- src/dump_as_rust.cpp | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) (limited to 'src/dump_as_rust.cpp') diff --git a/src/dump_as_rust.cpp b/src/dump_as_rust.cpp index 1f51f317..3c3a215d 100644 --- a/src/dump_as_rust.cpp +++ b/src/dump_as_rust.cpp @@ -535,6 +535,7 @@ private: void print_params(const AST::GenericParams& params); void print_bounds(const AST::GenericParams& params); + void print_pattern_tuple(const AST::Pattern::TuplePat& v); void print_pattern(const AST::Pattern& p, bool is_refutable); void print_type(const TypeRef& t); @@ -772,6 +773,15 @@ void RustPrinter::print_bounds(const AST::GenericParams& params) } } +void RustPrinter::print_pattern_tuple(const AST::Pattern::TuplePat& v) +{ + m_os << v.start; + if( v.has_wildcard ) + { + m_os << ".., "; + m_os << v.end; + } +} void RustPrinter::print_pattern(const AST::Pattern& p, bool is_refutable) { if( p.binding().is_valid() ) { @@ -814,16 +824,7 @@ void RustPrinter::print_pattern(const AST::Pattern& p, bool is_refutable) ), (StructTuple, m_os << v.path << "("; - if( v.tup_pat.glob_pos == ::AST::Pattern::TupleGlob::Start ) { - m_os << ".., "; - } - for(const auto& sp : v.tup_pat.sub_patterns) { - print_pattern(sp, is_refutable); - m_os << ","; - } - if( v.tup_pat.glob_pos == ::AST::Pattern::TupleGlob::End ) { - m_os << " .."; - } + this->print_pattern_tuple(v.tup_pat); m_os << ")"; ), (Struct, { @@ -838,16 +839,7 @@ void RustPrinter::print_pattern(const AST::Pattern& p, bool is_refutable) }), (Tuple, m_os << "("; - if( v.glob_pos == ::AST::Pattern::TupleGlob::Start ) { - m_os << ".., "; - } - for(const auto& sp : v.sub_patterns) { - print_pattern(sp, is_refutable); - m_os << ","; - } - if( v.glob_pos == ::AST::Pattern::TupleGlob::End ) { - m_os << " .."; - } + this->print_pattern_tuple(v); m_os << ")"; ), (Slice, -- cgit v1.2.3