First pass at string interpolation.

Requires a lexer hack, but a surprisingly un-hideous one. The lexer
maintains a stack of bracket characters so that it can match
parens/brackets/braces to tell where a subexp nested in a string
actually ends.
This commit is contained in:
Stephen Dolan committed 2012-09-17 20:41:57 +01:00
1 parent 50ebb036c4
commit 3db27b01a1
2 files changed
+98 -2

No files matched your search

+22 -1
View File
@@ -61,6 +61,12 @@
%token SETDIV "/="
%token SETDEFINEDOR "//="
%token QQSTRING_START
%token <literal> QQSTRING_TEXT
%token QQSTRING_INTERP_START
%token QQSTRING_INTERP_END
%token QQSTRING_END
/* revolting hack */
%left ';'
%left '|'
@@ -74,7 +80,7 @@
%left '*' '/'
%type <blk> Exp Term MkDict MkDictPair ExpD ElseBody
%type <blk> Exp Term MkDict MkDictPair ExpD ElseBody QQString
%{
#include "lexer.yy.h"
#define FAIL(loc, msg) \
@@ -264,11 +270,26 @@ Exp "==" Exp {
$$ = gen_binop($1, $3, EQ);
} |
QQSTRING_START QQString QQSTRING_END {
$$ = $2;
} |
Term {
$$ = $1;
}
QQString:
/* empty */ {
$$ = gen_op_const(LOADK, jv_string(""));
} |
QQString QQSTRING_TEXT {
$$ = gen_binop($1, gen_op_const(LOADK, $2), '+');
} |
QQString QQSTRING_INTERP_START Exp QQSTRING_INTERP_END {
$$ = gen_binop($1, $3, '+');
}
ElseBody:
"elif" Exp "then" Exp ElseBody {