Add a Boolean "not" operator.
Not wholly convinced this is a good idea, maybe "not" should be a builtin function instead? 'not (.a == .b)' vs. '.a == .b | not'
This commit is contained in:
1 parent
6e6ea50763
commit
da5d653de8
5 files changed
+16
-1
No files matched your search
+5
-1
@@ -383,7 +383,11 @@ block gen_or(block a, block b) {
|
|||||||
block_append(&code, gen_condbranch(block_join(gen_op_simple(POP), gen_op_const(LOADK, jv_true())),
|
block_append(&code, gen_condbranch(block_join(gen_op_simple(POP), gen_op_const(LOADK, jv_true())),
|
||||||
if_a_false));
|
if_a_false));
|
||||||
return code;
|
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 gen_cond(block cond, block iftrue, block iffalse) {
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ block gen_assign(block expr);
|
|||||||
block gen_definedor(block a, block b);
|
block gen_definedor(block a, block b);
|
||||||
block gen_and(block a, block b);
|
block gen_and(block a, block b);
|
||||||
block gen_or(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);
|
block gen_cond(block cond, block iftrue, block iffalse);
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
"elif" { return ELSE_IF; }
|
"elif" { return ELSE_IF; }
|
||||||
"and" { return AND; }
|
"and" { return AND; }
|
||||||
"or" { return OR; }
|
"or" { return OR; }
|
||||||
|
"not" { return NOT; }
|
||||||
"end" { return END; }
|
"end" { return END; }
|
||||||
"//" { return DEFINEDOR; }
|
"//" { return DEFINEDOR; }
|
||||||
"."|"="|";"|"["|"]"|","|":"|"("|")"|"{"|"}"|"|"|"+"|"\$" { return yytext[0];}
|
"."|"="|";"|"["|"]"|","|":"|"("|")"|"{"|"}"|"|"|"+"|"\$" { return yytext[0];}
|
||||||
|
|||||||
@@ -36,6 +36,7 @@
|
|||||||
%token END "end"
|
%token END "end"
|
||||||
%token AND "and"
|
%token AND "and"
|
||||||
%token OR "or"
|
%token OR "or"
|
||||||
|
%token NOT "not"
|
||||||
%right "//"
|
%right "//"
|
||||||
%nonassoc '=' SETPIPE
|
%nonassoc '=' SETPIPE
|
||||||
%nonassoc EQ
|
%nonassoc EQ
|
||||||
@@ -111,6 +112,10 @@ Exp "and" Exp {
|
|||||||
$$ = gen_and($1, $3);
|
$$ = gen_and($1, $3);
|
||||||
} |
|
} |
|
||||||
|
|
||||||
|
"not" Exp {
|
||||||
|
$$ = gen_not($2);
|
||||||
|
} |
|
||||||
|
|
||||||
Exp "//" Exp {
|
Exp "//" Exp {
|
||||||
$$ = gen_definedor($1, $3);
|
$$ = gen_definedor($1, $3);
|
||||||
} |
|
} |
|
||||||
|
|||||||
@@ -260,3 +260,7 @@ def inc(x): x |= .+1; inc(.[].a)
|
|||||||
[false,true]
|
[false,true]
|
||||||
[false,true]
|
[false,true]
|
||||||
[false,false]
|
[false,false]
|
||||||
|
|
||||||
|
[.[] | not .]
|
||||||
|
[1,0,false,null,true,"hello"]
|
||||||
|
[false,false,true,true,false,false]
|
||||||
Reference in new issue
Block a user