From e674cb99edf50de91f8f5aed3188e30ffb7c88d7 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Thu, 18 Feb 2016 21:34:00 +1100 Subject: Parser - box Patterns, edge bug fix --- src/ast/pattern.cpp | 9 +++++++++ src/ast/pattern.hpp | 6 ++++++ 2 files changed, 15 insertions(+) (limited to 'src/ast') diff --git a/src/ast/pattern.cpp b/src/ast/pattern.cpp index 1b189fa9..f2279a55 100644 --- a/src/ast/pattern.cpp +++ b/src/ast/pattern.cpp @@ -21,6 +21,9 @@ namespace AST { (MaybeBind, os << "?"; ), + (Box, + os << "box " << *ent.sub; + ), (Ref, os << "&" << (ent.mut ? "mut " : "") << *ent.sub; ), @@ -59,6 +62,9 @@ SERIALISE_TYPE(Pattern::, "Pattern", { ), (MaybeBind, ), + (Box, + s << e.sub; + ), (Ref, s << e.mut; s << e.sub; @@ -88,6 +94,9 @@ SERIALISE_TYPE(Pattern::, "Pattern", { _D(Any, ) _D(MaybeBind, ) + _D(Box, + s.item( ent.sub ); + ) _D(Ref, s.item( ent.mut ); s.item( ent.sub ); diff --git a/src/ast/pattern.hpp b/src/ast/pattern.hpp index 6b89aa35..f28fe8e3 100644 --- a/src/ast/pattern.hpp +++ b/src/ast/pattern.hpp @@ -21,6 +21,7 @@ public: TAGGED_UNION(Data, Any, (Any, () ), (MaybeBind, () ), + (Box, (unique_ptr sub;) ), (Ref, (bool mut; unique_ptr sub;) ), (Value, (unique_ptr start; unique_ptr end;) ), (Tuple, (::std::vector sub_patterns;) ), @@ -52,6 +53,11 @@ public: m_data( Data::make_MaybeBind({}) ) {} + struct TagBox {}; + Pattern(TagBox, Pattern sub): + m_data( Data::make_Box({ unique_ptr(new Pattern(mv$(sub))) }) ) + {} + struct TagValue {}; Pattern(TagValue, unique_ptr node, unique_ptr node2 = 0): m_data( Data::make_Value({ ::std::move(node), ::std::move(node2) }) ) -- cgit v1.2.3