Replies: 2 comments 1 reply
-
So with no space
With an (invalid) expression like ".tag | = "foo"' - yq will try to build an expression tree. Now each operator has an implied precedence (kind of like a maths expression, you evaluate
And then it discovers the "|" operator only has one argument, whereas it needs two. |
Beta Was this translation helpful? Give feedback.
-
Yep 👍
…________________________________
From: Armen Michaeli ***@***.***>
Sent: Friday, May 5, 2023 3:15:20 AM
To: mikefarah/yq ***@***.***>
Cc: Mike Farah ***@***.***>; Comment ***@***.***>
Subject: Re: [mikefarah/yq] (Testing own parser to infer grammar) What would `. tag | = "foo"` mean? (Discussion #1657)
Thanks. I think I was asking specifically about the variant . tag | = "foo" (space between . and tag)? It isn't an invalid expression here (yq v4.33.3). Anyway, I suppose the syntactical correctness here generally hinges on the simple fact that both | and = are binary operations -- requiring two operands, one on each side of the operator with an infix notation (that yq uses)?
—
Reply to this email directly, view it on GitHub<#1657 (reply in thread)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AAIZHNI3QLCYWVRJIVM3PV3XEPP2RANCNFSM6AAAAAAXU3WHYE>.
You are receiving this because you commented.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Mind you, the result seems different than if the white-space between the
|
and the=
were removed. Without the white-space, I understand there's the|=
operator, which has the effect of assigning "foo" as the value of the tag (using context of either the tag, if that even makes sense, or.
, at the right hand side of the assignment).With the white-space there, however, I don't understand what kind of expression I wrote, and the
-v
switch toyq
doesn't seem to help me much, except some indication that it is no longer the equivalent of the|=
operator being used, but rather the pipe (|
) operator and the plain assignment (=
) operator.Can someone please shed some light on the difference between the two expression variants (with and without white-space), and what the one with the white-space between the
|
and the=
, means? I understand also that some explicit parentheses might make it clear, but I am also not sure about the arity of the different operators in use here. E.g. if I were to rewrite the expression as(. tag |) = "foo"
I believe it's equivalent of the variant where the parentheses were removed (without any other change, in particular to the white-space), but that doesn't make it much more clear what kind of parse tree or expression I am looking at.Beta Was this translation helpful? Give feedback.
All reactions