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

emit statement not working as expected in mlr 6.0 #827

Closed
vapniks opened this issue Jan 3, 2022 · 6 comments
Closed

emit statement not working as expected in mlr 6.0 #827

vapniks opened this issue Jan 3, 2022 · 6 comments

Comments

@vapniks
Copy link
Contributor

vapniks commented Jan 3, 2022

This works fine with miller 5.3.0:

mlr -n put 'end {@in={"a":1}; emit @in["a"]}'

but gives the following error with the latest miller 6.0.0-rc (0b71298):

mlr: cannot parse DSL expression.
Parse error on token "[" at line 1 columnn 27.
Please check for missing semicolon.
Expected one of:
  ; } ,
@johnkerl
Copy link
Owner

johnkerl commented Jan 5, 2022

Hi @vapniks --

Bit of a story here.

emit goes way back early on in Miller, even before there were control structures like for loops. I put (in hindsight) too much syntactic complexity into emit, which wouldn't have been necessary if there had been other things like for loops.

The grammar is more complex in Miller 6, and I'm using a different parser-generator, without shift-reduce-conflict hacks in my use of it (I hope I'm not over-jargoning). At this point, allowing emit of indexed things is no longer possible in the grammar without either introducing shift-reduce conflicts (i.e. a parser-generator cannot be built for the grammar), or perhaps introducing new emit syntax.

What I think is the best (or perhaps least-bad) course is to more clearly document at
https://miller.readthedocs.io/en/latest/reference-dsl-output-statements/#emit1-and-emitemitpemitf
that we can't emit indexed oosvars now, and to document a suggested replacement of the form

$ mlr -n put 'end {@in={"a":1}; @ina = @in["a"]; emit @ina}'
ina=1

at https://miller.readthedocs.io/en/latest/new-in-miller-6/.

What do you think?

@johnkerl
Copy link
Owner

johnkerl commented Jan 9, 2022

@vapniks updated advice:

$ mlr5 -n put 'end {@in={"a":1}; emit @in["a"]}'
in=1

$ mlr -n put 'end {@in={"a":1}; emit1 {"in":@in["a"]}}'
in=1

@vapniks
Copy link
Contributor Author

vapniks commented Jan 10, 2022

Yes, sounds OK to me. However the example you give for mlr5 also works with mlr 6:

$ mlr -n put 'end {@in={"a":1}; emit {"in":@in["a"]}}'
in
1

Maybe also include this example which works with mlr5 but not mlr 6:

$ mlr -n put 'end {@in={"a":1}; emit @in["a"]}' 
mlr: cannot parse DSL expression.
Parse error on token "[" at line 1 columnn 27.
Please check for missing semicolon.
Expected one of:
  ; } ,

Btw, there's a typo in the above output: it should be "column" not "columnn".
I also noticed a couple of minor typos in the documentation. I've submitted some pull requests to fix them.

@johnkerl
Copy link
Owner

Sorry @vapniks I wasn't clear

mlr -n put 'end {@in={"a":1}; emit @in["a"]}' 

This works in Miller 5 but not Miller 6, and it won't. I'll make it clear that this syntax is no longer supported.

$ mlr -n put 'end {@in={"a":1}; emit {"in":@in["a"]}}'

Yes, this works in Miller 5 & 6. I'll make it clear that this is the suggested workaround for the previous.

johnkerl added a commit that referenced this issue Jan 11, 2022
@johnkerl johnkerl mentioned this issue Jan 11, 2022
johnkerl added a commit that referenced this issue Jan 11, 2022
* Conda/Docker install notes

* Clarify wording for #827
@johnkerl
Copy link
Owner

#858

Thanks again @vapniks ! :)

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

No branches or pull requests

2 participants