Kaynağa Gözat

Accept two or more consecutive strings as one like in C/C++

mingodad 8 yıl önce
ebeveyn
işleme
e4650598a8
1 değiştirilmiş dosya ile 22 ekleme ve 2 silme
  1. 22 2
      SquiLu/squirrel/sqcompiler.cpp

+ 22 - 2
SquiLu/squirrel/sqcompiler.cpp

@@ -1288,9 +1288,29 @@ public:
 		_es.etype = EXPR;
 		switch(_token)
 		{
-		case TK_STRING_LITERAL:
-			_fs->AddInstruction(_OP_LOAD, _fs->PushTarget(), _fs->GetConstant(_fs->CreateString(_lex.data->svalue,_lex.data->longstr.size()-1)));
+		case TK_STRING_LITERAL: {
+			SQInteger lhtk = _lex.LookaheadLex();
+			if(lhtk == TK_STRING_LITERAL) //C/C++ two consecutive strings
+			{
+				SQCharBuf buf;
+				//save the current string
+				buf.append(_lex.data->svalue,_lex.data->longstr.size()-1);
+				while(lhtk == TK_STRING_LITERAL)
+				{
+					Lex(); //get lookahead token
+					buf.append(_lex.data->svalue,_lex.data->longstr.size()-1);
+					lhtk = _lex.LookaheadLex();
+				}
+				_fs->AddInstruction(_OP_LOAD, _fs->PushTarget(), _fs->GetConstant(
+					_fs->CreateString(buf.data(),buf.size())));
+			}
+			else
+			{
+				_fs->AddInstruction(_OP_LOAD, _fs->PushTarget(), _fs->GetConstant(
+					_fs->CreateString(_lex.data->svalue,_lex.data->longstr.size()-1)));
+			}
 			Lex();
+			}
 			break;
 		case TK_BASE:
 			Lex();