Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Describe your changes
I'm adding support for the
has()
macro. I'm providing it similarly to the existingsize()
macro. I did copy the GO style of the macrohas(object.property)
to maximise interoperability.A big part of supporting
has()
is done in a few different visitors:macrosExpression
supportshas()
as a special case and calls for a helper method to handle it. For any other macro, the process continues to work the same.handleHasMacro
— handles thehas()
case, trying to evaluate the argument provided to the macro. The method will throw if no arguments are passed. The method also sets up aninHas
context, which visitors later use to change the default behaviour if called in ahas()
macro—The context approach mimics GO implementation. I'm not a GO developer, so I did my best to understand how they deal with this. The method will rethrow any exceptions thrown by called visitors; this is how we deal with invalid arguments.conditionalAnd
— I've added a short circuit for cases where the left side operand is false. This allows to use has as a check for existence:atomicExpression
— Will throw when called in thein
context and evaluate anidentifierExpression
.identifierExpression
— This is the only allowed case for ahas()
macro. It still will throw if not called for anidentifierDotExpression
context.Expected success cases
Expected errors
Disclaimer
I used the AWS Q AI assistant while working on the implementation and documentation. I reviewed the proposed code.
Issue ticket number/link
#32
Checklist before requesting a review