From c744ebf392209f1dc7dda8900d1e0b16823b55bd Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sat, 4 Apr 2015 16:25:14 +0800 Subject: Hacked in parsing of HRLs --- src/ast/ast.hpp | 5 +++++ src/parse/root.cpp | 25 +++++++++++++++++++++++++ 2 files changed, 30 insertions(+) (limited to 'src') 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); -- cgit v1.2.3