diff options
author | John Hodge <tpg@ucc.asn.au> | 2018-06-03 14:57:05 +0800 |
---|---|---|
committer | John Hodge <tpg@ucc.asn.au> | 2018-06-03 14:57:05 +0800 |
commit | bf8f8b4b4a9fe273451be59f68acafbe61968b83 (patch) | |
tree | 82993550cb3c88de0edbd55d79e4ea8e8cefffac /tools/standalone_miri/lex.cpp | |
parent | 39b3cf53798683e496804f8322da2254b10850f4 (diff) | |
parent | a7fb27789a2b34543851d207120e2c0001ee9c27 (diff) | |
download | mrust-bf8f8b4b4a9fe273451be59f68acafbe61968b83.tar.gz |
Merge branch 'master' of https://github.com/thepowersgang/mrustc
Diffstat (limited to 'tools/standalone_miri/lex.cpp')
-rw-r--r-- | tools/standalone_miri/lex.cpp | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/tools/standalone_miri/lex.cpp b/tools/standalone_miri/lex.cpp index 48a9e0cd..8fc77f7a 100644 --- a/tools/standalone_miri/lex.cpp +++ b/tools/standalone_miri/lex.cpp @@ -11,11 +11,11 @@ bool Token::operator==(TokenClass tc) const } bool Token::operator==(char c) const { - return this->strval.size() == 1 && this->strval[0] == c; + return (this->type == TokenClass::Ident || this->type == TokenClass::Symbol) && this->strval.size() == 1 && this->strval[0] == c; } bool Token::operator==(const char* s) const { - return this->strval == s; + return (this->type == TokenClass::Ident || this->type == TokenClass::Symbol) && this->strval == s; } uint64_t Token::integer() const @@ -56,6 +56,9 @@ double Token::real() const case TokenClass::ByteString: os << "b\"" << x.strval << "\""; break; + case TokenClass::Lifetime: + os << "'" << x.strval << "\""; + break; } return os; } @@ -95,6 +98,7 @@ Token Lexer::consume() auto rv = ::std::move(m_cur); advance(); + //::std::cout << *this << "Lexer::consume " << rv << " -> " << m_cur << ::std::endl; return rv; } @@ -349,6 +353,23 @@ void Lexer::advance() auto val = this->parse_string(); m_cur = Token { TokenClass::String, ::std::move(val) }; } + else if( ch == '\'') + { + ::std::string val; + ch = m_if.get(); + while( ch == '_' || ::std::isalnum(ch) ) + { + val += ch; + ch = m_if.get(); + } + m_if.unget(); + if( val == "" ) + { + ::std::cerr << *this << "Empty lifetime name"; + throw "ERROR"; + } + m_cur = Token { TokenClass::Lifetime, ::std::move(val) }; + } else { switch(ch) @@ -390,6 +411,10 @@ void Lexer::advance() { m_cur = Token { TokenClass::Symbol, "<<" }; } + else if( ch == '=' ) + { + m_cur = Token { TokenClass::Symbol, "<=" }; + } else { m_if.unget(); |