summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2016-02-27 13:59:43 +0800
committerJohn Hodge <tpg@mutabah.net>2016-02-27 13:59:43 +0800
commiteddcbab76c3c23bd211de322f551865f35bf8d40 (patch)
tree1b61414493796aa2d826b7e213c1e18f5e230787 /src
parent8e2c8a5513215581d0caae3ab45272f240a956e8 (diff)
downloadmrust-eddcbab76c3c23bd211de322f551865f35bf8d40.tar.gz
Parse/lex - Handle nested block comments
Diffstat (limited to 'src')
-rw-r--r--src/parse/lex.cpp33
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: {