diff options
author | John Hodge <tpg@mutabah.net> | 2015-04-04 16:25:14 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2015-04-04 16:25:14 +0800 |
commit | c744ebf392209f1dc7dda8900d1e0b16823b55bd (patch) | |
tree | 145599928895c06bc9e317623a3f312e660111a9 /src | |
parent | 18c2dbbaa330157006b56d3afc97b89379120ddd (diff) | |
download | mrust-c744ebf392209f1dc7dda8900d1e0b16823b55bd.tar.gz |
Hacked in parsing of HRLs
Diffstat (limited to 'src')
-rw-r--r-- | src/ast/ast.hpp | 5 | ||||
-rw-r--r-- | src/parse/root.cpp | 25 |
2 files changed, 30 insertions, 0 deletions
diff --git a/src/ast/ast.hpp b/src/ast/ast.hpp index 1cfae202..2b60ba57 100644 --- a/src/ast/ast.hpp +++ b/src/ast/ast.hpp @@ -56,6 +56,7 @@ class GenericBound: ::std::string m_lifetime_bound; // if "", use m_trait
bool m_optional;
AST::Path m_trait;
+ ::std::vector< ::std::string> m_hrls; // Higher-ranked lifetimes
public:
GenericBound() {}
@@ -73,6 +74,10 @@ public: m_trait( ::std::move(trait) )
{ }
+ void set_higherrank( ::std::vector< ::std::string> hrls ) {
+ m_hrls = mv$(hrls);
+ }
+
bool is_trait() const { return m_lifetime_bound == ""; }
const ::std::string& lifetime() const { return m_lifetime_bound; }
const TypeRef& test() const { return m_type; }
diff --git a/src/parse/root.cpp b/src/parse/root.cpp index 89843f34..15268ce9 100644 --- a/src/parse/root.cpp +++ b/src/parse/root.cpp @@ -109,6 +109,31 @@ void Parse_WhereClause(TokenStream& lex, AST::TypeParams& params) {
throw ParseError::Todo(lex, "Lifetime bounds in 'where' clauses");
}
+ // Higher-ranked types/lifetimes
+ else if( tok.type() == TOK_RWORD_FOR )
+ {
+ ::std::vector< ::std::string> lifetimes;
+ GET_CHECK_TOK(tok, lex, TOK_LT);
+ do {
+ switch(GET_TOK(tok, lex))
+ {
+ case TOK_LIFETIME:
+ lifetimes.push_back(tok.str());
+ break;
+ default:
+ throw ParseError::Unexpected(lex, tok, Token(TOK_LIFETIME));
+ }
+ } while( GET_TOK(tok, lex) == TOK_COMMA );
+ CHECK_TOK(tok, TOK_GT);
+
+ // Parse a bound as normal
+ TypeRef type = Parse_Type(lex);
+ GET_CHECK_TOK(tok, lex, TOK_COLON);
+ Parse_TypeBound(lex, params, type);
+
+ // And store the higher-ranked lifetime list
+ params.bounds().back().set_higherrank( mv$(lifetimes) );
+ }
else
{
lex.putback(tok);
|