Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support "if" without "else" clause #1825

Merged
merged 3 commits into from
Feb 21, 2019

Conversation

chancez
Copy link
Contributor

@chancez chancez commented Feb 15, 2019

This implements #1824. I decided to take a stab at it to see how difficult it
was, and it wasn't so difficult. Currently this PR only contains changes to the
yacc file because my yacc is quite newer and I'm seeing a lot of extraneous
changes to the parser.c and parser.h files.

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

Closes #1824

@coveralls
Copy link

coveralls commented Feb 15, 2019

Coverage Status

Coverage increased (+0.4%) to 84.972% when pulling 6c73fae on chancez:optional_else_branch into e843a4f on stedolan:master.

@chancez
Copy link
Contributor Author

chancez commented Feb 15, 2019

I'm having troubles compiling bison 3.0.4 on my Mac, but I did manage to run the build in a fedora container with bison 3.0.5.

I basically added all the changes and removed the updates to YYBISON_VERSION and the comment headers at the top updating the copyright dates. I can't be 100% sure the other changes are the same as 3.0.5, but someone else with bison 3.0.4 could give it a try.

@chancez
Copy link
Contributor Author

chancez commented Feb 15, 2019

Looks like failures are related to bundler missing in some environments, and one failed tests/shtest, but I'm not sure if that's related.

src/parser.y Outdated
@@ -357,9 +357,8 @@ Term "as" Patterns '|' Exp {
"if" Exp "then" Exp ElseBody {
$$ = gen_cond($2, $4, $5);
} |
"if" Exp "then" error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we still want to retain an error case though, for when the end token is missing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in latest commit. (Can squash when everything looks good)

@nicowilliams
Copy link
Contributor

@chancez LGTM. Please squash. Do also please update the docs (and squash that too), then I'll merge.

1 similar comment
@nicowilliams
Copy link
Contributor

@chancez LGTM. Please squash. Do also please update the docs (and squash that too), then I'll merge.

@chancez
Copy link
Contributor Author

chancez commented Feb 20, 2019

Ok, I'll try to get to that later in the week when I have some more time.

Chance Zibolski and others added 3 commits February 20, 2019 19:44
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
```
@nicowilliams
Copy link
Contributor

@chancez I've squash/rebased, added a commit for docs, and pushed to your branch. I'll merge shortly.

@nicowilliams nicowilliams merged commit 048acee into jqlang:master Feb 21, 2019
@nicowilliams
Copy link
Contributor

Thanks!

@chancez
Copy link
Contributor Author

chancez commented Feb 21, 2019

Awesome thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants