-
Notifications
You must be signed in to change notification settings - Fork 8
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
Parsing upcoming let-expression
#66
Conversation
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## main #66 +/- ##
==========================================
+ Coverage 87.88% 88.34% +0.46%
==========================================
Files 11 12 +1
Lines 2435 2557 +122
==========================================
+ Hits 2140 2259 +119
Misses 204 204
- Partials 91 94 +3
☔ View full report in Codecov by Sentry. |
6c865ec
to
9c3acd5
Compare
Signed-off-by: Springcomp <[email protected]>
9c3acd5
to
a329609
Compare
Signed-off-by: Springcomp <[email protected]>
a329609
to
e30f785
Compare
Signed-off-by: Springcomp <[email protected]>
Signed-off-by: Springcomp <[email protected]>
My setup seems broken, I do not understand how to lint my code ☹ |
Signed-off-by: Springcomp <[email protected]>
Signed-off-by: Springcomp <[email protected]>
Signed-off-by: Springcomp <[email protected]>
@springcomp does it work when you try to parse I have |
In |
I must have forgotten to push this change 🙄. The reason is that we use Basically, If you can follow the Python diff you will see what I mean. If you need, howevee, I can have a look at it tomorrow. |
Yeah i was tracking it down, it see it in:
I will give a look at the python implementation, i think i can read some basic python 🤞 |
Ok, parsing is passing now, I'll start implementing the bindings tomorrow. |
Perfect. Please note that I did not include the lexing either 😏 |
I feel like parsing is not robust enough, see #68 for example ( |
I did this: func (lexer *Lexer) consumeVarRef() token {
// Consume runes until we reach the end of an unquoted
// identifier.
start := lexer.currentPos - lexer.lastWidth
for {
r := lexer.next()
if r < 0 || r > 128 || identifierTrailingBits[uint64(r)/64]&(1<<(uint64(r)%64)) == 0 {
lexer.back()
break
}
}
value := lexer.expression[start:lexer.currentPos]
return token{
tokenType: TOKVarref,
value: value,
position: start,
length: lexer.currentPos - start,
}
} |
This seems perfect. 👍 As the check for a character that starts an |
Signed-off-by: Charles-Edouard Brétéché <[email protected]>
Signed-off-by: Charles-Edouard Brétéché <[email protected]>
@springcomp I implemented the interpreter part, WDYT ? |
That’s nice. I think we are almost there. Currently, there are three compliance tests failing.
I have the feeling that scopes are not correctly pushed / popped appropriately.
|
I didn't implement undefined-variable error (there's a TODO in this PR). |
Sorry I missed that. |
|
I'll do that asap, should not be long. |
@springcomp i pushed the fixes |
Signed-off-by: Springcomp <[email protected]>
That works great ! Implementation looks good to me. 👍 |
It's similar to |
I'm curious why we don't allow referencing previous bindings though jmespath/jmespath.py#307 (comment) |
Well we do allow referencing parent bindings.
My understanding is that:
As you are creating the second nested level of bindings, you are defining a shadow value for This seems logical to me. As you would not want to have side effects based upon the order in which each implementation would want to create the binding. Let's say an implementation would create the binding in alphabetical order of variable names. Or in reverse order. Or in an unspecified order. They would result in different output from one another. |
Well, i see advantages in allowing it too: To me it looks very similar to what we do with local variables: func f(a int) {
a := 10 // `a` shadows the `a` function argument
b := a // `b` references `a` local variable
} |
Sure it makes sense either way. For this to work though, the spec would need to absolutely specify the order in which binding variables are created. |
I was assuming variables were initialised in the declaration order. |
That's worth clarifying indeed. |
@springcomp shall we get this in ? |
Good question. I actually have no idea how much time James will allow for the proposal to reach consensus. I will proceed with other implementations as well and start the deprecation process in the spec. I think we need to care about code coverage which seems to have decreased. |
bbfe7cb
to
710c010
Compare
Signed-off-by: Springcomp <[email protected]>
Signed-off-by: Springcomp <[email protected]>
710c010
to
6a054c7
Compare
Signed-off-by: Charles-Edouard Brétéché <[email protected]>
@springcomp i added unit tests for the bindings package. |
@eddycharly can we include in this pull request provisions for settings a global scope from the
|
I'll do that tomorrow 👍 |
@eddycharly FYI |
@springcomp yeah i saw that, awesome ! |
Hello @eddycharly @JimBugwadia should this pull request be merged ? |
@springcomp sorry, we were quite busy during the last weeks. I think this is good to merge, we can improve in follow-up PRs if it's ok. |
That’s perfect for me. Thanks a lot. |
This PR implements the parsing of
let-expression
rules as they are anticipated to land in an upcoming proposal.This PR does not implement the lexer, nor does it include any expression evaluation logic.
This is a work in progress.
Fixes #53