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

Include the position information for the Expression nodes in the Fhipath Parser #2774

Merged
merged 24 commits into from
May 14, 2024

Conversation

brianpos
Copy link
Collaborator

Description

The Expression class has a Location property which is intended to store the position information of each Expression object in the AST. This has never been populated (was expected to go via the constructor).
This PR uses the sprache SetPos/Positioned() capability to inject that information while parsing.
The old anticipated approach has been retained, and leveraged for unit testing to manually populate the data.

It also adds support for skipping over comments in expressions.

Related issues

Resolves #2517

Testing

There are many new unit tests to verify the positioning information.

FirelyTeam Checklist

  • Update the title of the PR to be succinct and less than 50 characters
  • Mark the PR with the label breaking change when this PR introduces breaking changes

…pression types without impacting visitor implementations
…es from Constant to retain compatibility with existing code that might be using that type.
…und tripping more easily.

This will reduce to nothing if not handled in a visitor
…n (standardizing whitespace)

* Brackets can handle having extra whitespace around them
* Brackets support left/right subtokens inside
* FunctionCalls support left/right subtokens inside
* Position information updated for function calls (and child expressions too)
* Roundtripping fhirpath expressions unit tests
…he Expression objects

and also handling comments in fhirpath expressions (they are skipped and not retained in the expression AST)
@brianpos
Copy link
Collaborator Author

brianpos commented Apr 22, 2024

I need to recheck this against my other branch... fhirpath-position (which has the round-trip visualizer).
feature/fhirpath-parsing...feature/fhirpath-position
Will do that tomorrow.

@brianpos
Copy link
Collaborator Author

Branch is now good for review.
The other changes I have locally are for capturing the whitespace/comments into subtokens.
And I'd also like to change the name from SubTokenExpression to just SubToken

@ewoutkramer ewoutkramer marked this pull request as draft April 23, 2024 07:52
@ewoutkramer ewoutkramer marked this pull request as ready for review April 23, 2024 07:52
Copy link
Member

@ewoutkramer ewoutkramer left a comment

Choose a reason for hiding this comment

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

There's a risk I am making comments about things we discussed before at the WGM, but it was so long ago, that I have forgotten our conclusions ;-)

In general, we should now be adding doccomments to any (new) public classes and other surface elements, so that's my major feedback. If possible, adding #nullable enable and specifying nullability markers would be nice, but sometimes that is a pandora's box.

@brianpos
Copy link
Collaborator Author

I've completed all the changes requested.
If you want to also see the comment/whitespace parsing changes, they are in this branch
https://github.com/FirelyTeam/firely-net-sdk/tree/feature/fhirpath-parsing-comments

Diff here:
feature/fhirpath-parsing...feature/fhirpath-parsing-comments
Note that the TokenIgnoreComments that I introduced here has been removed - which is added in the first pass in this PR - so isn't a change to the public interface when combined.

/// <summary>
/// Any leading whitespace or comments encountered immediately before this SubToken
/// </summary>
public IEnumerable<WhitespaceSubToken> leadingWhitespace { get; internal set; }
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be Pascal Cased?

Copy link
Member

Choose a reason for hiding this comment

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

Yes.

/// <summary>
/// Any trailing whitespace or comments encountered immediately after this SubToken
/// </summary>
public IEnumerable<WhitespaceSubToken> trailingWhitespace { get; internal set; }
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be Pascal Cased?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Resolved in the other branch when that is merged in too.

}
break;
case "String":
_result.Append($"'{t}'");
Copy link
Collaborator Author

@brianpos brianpos May 2, 2024

Choose a reason for hiding this comment

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

@ewoutkramer ?
This line should really be handling the delimiting of the strings too.
Should the Functions.StringOperators.EscapeJson be the appropriate function to use there?

_result.Append("'" + Functions.StringOperators.EscapeJson(t) + "'"); 

Note: yes something does need to be done here, I found this round tripping all the search parameters/invariants.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, if the goal of this visitor is to roundtrip to the original fhirpath as much as possible, it should escape stuff. Not easy to really roundtrip (as you cannot distinguish between allowed unicode characters and escaped unicodes anymore), but that would be good enough. So, it should "undo" the parsing of the string.

If this were C# we could leverage Roslyn:

  return SyntaxFactory.LiteralExpression(SyntaxKind.StringLiteralExpression, SyntaxFactory.Literal(input)).ToFullString();

But I don't know if that's good enough.

ewoutkramer
ewoutkramer previously approved these changes May 3, 2024
case "Integer":
_result.Append($"{t}");
break;
case "Long":
Copy link
Member

Choose a reason for hiding this comment

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

You could combine all cases that do the same thing, to make clear they are doing the same thing!

/// <summary>
/// Any leading whitespace or comments encountered immediately before this SubToken
/// </summary>
public IEnumerable<WhitespaceSubToken> leadingWhitespace { get; internal set; }
Copy link
Member

Choose a reason for hiding this comment

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

Yes.

@ewoutkramer ewoutkramer removed the request for review from Kasdejong May 7, 2024 08:58
@ewoutkramer
Copy link
Member

@brianpos - note that both Gino and I had some review remarks.

Build is currently failing because of a QA step: https://dev.azure.com/firely/firely-net-sdk/_build/results?buildId=38380&view=logs&j=558a83a0-5585-5f85-5265-cdf5febe3f62&t=a961ae7d-38e2-5a82-9685-674f5235ed2d, we have added new constructors which breaks binary compat. We're not striving to get to binary compat, and I think it's alright for compile compatibility. But I don't remember how to disable the message. @Kasdejong ?

@brianpos
Copy link
Collaborator Author

brianpos commented May 7, 2024

Gino's concerns are in the second branch that follows this one.
If you're good with those other doffs I can just bring them all into this PR.
And I thought I'd addressed all your changes. Left the comment so you coukd verify.

I'll have another look at the constructors listed in the build.

@brianpos
Copy link
Collaborator Author

brianpos commented May 7, 2024

Should I just merge in the whitespace and comments capturing changes into this branch too now?

@brianpos
Copy link
Collaborator Author

brianpos commented May 7, 2024

@brianpos - note that both Gino and I had some review remarks.

Build is currently failing because of a QA step: https://dev.azure.com/firely/firely-net-sdk/_build/results?buildId=38380&view=logs&j=558a83a0-5585-5f85-5265-cdf5febe3f62&t=a961ae7d-38e2-5a82-9685-674f5235ed2d, we have added new constructors which breaks binary compat. We're not striving to get to binary compat, and I think it's alright for compile compatibility. But I don't remember how to disable the message. @Kasdejong ?

I've reviewed those messages, It looks like its just that it wants the constructors that have the default location = null parameter split into seperate ones.
I can do that very easily - and have done locally in the other branch ready to push with your approval.

@ewoutkramer
Copy link
Member

Should I just merge in the whitespace and comments capturing changes into this branch too now?

Nah, let's do two PRs, this one is done & reviewed now. Just need to either split those constructors, or wait for Kas or Marten to tune that exception file. I could probably find out how, but after this FMG meeting I'll join them in going a short Ascension break, so it will be Monday before we get to it.

…inary compatible with the previous release)

(cherry picked from commit f13e409)
@ewoutkramer ewoutkramer merged commit e10c64d into develop May 14, 2024
16 checks passed
@ewoutkramer ewoutkramer deleted the feature/fhirpath-parsing branch May 14, 2024 09:49
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.

Support position information in FHIRPath expressions
4 participants