diff options
author | John Hodge <tpg@mutabah.net> | 2016-02-27 13:59:43 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2016-02-27 13:59:43 +0800 |
commit | eddcbab76c3c23bd211de322f551865f35bf8d40 (patch) | |
tree | 1b61414493796aa2d826b7e213c1e18f5e230787 /src | |
parent | 8e2c8a5513215581d0caae3ab45272f240a956e8 (diff) | |
download | mrust-eddcbab76c3c23bd211de322f551865f35bf8d40.tar.gz |
Parse/lex - Handle nested block comments
Diffstat (limited to 'src')
-rw-r--r-- | src/parse/lex.cpp | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/src/parse/lex.cpp b/src/parse/lex.cpp index 96b04ae3..5289dd31 100644 --- a/src/parse/lex.cpp +++ b/src/parse/lex.cpp @@ -508,15 +508,38 @@ Token Lexer::getTokenInt() return Token(TOK_COMMENT, str); } case BLOCKCOMMENT: { ::std::string str; + unsigned int level = 0; while(true) { - if( ch == '*' ) { + ch = this->getc(); + + if( ch == '/' ) { + str.push_back(ch); ch = this->getc(); - if( ch == '/' ) break; - this->ungetc(); + if( ch == '*' ) { + level ++; + } + str.push_back(ch); + } + else { + if( ch == '*' ) { + ch = this->getc(); + if( ch == '/' ) { + if( level == 0 ) + break; + level --; + str.push_back('*'); + str.push_back('/'); + } + else { + str.push_back('*'); + str.push_back(ch); + } + } + else { + str.push_back(ch); + } } - str.push_back(ch); - ch = this->getc(); } return Token(TOK_COMMENT, str); } case SINGLEQUOTE: { |