-
Notifications
You must be signed in to change notification settings - Fork 453
Questions and errors in the spec #804
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
Comments
Thanks for catching this. I think you're right. The second and third expr should be marked as optional. And I think the second rule is going to be redundant then. We support all the variants you mentioned. We even have rewriting rules for desugaring them in the next section of the spec: @sparkprime Is that correct? @Alxandr If you feel like contributing to Jsonnet documentation, this snippet comes from here: https://github.com/google/jsonnet/blob/v0.15.0/doc/ref/spec.html#L328. That's completely optional ofc. If not, I'll do it myself later. |
I'm currently busy porting the whole thing to rust (for fun), so maybe after xD. Gonna leave this issue in my github inbox so I remember it til then, but it will probably be a week at least. Also; while we're on the topic: |
That's cool! If you have any questions feel free to ask them here. Please report any discrepancies/bugs that you find – reimplementation allows to catch very tricky issues and it's a great way for us to make sure that docs, tests and code stay in sync. I think you're also right about the |
It would be great if someone could say definitely whether or not it should be legal or not. Currently, I've set up my parser not to accept it, but it's easily enough to reverse. On the same note, the fact that you can't use And for those interested; the code can be found here. Parsing is found in this file (link is to specific commit, not master). |
More pseudo-random notes (figured I might just write these downs as I go through things, and it can be discussed/ignored later): This claims that The same kind of thing happens at My guess here is that Also; on |
Thanks a bunch. I knew what a binding is, and did arrive at where "binds" originate myself, however, I didn't know (at the time of writing) if On a happy note, my parser passes all the parser_tests from the go implementation (though they only check that it accepts valid input and rejects invalid input, not what it parses it to). |
Please don't worry about this. I think most engineers have a habit of trying too hard. The sort of things that you are asking about used to be confusing for me as well, when I was implementing go-jsonnet :-). I don't mind answering even basic questions as long as they are asked in a public forum (so that the next person with a similar issue can find it). It's also valuable feedback for us about what could be explained better. |
I'm back with more questions :). I've gotten past the first I'm currently completely stumped by the desugaring of object comprehension though, and figured I'd try to walk through how I read the definition here, so that I can be corrected, and maybe the description can be improved. And if I'm lucky, I might just figure it out as I'm writing (rubber ducking at it's finest). The definition looks like this: And for having something to discuss, let's go with the following object comprehension expression:
It's fairly convoluted, but it has all of the features (as far as I know) of a object comprehension that's being defined how to deal with in the desugar definition above. So, if I am to interpret the desugar definition, it should go as follows (using some pseudo code):
And as predicted, I might just have figured it out by trying to explain it 😅. Regardless, I figured I'd try to also explain the reason I'm personally having so much problem with this. What makes it really hard to interpret the definition of the
Basically, it's really hard to know what is and isn't jsonnet verbatim, and what is "code". Maybe adding color coding or somesuch to make this clearer would vastly help with readability here. Even having gone though this multiple times, I'm not sure the list above is correct. |
Also; as far as I can tell,
However, that would offset all of the variables defined in the spec here: |
I find myself stuck once again: An example here is Which means that
and we end up with
|
The desugaring rule for object comprehensions
AFAICT your interpretation is correct.
I agree that it is hard to distinguish sometimes and that can be quite confusing. I have never thought about it, though. Thanks for spelling it out. Being terse, on the other hand, is not a bug, it's a feature. You can't read it as fast as prose, but you'll need waaay more prose to describe things precisely (and that tends to be language-lawyery prose which is not exactly accessible either). That said, I would like to add comments explaining the intention for each rule, e.g. "reduce object comprehensions to use only one
Good idea. The most natural way for me seems to be using And of course you're right about 0-indexing vs 1-indexing. Another good catch :-). FYI go-jsonnet desugares object locals differently, but it turned out to also be quite painful. I plan to get rid of this rule completely and directly handle arbitrarily nested Desugaring
|
s/base/e/, sorry |
I've finished the code to lower from AST to Core (though my core language is slightly larger than the spec, as I keep the ´import Using the following input: [
x * y
for x in [1, 2, 3]
if true
for y in [4, 5, 6]
] I get the following (erroneous) output: local
arr = [
1,
2,
3,
];
std.join(
[
],
std.makeArray(
std.length(
arr,
),
function(
i=error 'Parameter not bound'
)
local
x = arr[i];
[
if true
then local
arr = [
4,
5,
6,
];
std.join(
[
],
std.makeArray(
std.length(
arr,
),
function(
i=error 'Parameter not bound'
)
local
y = arr[i];
[
x
* y,
],
),
)
else [
],
],
),
) Unfortunately, I don't know jsonnet well enough to see where I've gone wrong here. Do you see any obvious errors? |
More questions. According to the spec; the following jssonet { c: 5 } { f: $.c } Should expand to this: {
["c"]: local
$ = self;
5,
}
+ {
["f"]: local
$ = self;
$["c"],
}
Now, this might be entirely correct (and I might get answers if I started implementing the engine), but it doesn't seem correct. Basically, as per my understanding of |
Yes. There is one unnecessary array. This is already an array, you don't need to wrap it in another one:
BTW a great way to debug Jsonnet programs in cases like this is to take the interesting subexpressions out of the program and evaluate them on their own. Due to referential transparency, explicit namespaces and everything being an expression this tends to work much better than in other languages. Basically the only need you need to fix if you take expression out of context is local variables passed from above (and Jsonnet will always tell you about a missing variable, and it's impossible to get evaluation to succeed, but produce a wrong result this way). EDIT: from what I say this is also a problem in desugaring rules – there is an extra [] for the |
Yes.
Yes.
Maybe.
Yes, exactly. This is how operator So, of course I usually think of Jsonnet objects as stacks of layers. Each layer consists a bunch of field definitions. So Self, super and indexing are best explained with an example:
Indexing object from outside like Hope it helps. |
Is it to desugar e' ?
…On Fri, 15 May 2020 at 08:46, Aleksander Heintz ***@***.***> wrote:
I got array comprehension working :). It seems there are two errors in the
spec here:
[image: image]
<https://user-images.githubusercontent.com/112334/82024499-277a3980-9690-11ea-99af-76b34c7dca5e.png>
the array around the recursive call here is unneeded, as desugar_arrcomp
will always produce an array.
[image: image]
<https://user-images.githubusercontent.com/112334/82024938-dc145b00-9690-11ea-9553-227e08677092.png>
the same is true here.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#804 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AABJBXSAXVQAO7234FVFEW3RRTXNDANCNFSM4M3PH45A>
.
|
Not sure I get the question? Is what to desugar |
Sorry I misread what you said. You're right. Also there's a "base" just below that should be an e. The desugar_expr could be around the (e') as well, but that's more stylistic than correctness |
Thanks for taking the time to read through this by the way. It's rare for people to read it in detail unless they're actually needing to use it for something. And being as it's written by a human being and not verified, there still lingering mistakes even years after it was written. |
Yeah, well, I am using it 😛. But yeah, I figured I might as well take the time to report any issues I find given that I'm going through it with a rather fine comb (not sure if that expression translated correctly). I've started looking at the rules for validation and execution and will probably have more questions shortly because I think the syntax needs to explained more, but for now, I'm redoing my parser to a different architecture, so not entirely sure when I'll get to it. |
This change only covers clear, simple errors and not stylistic issues or spec-implementation discrepancies.
This change only covers clear, simple errors and not stylistic issues or spec-implementation discrepancies.
By the way; I've (for the most part) finished implementing v3 of the parser, and I'm quite happy with this one. There are some issues with slices (not parsing them, I believe, but figuring out what expr is what in the resulting parse tree), but I'll be looking at that shortly. In the meantime, I have my parser running in WASM, so I added it as a plugin to astexplorer. I thought some of you might find this cool. It's available here: https://jsonnet-astexplorer.now.sh/. Just select jsonnet from the language dropdown, and you can inspect the parse tree output of the jsonnet parser 😃. |
This change only covers clear, simple errors and not stylistic issues or spec-implementation discrepancies.
I think we fixed all issues reported here. Feel free to reopen if we missed something or if there is something new (or just open a new issue, either way is fine). |
According to the language spec, the following is the ways you can slice an array:
As far as I can tell, this does not accept the following strings:
foo[::]
foo[1::]
foo[::1]
foo[1::1]
However, as from what I can see, all of those works. Is this just an error in the BNF? Or am I reading it wrong?
The text was updated successfully, but these errors were encountered: