diff options
author | Stephen Dolan <mu@netsoc.tcd.ie> | 2012-12-27 20:49:34 +0000 |
---|---|---|
committer | Stephen Dolan <mu@netsoc.tcd.ie> | 2012-12-28 01:23:09 +0000 |
commit | 89e26969ae5bc7a259c1bd150f4d58c67800424b (patch) | |
tree | 908889d2831cb91e117859c828b28ba81c6adec6 /parser.y | |
parent | 52db8000c6e0564e92fdba72687e338dc603e02d (diff) |
@foo syntax for encoding of strings into various formats.
Fixes part of #47 and #48.
Diffstat (limited to 'parser.y')
-rw-r--r-- | parser.y | 20 |
1 files changed, 15 insertions, 5 deletions
@@ -48,6 +48,7 @@ struct lexer_param; %token INVALID_CHARACTER %token <literal> IDENT %token <literal> LITERAL +%token <literal> FORMAT %token EQ "==" %token NEQ "!=" %token DEFINEDOR "//" @@ -158,8 +159,8 @@ static block gen_binop(block a, block b, int op) { return gen_call(funcname, BLOCK(gen_lambda(a), gen_lambda(b))); } -static block gen_format(block a) { - return BLOCK(a, gen_call("tostring", gen_noop())); +static block gen_format(block a, jv fmt) { + return BLOCK(a, gen_call("format", BLOCK(gen_lambda(gen_const(fmt))))); } static block gen_update(block a, block op, int optype) { @@ -316,10 +317,16 @@ FuncDef: String: -QQSTRING_START QQString QQSTRING_END { - $$ = $2; +QQSTRING_START { $<literal>$ = jv_string("text"); } QQString QQSTRING_END { + $$ = $3; + jv_free($<literal>2); +} | +FORMAT QQSTRING_START { $<literal>$ = $1; } QQString QQSTRING_END { + $$ = $4; + jv_free($<literal>3); } + QQString: /* empty */ { $$ = gen_const(jv_string("")); @@ -328,7 +335,7 @@ QQString QQSTRING_TEXT { $$ = gen_binop($1, gen_const($2), '+'); } | QQString QQSTRING_INTERP_START Exp QQSTRING_INTERP_END { - $$ = gen_binop($1, gen_format($3), '+'); + $$ = gen_binop($1, gen_format($3, jv_copy($<literal>0)), '+'); } @@ -373,6 +380,9 @@ LITERAL { String { $$ = $1; } | +FORMAT { + $$ = gen_format(gen_noop(), $1); +} | '(' Exp ')' { $$ = $2; } | |