Skip to content

Commit

Permalink
Little bits of cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
popematt committed Sep 6, 2024
1 parent 285d99a commit 770c81e
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public IonWriter build(Appendable out) {
symbolInliningStrategy,
LengthPrefixStrategy.NEVER_PREFIXED,
// This could be made configurable.
ManagedWriterOptions_1_1.MacroAddressStrategy.BY_NAME
ManagedWriterOptions_1_1.EExpressionIdentifierStrategy.BY_NAME
);
return IonManagedWriter_1_1.textWriter(out, options, b);
}
Expand All @@ -169,7 +169,7 @@ public IonWriter build(OutputStream out) {
symbolInliningStrategy,
LengthPrefixStrategy.NEVER_PREFIXED,
// This could be made configurable.
ManagedWriterOptions_1_1.MacroAddressStrategy.BY_NAME
ManagedWriterOptions_1_1.EExpressionIdentifierStrategy.BY_NAME
);
return IonManagedWriter_1_1.textWriter(out, options, b);
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/amazon/ion/impl/bin/IonManagedWriter_1_1.kt
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ internal class IonManagedWriter_1_1(

override fun addMacro(macro: Macro): MacroRef {
val id = internMacro(macro)
return if (options.macroAddressStrategy == ManagedWriterOptions_1_1.MacroAddressStrategy.BY_NAME) {
return if (options.eExpressionIdentifierStrategy == ManagedWriterOptions_1_1.EExpressionIdentifierStrategy.BY_NAME) {
macroNames[id]
?.let { MacroRef.ByName(it) }
?: MacroRef.ById(id)
Expand All @@ -770,15 +770,15 @@ internal class IonManagedWriter_1_1(
override fun addMacro(name: String, macro: Macro): MacroRef {
val id = internMacro(macro)
macroNames[id] = name
return if (options.macroAddressStrategy == ManagedWriterOptions_1_1.MacroAddressStrategy.BY_NAME) {
return if (options.eExpressionIdentifierStrategy == ManagedWriterOptions_1_1.EExpressionIdentifierStrategy.BY_NAME) {
MacroRef.ByName(name)
} else {
MacroRef.ById(id)

Check warning on line 776 in src/main/java/com/amazon/ion/impl/bin/IonManagedWriter_1_1.kt

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/amazon/ion/impl/bin/IonManagedWriter_1_1.kt#L776

Added line #L776 was not covered by tests
}
}

override fun startMacro(macroRef: MacroRef) {
val useNames = options.macroAddressStrategy == ManagedWriterOptions_1_1.MacroAddressStrategy.BY_NAME
val useNames = options.eExpressionIdentifierStrategy == ManagedWriterOptions_1_1.EExpressionIdentifierStrategy.BY_NAME
val ref = when (macroRef) {
is MacroRef.ById -> if (useNames) macroRef.intoNamed() else macroRef
is MacroRef.ByName -> if (useNames) macroRef else macroRef.intoId()
Expand Down
16 changes: 10 additions & 6 deletions src/main/java/com/amazon/ion/impl/bin/ManagedWriterOptions_1_1.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,33 @@ data class ManagedWriterOptions_1_1(
val internEncodingDirectiveSymbols: Boolean,
val symbolInliningStrategy: SymbolInliningStrategy,
val lengthPrefixStrategy: LengthPrefixStrategy,
val macroAddressStrategy: MacroAddressStrategy,
val eExpressionIdentifierStrategy: EExpressionIdentifierStrategy,
) : SymbolInliningStrategy by symbolInliningStrategy, LengthPrefixStrategy by lengthPrefixStrategy {
companion object {
@JvmField
val ION_BINARY_DEFAULT = ManagedWriterOptions_1_1(
internEncodingDirectiveSymbols = true,
symbolInliningStrategy = SymbolInliningStrategy.NEVER_INLINE,
lengthPrefixStrategy = LengthPrefixStrategy.ALWAYS_PREFIXED,
macroAddressStrategy = MacroAddressStrategy.BY_ID,
eExpressionIdentifierStrategy = EExpressionIdentifierStrategy.BY_ADDRESS,
)
@JvmField
val ION_TEXT_DEFAULT = ManagedWriterOptions_1_1(
// It's a little easier to read this way
// Encoding directives are easier to read if we don't intern their keywords.
internEncodingDirectiveSymbols = false,
symbolInliningStrategy = SymbolInliningStrategy.ALWAYS_INLINE,
// This doesn't actually have any effect for Ion Text since there are no length-prefixed containers.
lengthPrefixStrategy = LengthPrefixStrategy.NEVER_PREFIXED,
macroAddressStrategy = MacroAddressStrategy.BY_NAME,
eExpressionIdentifierStrategy = EExpressionIdentifierStrategy.BY_NAME,
)
}

enum class MacroAddressStrategy {
/**
* Indicates whether e-expressions should be written using macro
* names or macro addresses (when a choice is available).
*/
enum class EExpressionIdentifierStrategy {
BY_NAME,
BY_ID,
BY_ADDRESS,
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/amazon/ion/impl/macro/MacroCompiler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ class MacroCompiler(private val reader: IonReaderContinuableCore) {
}
// TODO: Once we have a macro table, validate that id exists in current macro table.
IonType.INT -> MacroRef.ById(reader.intValue())
else -> throw IonException("macro invocation must start with an id (int) or identifier (symbol); found ${reader.type ?: "nothing"}\"")
else -> throw IonException("macro invocation must start with an id (int) or identifier (symbol); found ${reader.encodingType ?: "nothing"}\"")
}

val macroStart = expressions.size
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public IonWriter build(OutputStream out) {
true,
symbolInliningStrategy,
lengthPrefixStrategy,
ManagedWriterOptions_1_1.MacroAddressStrategy.BY_ID
ManagedWriterOptions_1_1.EExpressionIdentifierStrategy.BY_ADDRESS
);
return IonManagedWriter_1_1.binaryWriter(out, options, this);
}
Expand Down

0 comments on commit 770c81e

Please sign in to comment.