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

Implements encoding directive macros and comment macro #973

Merged
merged 1 commit into from
Oct 15, 2024

Conversation

popematt
Copy link
Contributor

Issue #, if available:

None

Description of changes:

  • Adds an optional body field to SystemMacro
  • Adds TDL definitions of use, set_macros, add_macros, set_symbols, add_symbols, and comment`.
  • Updates the MacroEvaluator to support reading template bodies for system macros.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@popematt popematt requested a review from tgregg October 14, 2024 22:46
Comment on lines +18 to +23
// Technically not system macros, but special forms. However, it's easier to model them as if they are macros in TDL.
// We give them an ID of -1 to distinguish that they are not addressable outside TDL.
IfNone(-1, "if_none", listOf(zeroToManyTagged("stream"), zeroToManyTagged("true_branch"), zeroToManyTagged("false_branch"))),
IfSome(-1, "if_some", listOf(zeroToManyTagged("stream"), zeroToManyTagged("true_branch"), zeroToManyTagged("false_branch"))),
IfSingle(-1, "if_single", listOf(zeroToManyTagged("stream"), zeroToManyTagged("true_branch"), zeroToManyTagged("false_branch"))),
IfMulti(-1, "if_multi", listOf(zeroToManyTagged("stream"), zeroToManyTagged("true_branch"), zeroToManyTagged("false_branch"))),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🗺️ These were moved to the beginning of the enum because use needs to reference if_none, and the constructor args for an enum entry can only use back references to other entries of the same enum.

Comment on lines -96 to +98
override fun <T : Any?> asFacet(facetType: Class<T>?): Nothing = TODO("Not supported")
override fun <T : Any?> asFacet(facetType: Class<T>?): Nothing? = null
override fun getDepth(): Int = containerStack.size()
override fun getSymbolTable(): SymbolTable = TODO("Not implemented in this abstraction")
override fun getSymbolTable(): SymbolTable? = null
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🗺️ Rather than throwing exceptions, these now return null, which is allowed by the interface. I don't know why I didn't do that to begin with, but now it means we can use e.g. _Private_IonSystem.iterate() on a MacroEvaluatorAsIonReader instance.

Copy link

codecov bot commented Oct 14, 2024

Codecov Report

Attention: Patch coverage is 87.62887% with 12 lines in your changes missing coverage. Please review.

Please upload report for BASE (ion-11-encoding@9dc06cc). Learn more about missing BASE report.

Files with missing lines Patch % Lines
...n/java/com/amazon/ion/impl/macro/MacroEvaluator.kt 66.66% 2 Missing and 2 partials ⚠️
...main/java/com/amazon/ion/impl/macro/SystemMacro.kt 94.59% 3 Missing and 1 partial ⚠️
.../com/amazon/ion/impl/macro/ExpressionBuilderDsl.kt 57.14% 3 Missing ⚠️
...amazon/ion/impl/macro/MacroEvaluatorAsIonReader.kt 50.00% 1 Missing ⚠️
Additional details and impacted files
@@                Coverage Diff                 @@
##             ion-11-encoding     #973   +/-   ##
==================================================
  Coverage                   ?   70.42%           
  Complexity                 ?     7049           
==================================================
  Files                      ?      201           
  Lines                      ?    27778           
  Branches                   ?     4998           
==================================================
  Hits                       ?    19562           
  Misses                     ?     6646           
  Partials                   ?     1570           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@tgregg tgregg left a comment

Choose a reason for hiding this comment

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

Could you add a TODO somewhere to add tests that verify that the encoding directive-related macros actually take effect in the readers?

symbol(IMPORT)
symbol(theModule)
variable(0)
macro(IfNone) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we're adding default, so we could use it here once we implement it.

@popematt
Copy link
Contributor Author

Could you add a TODO somewhere to add tests that verify that the encoding directive-related macros actually take effect in the readers?

The tests in Ion_1_1_RoundTripTest have Ion 1.1 encoding directives, and this will also be covered by the conformance tests.

@popematt popematt merged commit 66cab4e into amazon-ion:ion-11-encoding Oct 15, 2024
18 of 36 checks passed
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.

2 participants