diff options
author | Stephen Dolan <mu@netsoc.tcd.ie> | 2012-12-03 20:31:40 +0000 |
---|---|---|
committer | Stephen Dolan <mu@netsoc.tcd.ie> | 2012-12-03 20:31:40 +0000 |
commit | a88d53d2fda9a755c9c972a09a1206d54ca0d8b2 (patch) | |
tree | 5e9d45ab2e96fa8a96a69b00231dcc5cadd492f6 | |
parent | 5f6a95c7b574c6d0f52e62e2405c550606a5ce75 (diff) |
Extend `{foo}` syntax to allow `{"foo"}` as well.
Useful when "foo" contains unusual characters. Should help with
the issues #7, #38, #40, #42.
-rw-r--r-- | execute.c | 11 | ||||
-rw-r--r-- | opcode_list.h | 1 | ||||
-rw-r--r-- | parser.y | 4 | ||||
-rw-r--r-- | testdata | 4 |
4 files changed, 20 insertions, 0 deletions
@@ -208,6 +208,17 @@ jv jq_next() { break; } + case DUP2: { + stackval keep = stack_pop(); + stackval v = stack_pop(); + stackval v2 = v; + v2.value = jv_copy(v.value); + stack_push(v); + stack_push(keep); + stack_push(v2); + break; + } + case SWAP: { stackval a = stack_pop(); stackval b = stack_pop(); diff --git a/opcode_list.h b/opcode_list.h index a39d30e0..03cdbc8b 100644 --- a/opcode_list.h +++ b/opcode_list.h @@ -1,5 +1,6 @@ OP(LOADK, CONSTANT, 1, 1) OP(DUP, NONE, 1, 2) +OP(DUP2, NONE, 2, 3) OP(SWAP, NONE, 2, 2) OP(POP, NONE, 1, 0) OP(LOADV, VARIABLE, 1, 1) @@ -414,6 +414,10 @@ MkDictPair | String ':' ExpD { $$ = gen_dictpair($1, $3); } +| String { + $$ = gen_dictpair($1, BLOCK(gen_op_simple(POP), gen_op_simple(DUP2), + gen_op_simple(DUP2), gen_op_simple(INDEX))); + } | IDENT { $$ = gen_dictpair(gen_const(jv_copy($1)), gen_index(gen_noop(), gen_const($1))); @@ -64,6 +64,10 @@ null {"a":1, "b":2, "c":3, "d":"c"} {"a":1, "b":2, "c":1, "e":2} +{"a",b,"a$\(1+1)"} +{"a":1, "b":2, "c":3, "a$2":4} +{"a":1, "b":2, "a$2":4} + # # Field access, piping # |