summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2016-02-23 10:47:54 +1100
committerJohn Hodge <tpg@mutabah.net>2016-02-23 10:47:54 +1100
commit6325fd13e77e80dc24bfea7f8fff5fad45861295 (patch)
tree46642e87450688d6dcdd8655c9f3b691e0c330b6
parent1592a53e831b041b8e3392a06e12179379394eda (diff)
downloadmrust-6325fd13e77e80dc24bfea7f8fff5fad45861295.tar.gz
Attributes on match arms
-rw-r--r--src/ast/ast.hpp74
-rw-r--r--src/ast/expr.hpp2
-rw-r--r--src/parse/expr.cpp9
3 files changed, 12 insertions, 73 deletions
diff --git a/src/ast/ast.hpp b/src/ast/ast.hpp
index a703da89..4165b34d 100644
--- a/src/ast/ast.hpp
+++ b/src/ast/ast.hpp
@@ -22,7 +22,7 @@
#include <serialise.hpp>
#include "pattern.hpp"
-
+#include "attrs.hpp"
#include "expr.hpp"
namespace AST {
@@ -157,78 +157,6 @@ public:
SERIALISABLE_PROTOTYPES();
};
-//
-class MetaItem;
-
-class MetaItems:
- public Serialisable
-{
-public:
- ::std::vector<MetaItem> m_items;
-
- MetaItems() {}
- MetaItems(::std::vector<MetaItem> items):
- m_items(items)
- {
- }
-
- void push_back(MetaItem i);
-
- MetaItem* get(const char *name);
- bool has(const char *name) {
- return get(name) != 0;
- }
-
- friend ::std::ostream& operator<<(::std::ostream& os, const MetaItems& x) {
- return os << "[" << x.m_items << "]";
- }
-
- SERIALISABLE_PROTOTYPES();
-};
-
-class MetaItem:
- public Serialisable
-{
- ::std::string m_name;
- MetaItems m_sub_items;
- ::std::string m_str_val;
-public:
- MetaItem() {}
- MetaItem(::std::string name):
- m_name(name)
- {
- }
- MetaItem(::std::string name, ::std::string str_val):
- m_name(name),
- m_str_val(str_val)
- {
- }
- MetaItem(::std::string name, ::std::vector<MetaItem> items):
- m_name(name),
- m_sub_items(items)
- {
- }
-
- void mark_used() {}
- const ::std::string& name() const { return m_name; }
- const ::std::string& string() const { return m_str_val; }
- bool has_sub_items() const { return m_sub_items.m_items.size() > 0; }
- const MetaItems& items() const { return m_sub_items; }
- MetaItems& items() { return m_sub_items; }
-
- friend ::std::ostream& operator<<(::std::ostream& os, const MetaItem& x) {
- os << x.m_name;
- if(x.m_sub_items.m_items.size())
- os << "(" << x.m_sub_items.m_items << ")";
- else
- os << "=\"" << x.m_str_val << "\"";
- return os;
- }
-
- SERIALISABLE_PROTOTYPES();
-};
-
-
enum eItemType
{
ITEM_TRAIT,
diff --git a/src/ast/expr.hpp b/src/ast/expr.hpp
index 2fe9ab36..96b83381 100644
--- a/src/ast/expr.hpp
+++ b/src/ast/expr.hpp
@@ -10,6 +10,7 @@
#include "../parse/tokentree.hpp"
#include "../types.hpp"
#include "pattern.hpp"
+#include "attrs.hpp"
namespace AST {
@@ -235,6 +236,7 @@ struct ExprNode_Match:
struct Arm:
public Serialisable
{
+ MetaItems m_attrs;
::std::vector<Pattern> m_patterns;
unique_ptr<ExprNode> m_cond;
diff --git a/src/parse/expr.cpp b/src/parse/expr.cpp
index 723352d3..f253293d 100644
--- a/src/parse/expr.cpp
+++ b/src/parse/expr.cpp
@@ -490,6 +490,15 @@ ExprNodeP Parse_Expr_Match(TokenStream& lex)
break;
lex.putback(tok);
AST::ExprNode_Match::Arm arm;
+
+ ::AST::MetaItems arm_attrs;
+ while( LOOK_AHEAD(lex) == TOK_ATTR_OPEN ) {
+ GET_TOK(tok, lex);
+ arm_attrs.push_back( Parse_MetaItem(lex) );
+ GET_CHECK_TOK(tok, lex, TOK_SQUARE_CLOSE);
+ }
+ arm.m_attrs = mv$(arm_attrs);
+
do {
// Refutable pattern
arm.m_patterns.push_back( Parse_Pattern(lex, true) );