-
Notifications
You must be signed in to change notification settings - Fork 332
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
Helper to get static string from parser #2736
base: main
Are you sure you want to change the base?
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 |
---|---|---|
|
@@ -118,5 +118,34 @@ public string GetAnonymizedFormula() | |
{ | ||
return StructuralPrint.Print(Root); | ||
} | ||
|
||
/// <summary> | ||
/// Checks if the expression does not depend on extra evaluations. | ||
/// Examples: | ||
/// "Lorem ipsum" // is a static expression since there is no extra evaluation needed. | ||
/// "Today is " & Today() // is not a static expression since the function call 'Today()' needs to be evaluated. | ||
/// $"Today is {""some text""}" // is not a static expression since the interpolation needs to be evaluated. | ||
/// </summary> | ||
/// <returns>True if no extra evaluation is needed. False otherwise.</returns> | ||
public bool TryGetStaticTextExpression(out string staticExpression) | ||
{ | ||
if (Options.TextFirst && | ||
Root is StrInterpNode strInterpNode && | ||
strInterpNode.ChildNodes.Count == 1 && | ||
strInterpNode.ChildNodes.First() is StrLitNode strLitNode) | ||
{ | ||
staticExpression = strLitNode.Value; | ||
return true; | ||
} | ||
|
||
if (Root is StrLitNode strLitNode1) | ||
{ | ||
staticExpression = strLitNode1.Value; | ||
return true; | ||
} | ||
|
||
staticExpression = null; | ||
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. what about numbers? (this gets to the purpose of the feature) 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. Today, this requirement is limited to string type arguments, but in the future, we might need to extend it. |
||
return false; | ||
} | ||
} | ||
} |
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.
can we avoid this?