From eddcbab76c3c23bd211de322f551865f35bf8d40 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sat, 27 Feb 2016 13:59:43 +0800 Subject: Parse/lex - Handle nested block comments --- src/parse/lex.cpp | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) (limited to 'src/parse/lex.cpp') 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: { -- cgit v1.2.3