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 .a.[] and .a.[]? each syntax #2650

Merged
merged 1 commit into from
Jul 9, 2023

Conversation

wader
Copy link
Member

@wader wader commented Jul 3, 2023

Fixes #1699

} |
Term '.' '[' ']' %prec NONOPT {
$$ = block_join($1, gen_op_simple(EACH));
} |
Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe there a nice way? some concerns:

  • I'm a bit bit confused how the chaining/suffix-list thing actually works in the grammar, what rule allows for the chaining?
  • Does the new rules allow for some syntax that we don't want?

Copy link
Member Author

Choose a reason for hiding this comment

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

We should probably also support slice syntax? .a.[1:2]. Looking at the grammar the slice stuff has lots of rules. Wondering if there is some nice way to add optional dot without duplicating all the rules?

Copy link
Contributor

Choose a reason for hiding this comment

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

I second @wader's comment.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm a bit bit confused how the chaining/suffix-list thing actually works in the grammar, what rule allows for the chaining?

This one:

Exp '|' Exp {
  $$ = block_join($1, $3);
} |

and:

Exp:
FuncDef Exp %prec FUNCDEF {
  $$ = block_bind_referenced($1, $2, OP_IS_CALL_PSEUDO);
} |
... /* elided */
Term {
  $$ = $1;
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Does the new rules allow for some syntax that we don't want?

I don't think so.

@wader wader marked this pull request as draft July 4, 2023 16:01
@nicowilliams
Copy link
Contributor

I mean, .a.[0] is... ugly, but I admit that I too sometimes typo this and that it's very natural to typo it, so maybe, yeah, it should work and in the obvious way...

@wader
Copy link
Member Author

wader commented Jul 5, 2023

I mean, .a.[0] is... ugly, but I admit that I too sometimes typo this and that it's very natural to typo it, so maybe, yeah, it should work and in the obvious way...

Yeap looks a bit weird :) the main reason for me is mostly to make things more consistent now when .a.[0] (and .a.[{start:1,end:2}]) is allowed.

@nicowilliams
Copy link
Contributor

Oh. Interesting, I hadn't noticed that we allow that now. Yeah, I agree that if we're going to allow .a.[0] then we should allow all forms of .[].

@pkoppstein
Copy link
Contributor

I believe this PR also in effect addresses the concerns expressed in #2512

@nicowilliams nicowilliams marked this pull request as ready for review July 9, 2023 15:08
@nicowilliams
Copy link
Contributor

LGTM

@nicowilliams nicowilliams merged commit ab1a681 into jqlang:master Jul 9, 2023
14 checks passed
@nicowilliams
Copy link
Contributor

Thanks!

} |
Term '.' '[' ']' %prec NONOPT {
$$ = block_join($1, gen_op_simple(EACH));
} |
Term '[' Exp ':' Exp ']' '?' {
$$ = gen_slice_index($1, $3, $5, INDEX_OPT);
} |
Copy link
Member Author

Choose a reason for hiding this comment

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

@nicowilliams Sorry i should have marked this PR as draft as i think we probably want to support extra dot with all the different slice variants? also probably good with some basic tests for it. Then also thinking if there is some nicer way to write the rules that don't need as much duplication?

Copy link
Contributor

Choose a reason for hiding this comment

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

We can always add that later.

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.

.foo.[] is a syntax error (but not .foo | .[] or .foo[])
3 participants