Support "if" without "else" clause

Defaults the else clause to the identity filter "." if an else clause is
missing.

The following two jq programs are considered equivalent:

```
if .foo then
    .foo = "bar"
else
    .
end
```

```
if .foo then
    .foo = "bar"
end
```
This commit is contained in:
Chance Zibolski authored and Nico Williams committed 2019-02-20 20:03:26 -06:00
1 parent 1ef90acb38
commit 4f6045a94e
4 files changed
+1092 -1057

No files matched your search

+6 -6
View File
@@ -1,8 +1,8 @@
/* A Bison parser, made by GNU Bison 3.0.4. */
/* A Bison parser, made by GNU Bison 3.0.5. */
/* Bison interface for Yacc-like parsers in C
Copyright (C) 1984, 1989-1990, 2000-2015 Free Software Foundation, Inc.
Copyright (C) 1984, 1989-1990, 2000-2015, 2018 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -40,7 +40,7 @@
extern int yydebug;
#endif
/* "%code requires" blocks. */
#line 11 "src/parser.y" /* yacc.c:1909 */
#line 11 "src/parser.y" /* yacc.c:1910 */
#include "locfile.h"
struct lexer_param;
@@ -57,7 +57,7 @@ struct lexer_param;
} \
} while (0)
#line 61 "src/parser.h" /* yacc.c:1909 */
#line 61 "src/parser.h" /* yacc.c:1910 */
/* Token type. */
#ifndef YYTOKENTYPE
@@ -163,12 +163,12 @@ struct lexer_param;
union YYSTYPE
{
#line 31 "src/parser.y" /* yacc.c:1909 */
#line 31 "src/parser.y" /* yacc.c:1910 */
jv literal;
block blk;
#line 172 "src/parser.h" /* yacc.c:1909 */
#line 172 "src/parser.h" /* yacc.c:1910 */
};
typedef union YYSTYPE YYSTYPE;