From 6fb0ba8539b54642c96d8f0d45c3bf812a316ec7 Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Sun, 14 Sep 2014 08:09:02 +1000 Subject: Support LSL multi line strings. --- src/LuaSL/LuaSL_LSL_tree.h | 3 ++- src/LuaSL/LuaSL_compile.c | 11 ++++++++++- src/LuaSL/LuaSL_lemon_yaccer.y | 3 ++- src/LuaSL/LuaSL_lexer.l | 2 ++ 4 files changed, 16 insertions(+), 3 deletions(-) (limited to 'src/LuaSL') diff --git a/src/LuaSL/LuaSL_LSL_tree.h b/src/LuaSL/LuaSL_LSL_tree.h index 3b0a6d5..dd15bed 100644 --- a/src/LuaSL/LuaSL_LSL_tree.h +++ b/src/LuaSL/LuaSL_LSL_tree.h @@ -144,7 +144,8 @@ typedef enum MF_POSTDEC = 64, MF_POSTINC = 128, MF_LSLCONST = 256, - MF_TYPECAST = 512 + MF_TYPECAST = 512, + MF_MSTRING = 1024 } miscFlags; struct _allowedTypes diff --git a/src/LuaSL/LuaSL_compile.c b/src/LuaSL/LuaSL_compile.c index 9d6834d..ecc61bd 100644 --- a/src/LuaSL/LuaSL_compile.c +++ b/src/LuaSL/LuaSL_compile.c @@ -105,6 +105,7 @@ LSL_Token LSL_Tokens[] = {LSL_KEY, ST_NONE, "key", LSL_NONE, outputStringToken}, {LSL_LIST, ST_NONE, "list", LSL_NONE, outputListToken}, {LSL_ROTATION, ST_NONE, "rotation", LSL_NONE, outputListToken}, + {LSL_MSTRING, ST_NONE, "string", LSL_NONE, outputStringToken}, {LSL_STRING, ST_NONE, "string", LSL_NONE, outputStringToken}, {LSL_VECTOR, ST_NONE, "vector", LSL_NONE, outputListToken}, @@ -2184,7 +2185,15 @@ static void outputStatementToken(FILE *file, outputMode mode, LSL_Leaf *content) static void outputStringToken(FILE *file, outputMode mode, LSL_Leaf *content) { if (content) - fprintf(file, "%s", content->value.stringValue); // The quotes are part of the string value already. + { + if (MF_MSTRING & content->flags) + { + // TODO - LSL might ignore leading spaces in later lines, but does Lua? + fprintf(file, "[=[%.*s]=]", (int) strlen(content->value.stringValue) - 2, &content->value.stringValue[1]); + } + else + fprintf(file, "%s", content->value.stringValue); // The quotes are part of the string value already. + } } boolean compilerSetup(gameGlobals *ourGlobals) diff --git a/src/LuaSL/LuaSL_lemon_yaccer.y b/src/LuaSL/LuaSL_lemon_yaccer.y index 5ddf45a..9d507c9 100644 --- a/src/LuaSL/LuaSL_lemon_yaccer.y +++ b/src/LuaSL/LuaSL_lemon_yaccer.y @@ -216,7 +216,8 @@ expr(A) ::= LSL_BRACKET_OPEN(L) exprList(E) LSL_BRACKET_CLOSE(R). [LSL_BRACKET_O %nonassoc LSL_ROTATION LSL_VECTOR. // Uses the same symbol for less than, greater than, and the rotation / vector delimiters. expr(A) ::= LSL_LESS_THAN(L) exprList(E) LSL_GREATER_THAN(R). [LSL_ANGLE_OPEN] { A = addRotVec(L, E, R); } -%nonassoc LSL_STRING. +%nonassoc LSL_MSTRING LSL_STRING. +expr(A) ::= LSL_MSTRING(B). { B->basicType = OT_string; B->flags |= MF_MSTRING; A = B; } expr(A) ::= LSL_STRING(B). { B->basicType = OT_string; A = B; } diff --git a/src/LuaSL/LuaSL_lexer.l b/src/LuaSL/LuaSL_lexer.l index 9d58899..248ba3e 100644 --- a/src/LuaSL/LuaSL_lexer.l +++ b/src/LuaSL/LuaSL_lexer.l @@ -27,6 +27,7 @@ IDENTIFIER (_|[[:alpha:]])(_|[[:alpha:]]|[[:digit:]])* CHAR '(\\.|[^\\'\n])+' KEY \"{HEX}{8}-{HEX}{4}-{HEX}{4}-{HEX}{4}-{HEX}{12}\" STRING \"(\\.|[^\\"\n])*\" +MSTRING \"(\\.|[^\\"])*\" %% @@ -109,6 +110,7 @@ STRING \"(\\.|[^\\"\n])*\" {FLOAT} %{ yylval->value.stringValue = eina_stringshare_add_length(yytext, yyleng); return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_FLOAT); %} {KEY} %{ yylval->value.stringValue = eina_stringshare_add_length(yytext, yyleng); return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_KEY); %} {STRING} %{ yylval->value.stringValue = eina_stringshare_add_length(yytext, yyleng); return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_STRING); %} +{MSTRING} %{ yylval->value.stringValue = eina_stringshare_add_length(yytext, yyleng); return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_MSTRING); %} <> { return common(yylval, yytext, yyleng, yyextra, TRUE, LSL_SCRIPT); } -- cgit v1.1