Changeset 221


Ignore:
Timestamp:
04/11/14 23:37:17 (10 years ago)
Author:
Maciej Komosinski
Message:

"here document" in framscript, ​http://www.framsticks.com/common/script/framscript-lang.html#heredoc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/vm/framscript.l

    r163 r221  
    1111#define YY_NEVER_INTERACTIVE 1
    1212
     13static SString quoteDoubleQuotes(const SString &src);
     14
    1315%}
    1416
     
    1719%x asmcode2
    1820%x comment
     21%x heredoc
    1922
    2023%%
     
    2831"null"            {framscriptlval.setEmpty(); return CONSTANT;}
    2932\"([^\\\"]|\\.)*\" {framscriptlval.setString(SString(yytext+1,yyleng-2));return CONSTANT;}
     33"<<<".*\n            {trctx.herelimit=SString(yytext+3,yyleng-4); trctx.tmp=""; BEGIN heredoc; }
    3034"@line "[0-9]+\n   {trctx.line=atol(yytext+6);}
    3135"@file "[^\n\t\r]+\n {trctx.srcname=SString(yytext+6,yyleng-7);}
     
    6771<comment>\*\/       BEGIN 0;
    6872<comment>.          ;
    69 
     73<heredoc>[^\n]*\n   {
     74                    trctx.line++;
     75                    SString tmp(yytext,yyleng-1);
     76                    if (tmp==trctx.herelimit)
     77                        { framscriptlval.setString(quoteDoubleQuotes(trctx.tmp)); BEGIN 0; return CONSTANT;}
     78                    else
     79                        { trctx.tmp+=tmp; trctx.tmp+="\n";}
     80                    }
    7081[ \t\r\f]           ;
    7182\n                  {trctx.line++;}
     
    90101
    91102%%
     103
     104//exclusively for heredoc, but it should not be needed, there is some unexpected difference between quoting \n and \" in framscript parsing (TODO)
     105static SString quoteDoubleQuotes(const SString &src)
     106{
     107int len=src.len();
     108SString ret((len*11)/10+10);
     109const char*t=(const char*)src;
     110while(len>0)
     111        {
     112        if (*t=='\"')
     113                ret+="\\\"";
     114        else
     115                 ret+=*t;
     116        t++; len--;
     117        }
     118return ret;
     119}
     120
    92121void framscript_init_lex()
    93122{
Note: See TracChangeset for help on using the changeset viewer.