-
Notifications
You must be signed in to change notification settings - Fork 47
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
Refactors PrintStatement so that .values
array is all expressions
#1296
Refactors PrintStatement so that .values
array is all expressions
#1296
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The more I look at this, the more I think LiteralExpression
is not the correct expression type for this. Perhaps we should make a new PrintSeparatorExpression
instead, just to retain the semantic integrity of LiteralExpression.
@elsassph You've had a decent amount of experience with parsers. Any thoughts on how we'd approach this one?
It does feel wrong to make I guess the alternative would be to model it as binary-expressions where |
Hmm. I'm not crazy about the idea of |
The more I dug into this, the more I dislike the concept of this expression basically not actually representing code. I just had another thought. What if we stored an array of separators on
This keeps the separators separate from the actual "code", while retaining their position. It makes things slightly for annoying Ast creation, but we have similar problems with TemplateStringExpression, and we're not even capturing the commas for function parameters at this point. |
…hterscript into better_PrintStatment_expressions
I refactored this to leverage a new expression called What about instead storing arrays between each section? Similar to one of my previous examples, except add another level of array.
Here's an example:
We'd produce the following ast: new PrintStatement({
print: token('print'),
expressions: [
literal('1'),
literal('2'),
literal('3')
],
//separators can come before the first expression, so we start with them.
separators: [
[token(','), token(','), token(',')],
[token(';')],
//no separator between 2 and 3
[],
[token(';'), token(';')]
]
}) This feels more "correct" in that we don't have these weird expressions floating around that aren't actual code. However, it gets a bit extra gross neeting to maintain these deep nested lists of things. From a plugin perspective, it's a lot easier to build the list of print items just by pushing to a flat @markwpearce @philippe-wm any final thoughts? If you are both okay with the current implementation of |
@TwitchBronBron I think this is ready for merging. I'm happy with this approach. |
;
and,
are converted toPrintSeparatorExpression
Addresses #1280