diff options
author | John Hodge <tpg@mutabah.net> | 2016-08-18 21:40:06 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2016-08-18 21:40:06 +0800 |
commit | c0d8141930e95f71a6d4fb84114fdc8a449527b7 (patch) | |
tree | 828892e2cbee599bc15227ba3270f6ddc82d2581 /src/ast/pattern.cpp | |
parent | 65aba167033019994e35f43b819d8fbd3620e9ff (diff) | |
download | mrust-c0d8141930e95f71a6d4fb84114fdc8a449527b7.tar.gz |
All - Support tuple patterns with .. at the start/end - TODO: Support in the middle
Diffstat (limited to 'src/ast/pattern.cpp')
-rw-r--r-- | src/ast/pattern.cpp | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/src/ast/pattern.cpp b/src/ast/pattern.cpp index 164ba962..bc961e63 100644 --- a/src/ast/pattern.cpp +++ b/src/ast/pattern.cpp @@ -57,6 +57,17 @@ namespace AST { ) return os; } +::std::ostream& operator<<(::std::ostream& os, const Pattern::TuplePat& val) +{ + if( val.glob_pos == Pattern::TupleGlob::Start ) { + os << ".., "; + } + os << val.sub_patterns; + if( val.glob_pos == Pattern::TupleGlob::End ) { + os << ".., "; + } + return os; +} ::std::ostream& operator<<(::std::ostream& os, const Pattern& pat) { os << "Pattern("; @@ -85,13 +96,10 @@ namespace AST { os << " ... " << ent.end; ), (Tuple, - os << "(" << ent.sub_patterns << ")"; - ), - (WildcardStructTuple, - os << ent.path << " (..)"; + os << "(" << ent << ")"; ), (StructTuple, - os << ent.path << " (" << ent.sub_patterns << ")"; + os << ent.path << " (" << ent.tup_pat << ")"; ), (Struct, os << ent.path << " {" << ent.sub_patterns << "}"; @@ -159,6 +167,12 @@ AST::Pattern AST::Pattern::clone() const rv.push_back( p.clone() ); return rv; } + static TuplePat clone_tup(const TuplePat& p) { + return TuplePat { + p.glob_pos, + H::clone_list(p.sub_patterns) + }; + } static AST::Pattern::Value clone_val(const AST::Pattern::Value& v) { TU_MATCH(::AST::Pattern::Value, (v), (e), (Invalid, return Value(e);), @@ -191,13 +205,10 @@ AST::Pattern AST::Pattern::clone() const rv.m_data = Data::make_Value({ H::clone_val(e.start), H::clone_val(e.end) }); ), (Tuple, - rv.m_data = Data::make_Tuple({ H::clone_list(e.sub_patterns) }); - ), - (WildcardStructTuple, - rv.m_data = Data::make_WildcardStructTuple({ ::AST::Path(e.path) }); + rv.m_data = Data::make_Tuple({ H::clone_tup(e) }); ), (StructTuple, - rv.m_data = Data::make_StructTuple({ ::AST::Path(e.path), H::clone_list(e.sub_patterns) }); + rv.m_data = Data::make_StructTuple({ ::AST::Path(e.path), H::clone_tup(e.tup_pat) }); ), (Struct, ::std::vector< ::std::pair< ::std::string, Pattern> > sps; |