diff options
author | Stephen Dolan <mu@netsoc.tcd.ie> | 2013-05-13 20:16:19 +0100 |
---|---|---|
committer | Stephen Dolan <mu@netsoc.tcd.ie> | 2013-05-13 20:16:19 +0100 |
commit | 33901b74b16ce037c732d7a33444862d93c91065 (patch) | |
tree | 3bdbf1472b31187a665dd7b601f04ad869473b49 /parser.y | |
parent | a47cfa475700469d0ea0e7a7c80c5fef8690ac3f (diff) |
Array slicing. Closes #2.
Diffstat (limited to 'parser.y')
-rw-r--r-- | parser.y | 20 |
1 files changed, 20 insertions, 0 deletions
@@ -141,6 +141,17 @@ static block gen_index(block obj, block key) { return BLOCK(gen_subexp(key), obj, gen_op_simple(INDEX)); } +static block gen_slice_index(block obj, block start, block end) { + block key = BLOCK(gen_subexp(gen_const(jv_object())), + gen_subexp(gen_const(jv_string("start"))), + gen_subexp(start), + gen_op_simple(INSERT), + gen_subexp(gen_const(jv_string("end"))), + gen_subexp(end), + gen_op_simple(INSERT)); + return BLOCK(key, obj, gen_op_simple(INDEX)); +} + static block gen_binop(block a, block b, int op) { const char* funcname = 0; switch (op) { @@ -408,6 +419,15 @@ Term '[' Exp ']' { Term '[' ']' { $$ = block_join($1, gen_op_simple(EACH)); } | +Term '[' Exp ':' Exp ']' { + $$ = gen_slice_index($1, $3, $5); +} | +Term '[' Exp ':' ']' { + $$ = gen_slice_index($1, $3, gen_const(jv_null())); +} | +Term '[' ':' Exp ']' { + $$ = gen_slice_index($1, gen_const(jv_null()), $4); +} | LITERAL { $$ = gen_const($1); } | |