Skip to content
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

Replace Value with Expression in the grammar #1023

Merged
merged 66 commits into from
May 24, 2022
Merged

Conversation

cmnrd
Copy link
Collaborator

@cmnrd cmnrd commented Mar 10, 2022

This makes a first step at implementing the spec in #986 by creating an extensible Expression syntax in replacement of the old Value rule. In consequence of the grammar changes, this PR also includes a ton of refactoring.

This PR is based on #1022 and includes its changes.

Copy link
Collaborator

@edwardalee edwardalee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not understanding this PR. It seems to be mostly about renaming the Value AST node to Expression without changing what it means. Is this meant to be a stepping stone towards supporting expressions?

)?
;

Value:
(parameter=[Parameter] | time=Time | literal=Literal | code=Code);
Expression:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused by this. I would expect an Expression to somehow different from a Value. This looks to me the same as what we used to call a Value.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the idea here is that @cmnrd plans to augment this rule later on. This PR is just meant to set the stage for that.

@cmnrd
Copy link
Collaborator Author

cmnrd commented Mar 23, 2022

Yes, this a first step at introducing an expression syntax. This PR only converts what we now call a Value to an Expression. However, at the same time the resulting model is adjusted such that we have a base class Expressions and the different types of expressions (ParameterReferecen, Literal, Code, Time) are child classes. This enables easy addition of new expression rules in the future. Also, this allows for a better design of our code generators where we can use the Visitor pattern (in Java) or when blocks (in Kotlin) to differentiate the different expression types. This, however, is not part of this PR yet.

petervdonovan and others added 11 commits May 18, 2022 18:53
This pass was automated instead of manual. It replaces carriage return/line feed line terminators with just line feed terminators, and it removes trailing whitespace.
This is a manual pass for incorrect indentation.
'expressions' has already been approved; we just need to make sure it passes CI.
To make that work, it is necessary to merge in changes from 'master'.
@petervdonovan
Copy link
Collaborator

petervdonovan commented May 20, 2022

The LSP tests have been a hindrance for this branch... sorry. I suspect that if we re-ran the tests, the LSP tests would be more likely to pass than not. This annoying inconsistency exists because I deliberately set them up to use a different random seed each time, on the grounds that as we run CI each day, we might randomly catch more edge cases over time.

This time, the LSP tests seem to be failing because the body of the STP handler in test/Python/src/federated/DistributedCountDecentralizedLateDownstream.lf is not being code-generated. This does not seem right to me. Maybe @Soroosh129 could explain what is going on?

@Soroosh129
Copy link
Contributor

This time, the LSP tests seem to be failing because the body of the STP handler in test/Python/src/federated/DistributedCountDecentralizedLateDownstream.lf is not being code-generated. This does not seem right to me. Maybe @Soroosh129 could explain what is going on?

I can't seem to replicate this issue. The STP handler is being generated for me on master and this branch:

Python

image

C

image

@petervdonovan
Copy link
Collaborator

I was mistaken; thanks to Soroush for patiently explaining. The real reason for the most recent test failure in this branch is that instead of having toText insert tags while toUntaggedText does not insert tags, we have a toText function that does not insert tags and a toTaggedText function that does insert tags. This makes inserting tags more like an "opt-in" than an "opt-out."

I don't feel strongly about this, and I am sure there is a reason for this change. However, I am not convinced that it is the best choice. In ASTUtils.toUntaggedText (which is now deleted), I had left a comment stating that toUntaggedText only existed because we were analyzing and patching the contents of code blocks using regular expressions, which is a practice that probably should be discouraged. I think that verbatim code should nearly always have tags, so with the behavior of toText that is in this branch, I will probably have to do another pass over all the code generators to change most mentions of toText to toTaggedText.

@lhstrh
Copy link
Member

lhstrh commented May 20, 2022

I think I lean towards reverting the mechanism to opt-out instead of having opt-in.

Copy link
Member

@lhstrh lhstrh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me! I guess the only minor aesthetic issue I see that not all developers might initially be aware of what tagging is and whether they should use toText or toUntaggedText. Perhaps we can come up with a better name for toUntaggedText that highlights its typical use case rather than the presence of tags? Maybe toOriginalText? Or toVerbatimText? IDK...

org.lflang/src/org/lflang/ASTUtils.java Outdated Show resolved Hide resolved
org.lflang/src/org/lflang/ASTUtils.java Outdated Show resolved Hide resolved
org.lflang/src/org/lflang/ASTUtils.java Outdated Show resolved Hide resolved
@petervdonovan petervdonovan merged commit c4dfbd9 into master May 24, 2022
@petervdonovan petervdonovan deleted the expressions branch May 24, 2022 21:07
@cmnrd
Copy link
Collaborator Author

cmnrd commented Jun 21, 2022

Thanks for finishing this up! With regard to the discussion about toText and toTaggedText, I found that toText is also used a lot outside of the generators and there the additional tags are pretty confusing. However, I like the new to toOriginalText name for the function and it should be pretty clear now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants