-
Notifications
You must be signed in to change notification settings - Fork 7
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
Basic for parsing/interpreting #32
Conversation
Also implements __iter__ on Dict and List added main handling on interpreter Added enumerate global function Added items function on Dict tests also check real python
Thanks a lot! Most of the work seems good, especially in the The parser will probably require some changes, as I think we should reuse Consider this example from Python's AST: $ python -m ast <<<'for i in x in y in z: ...'
Module(
body=[
For(
target=Name(id='i', ctx=Store()),
iter=Compare(
left=Name(id='x', ctx=Load()),
ops=[
In(),
In()],
comparators=[
Name(id='y', ctx=Load()),
Name(id='z', ctx=Load())]),
body=[
Expr(
value=Constant(value=Ellipsis))],
orelse=[])],
type_ignores=[]) This seems to show that we can stop at the first Well, unfortunately that's not the case, for example, if there are commas after that sub-expression: $ python -m ast <<<'for i in x, j in y in z: ...'
Module(
body=[
For(
target=Name(id='i', ctx=Store()),
iter=Tuple(
elts=[
Name(id='x', ctx=Load()),
Compare(
left=Name(id='j', ctx=Load()),
ops=[
In(),
In()],
comparators=[
Name(id='y', ctx=Load()),
Name(id='z', ctx=Load())])],
ctx=Load()),
body=[
Expr(
value=Constant(value=Ellipsis))],
orelse=[])],
type_ignores=[]) Here, Doing this correctly will require some more looking into how Python's actual grammar works. |
I did experiment with multiple expressions separated by comma after the in. I think that already works. The extra ins are comparisson operators or am I missing something :-) In both case the target is target=Name(id='i', ctx=Store()), Or do you mean the output of my code :-) |
You're right, I confused myself. Making some small changes to the code... |
I think I also forgot to add the 'range' function |
I made some adjustments:
|
Please feel free to add a |
I think they can have multiple. There are examples in the tests: This one has two targets
|
@Jacco In this case |
Ah ok, I missed the inner workings self.assign :-) |
I'll merge this PR soon, you can add a |
Resolved #31
Also implements iter on Dict and List
added main handling on interpreter
Added enumerate global function
Added items function on Dict
tests also check real python