"if" { return IF; }
"then" { return THEN; }
"else" { return ELSE; }
+"elif" { return ELSE_IF; }
"end" { return END; }
"//" { return DEFINEDOR; }
"."|"="|";"|"["|"]"|","|":"|"("|")"|"{"|"}"|"|"|"+"|"\$" { return yytext[0];}
%token IF "if"
%token THEN "then"
%token ELSE "else"
+%token ELSE_IF "elif"
%token END "end"
%right "//"
%nonassoc '=' SETPIPE
%left '+'
-%type <blk> Exp Term MkDict MkDictPair ExpD
+%type <blk> Exp Term MkDict MkDictPair ExpD ElseBody
%{
#include "lexer.yy.h"
jv_free($4);
} |
-"if" Exp "then" Exp "else" Exp "end" {
- $$ = gen_cond($2, $4, $6);
+"if" Exp "then" Exp ElseBody {
+ $$ = gen_cond($2, $4, $5);
} |
Exp '=' Exp {
$$ = $1;
}
+ElseBody:
+"elif" Exp "then" Exp ElseBody {
+ $$ = gen_cond($2, $4, $5);
+} |
+"else" Exp "end" {
+ $$ = $2;
+}
+
ExpD:
ExpD '|' ExpD {
[{"foo":0},{"foo":1},{"foo":[]},{"foo":true},{"foo":false},{"foo":null},{"foo":"foo"},{}]
["yep","yep","yep","yep","nope","nope","yep","nope"]
+[.[] | if .baz then "strange" elif .foo then "yep" else "nope" end]
+[{"foo":0},{"foo":1},{"foo":[]},{"foo":true},{"foo":false},{"foo":null},{"foo":"foo"},{}]
+["yep","yep","yep","yep","nope","nope","yep","nope"]
+
+
# FIXME: define/test behaviour of 'if (.foo,.bar) then A else B end'
[.[] | [.foo[] // .bar]]