-
Notifications
You must be signed in to change notification settings - Fork 5
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
Support Dereferenced Function/Method Returns in Grammar #59
Support Dereferenced Function/Method Returns in Grammar #59
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## master #59 +/- ##
========================================
+ Coverage 72.3% 72.6% +0.3%
========================================
Files 18 18
Lines 3797 3806 +9
========================================
+ Hits 2746 2764 +18
+ Misses 1051 1042 -9
|
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.
Thanks yet again @engineerjoe440!
My comments in the review are partly verbose notes-to-self/thinking aloud as usual.
The core of this is good; merging and calling this completed 👍
@@ -749,7 +749,7 @@ reset_statement: _variable "R="i expression ";"+ | |||
reference_assignment_statement: _variable "REF="i expression ";"+ | |||
|
|||
// method ::= expression [DEREFERENCED] '.' _identifier '(' ')'; | |||
method_statement: symbolic_variable "(" ")" ";"+ | |||
method_statement: symbolic_variable "(" ")" DEREFERENCED? ";"+ |
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.
Looks like it's time to get rid of method_statement
entirely.
function_call_statement
(using function_call
) handles everything it does and more, so having both just makes for ambiguity in the grammar.
I'll make an issue to remove it along with its related MethodStatement
class.
@@ -1621,6 +1622,12 @@ def from_lark( | |||
first_parameter: Optional[ParameterAssignment] = None, | |||
*remaining_parameters: ParameterAssignment, |
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.
Technically the remaining_parameters
annotation needs updating here because it can now contain a lark.Token
as well (holding that semi-colon ";"
). Then static analyzers will complain that parameters
is no longer compatible with List[ParameterAssignment]
, ...
Let's just roll with this and maybe clean it up later - there are much bigger fish to fry!
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.
I think that's a fair point, though, @klauer... I had toyed with it, but decided the same about "bigger fish" (at least for this moment in time). Do you have thoughts on a better name? I'd be happy to lob something in there in upcoming changes.
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.
I couldn't think of a way to express it in words - sometimes code is more succinct.
I think this might be preferable:
@staticmethod
def from_lark(
name: SymbolicVariable,
*params: Union[ParameterAssignment, lark.Token, None],
) -> FunctionCall:
# Condition parameters (which may be `None`) to represent empty tuple
if params and params[0] is None:
params = params[1:]
dereferenced = bool(params and params[-1] == "^")
if dereferenced:
params = params[:-1]
return FunctionCall(
name=name,
parameters=typing.cast(List[ParameterAssignment], list(params)),
dereferenced=dereferenced,
)
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.
OK! I'm gonna roll this in to the next bit of work I do. 👍
Related Issues
Changes
^
) character to function and method call (return) statements.Closing Thoughts
These changes should make this all a bit more convenient, and should allow for syntax such as:
Which can allow for chained method calls using dereferences on any returned pointers.