1
0
mirror of https://github.com/stedolan/jq.git synced 2024-05-11 05:55:39 +00:00

Make "not" a builtin function rather than syntax.

Fixes a really awkward grammar issue.
This commit is contained in:
Stephen Dolan
2012-09-17 21:08:43 +01:00
parent 297a0679d1
commit 830610cef8
6 changed files with 10 additions and 14 deletions

View File

@ -159,6 +159,12 @@ static block j_null() {
gen_op_simple(RET)));
}
static block j_not() {
return gen_op_block_defn(CLOSURE_CREATE, "not",
block_join(gen_condbranch(gen_op_const(LOADK, jv_false()),
gen_op_const(LOADK, jv_true())),
gen_op_simple(RET)));
}
static struct cfunction function_list[] = {
{f_plus, "_plus", CALL_BUILTIN_3_1},
@ -179,6 +185,7 @@ static bytecoded_builtin bytecoded_builtins[] = {
j_false,
j_true,
j_null,
j_not,
};

View File

@ -361,7 +361,7 @@ block gen_definedor(block a, block b) {
return c;
}
static block gen_condbranch(block iftrue, block iffalse) {
block gen_condbranch(block iftrue, block iffalse) {
block b = gen_noop();
block_append(&iftrue, gen_op_target(JUMP, iffalse));
block_append(&b, gen_op_target(JUMP_F, iftrue));
@ -398,11 +398,6 @@ block gen_or(block a, block b) {
return code;
}
block gen_not(block a) {
return block_join(a, gen_condbranch(gen_op_const(LOADK, jv_false()),
gen_op_const(LOADK, jv_true())));
}
block gen_cond(block cond, block iftrue, block iffalse) {
block b = gen_op_simple(DUP);
block_append(&b, cond);

View File

@ -32,9 +32,9 @@ block gen_both(block a, block b);
block gen_collect(block expr);
block gen_assign(block expr);
block gen_definedor(block a, block b);
block gen_condbranch(block iftrue, block iffalse);
block gen_and(block a, block b);
block gen_or(block a, block b);
block gen_not(block a);
block gen_cond(block cond, block iftrue, block iffalse);

View File

@ -40,7 +40,6 @@
"elif" { return ELSE_IF; }
"and" { return AND; }
"or" { return OR; }
"not" { return NOT; }
"end" { return END; }
"//" { return DEFINEDOR; }
"|=" { return SETPIPE; }

View File

@ -53,7 +53,6 @@
%token END "end"
%token AND "and"
%token OR "or"
%token NOT "not"
%token SETPIPE "|="
%token SETPLUS "+="
%token SETMINUS "-="
@ -210,10 +209,6 @@ Exp "and" Exp {
$$ = gen_and($1, $3);
} |
"not" Exp {
$$ = gen_not($2);
} |
Exp "//" Exp {
$$ = gen_definedor($1, $3);
} |

View File

@ -331,6 +331,6 @@ def inc(x): x |= .+1; inc(.[].a)
[false,true]
[false,false]
[.[] | not .]
[.[] | not]
[1,0,false,null,true,"hello"]
[false,false,true,true,false,false]