-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
METHOD DoSomething | ||
VAR | ||
Something : BOOL; | ||
END_VAR | ||
|
||
Something := anObject.WriteLine(THIS^.something.t, THIS^.GetTagName()^, INT_TO_STRING(BOOL_TO_INT(THIS^.someAttribute))); | ||
|
||
END_METHOD |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1587,6 +1587,7 @@ def __str__(self) -> str: | |
class FunctionCall(Expression): | ||
name: SymbolicVariable | ||
parameters: List[ParameterAssignment] | ||
dereferenced: bool | ||
meta: Optional[Meta] = meta_field() | ||
|
||
@property | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. Technically the 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 commentThe 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 commentThe 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. @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 commentThe 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. 👍 |
||
) -> FunctionCall: | ||
# Remove the Dereference Token if Present in the Remaining Parameters | ||
dereferenced = False | ||
if remaining_parameters: | ||
if str(remaining_parameters[-1]) == "^": | ||
dereferenced = True | ||
remaining_parameters = remaining_parameters[:-1] | ||
# Condition parameters (which may be `None`) to represent empty tuple | ||
if first_parameter is None: | ||
parameters = [] | ||
|
@@ -1630,11 +1637,15 @@ def from_lark( | |
return FunctionCall( | ||
name=name, | ||
parameters=parameters, | ||
dereferenced=dereferenced | ||
) | ||
|
||
def __str__(self) -> str: | ||
dereference = "" | ||
parameters = ", ".join(str(param) for param in self.parameters) | ||
return f"{self.name}({parameters})" | ||
if self.dereferenced: | ||
dereference = "^" | ||
return f"{self.name}({parameters}){dereference}" | ||
|
||
|
||
@dataclass | ||
|
@@ -2620,6 +2631,7 @@ def from_lark( | |
return FunctionCallStatement( | ||
name=invocation.name, | ||
parameters=invocation.parameters, | ||
dereferenced=invocation.dereferenced, | ||
meta=invocation.meta, | ||
) | ||
|
||
|
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
(usingfunction_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.