diff options
author | John Hodge <tpg@mutabah.net> | 2016-02-25 15:49:42 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2016-02-25 15:49:42 +0800 |
commit | d87ee8e9cf5e867aea7f5dba58781993f35d508e (patch) | |
tree | 3e650f25affba8e09d336451310f238ac2a919c7 /src | |
parent | 5087cc1ef01303c8635fb82d0957ba214b379ca2 (diff) | |
download | mrust-d87ee8e9cf5e867aea7f5dba58781993f35d508e.tar.gz |
Fix raw string lex
Diffstat (limited to 'src')
-rw-r--r-- | src/parse/lex.cpp | 26 | ||||
-rw-r--r-- | src/parse/lex.hpp | 2 |
2 files changed, 21 insertions, 7 deletions
diff --git a/src/parse/lex.cpp b/src/parse/lex.cpp index b5737d30..260ca319 100644 --- a/src/parse/lex.cpp +++ b/src/parse/lex.cpp @@ -567,17 +567,26 @@ Token Lexer::getTokenInt_RawString(bool is_byte) ch = this->getc(); } if( hashes == 0 && ch != '"' ) { - this->ungetc(); - assert( !is_byte ); - return this->getTokenInt_Identifier('r'); + this->ungetc(); // Unget the not '"' + if( is_byte ) + return this->getTokenInt_Identifier('b', 'r'); + else + return this->getTokenInt_Identifier('r'); } char terminator = ch; ::std::string val; + DEBUG("terminator = '" << terminator << "', hashes = " << hashes); unsigned terminating_hashes = 0; for(;;) { - ch = this->getc(); + try { + ch = this->getc(); + } + catch( Lexer::EndOfFile e ) { + throw ParseError::Generic(*this, "EOF reached in raw string"); + } + if( terminating_hashes > 0 ) { assert(terminating_hashes > 0); @@ -585,8 +594,11 @@ Token Lexer::getTokenInt_RawString(bool is_byte) val += terminator; while( terminating_hashes < hashes ) { val += '#'; + terminating_hashes += 1; } terminating_hashes = 0; + + this->ungetc(); } else { terminating_hashes -= 1; @@ -610,10 +622,12 @@ Token Lexer::getTokenInt_RawString(bool is_byte) } return Token(is_byte ? TOK_BYTESTRING : TOK_STRING, val); } -Token Lexer::getTokenInt_Identifier(char leader) +Token Lexer::getTokenInt_Identifier(char leader, char leader2) { - char ch = leader; ::std::string str; + if( leader2 != '\0' ) + str += leader; + char ch = leader2 == '\0' ? leader : leader2; while( issym(ch) ) { str.push_back(ch); diff --git a/src/parse/lex.hpp b/src/parse/lex.hpp index 1b37127e..3607fef0 100644 --- a/src/parse/lex.hpp +++ b/src/parse/lex.hpp @@ -201,7 +201,7 @@ private: signed int getSymbol(); Token getTokenInt_RawString(bool is_byte); - Token getTokenInt_Identifier(char ch); + Token getTokenInt_Identifier(char ch, char ch2='\0'); double parseFloat(uint64_t whole); uint32_t parseEscape(char enclosing); |