diff --git a/runtime/src/main/java/dev/ionfusion/runtime/_private/util/IonCatalogLoader.java b/runtime/src/main/java/dev/ionfusion/runtime/_private/util/IonCatalogLoader.java index be5829b6..e893c9d5 100644 --- a/runtime/src/main/java/dev/ionfusion/runtime/_private/util/IonCatalogLoader.java +++ b/runtime/src/main/java/dev/ionfusion/runtime/_private/util/IonCatalogLoader.java @@ -13,6 +13,8 @@ import com.amazon.ion.system.IonReaderBuilder; import com.amazon.ion.system.IonSystemBuilder; import com.amazon.ion.system.SimpleCatalog; +import dev.ionfusion.runtime.base.ResourceDescriptor; +import dev.ionfusion.runtime.base.ResourcePosition; import dev.ionfusion.runtime.base.SourceLocation; import dev.ionfusion.runtime.base.SourceName; import java.io.File; @@ -58,15 +60,15 @@ private static boolean hasSharedSymtabAnnotation(IonReader reader) } - private String prefix(SourceLocation loc) + private String prefix(ResourcePosition loc) { return "Error reading symbol table at " + loc.display() + ":\n"; } - void loadSymtab(SourceName name, IonReader reader) + void loadSymtab(ResourceDescriptor rsrc, IonReader reader) { - SourceLocation loc = SourceLocation.forCurrentSpan(reader, name); + ResourcePosition loc = SourceLocation.forCurrentSpan(reader, rsrc); if (reader.getType() != IonType.STRUCT) { @@ -96,7 +98,7 @@ void loadSymtab(SourceName name, IonReader reader) catch (IonException e) { // We use the location of the symtab as a whole, because when things - // fail the IonReader's cursor is usually in between values and thus + // fail, the IonReader's cursor is usually in between values and thus // there's no current span. String message = prefix(loc) + e.getMessage(); throw new IonException(message, e); @@ -107,7 +109,7 @@ void loadSymtab(SourceName name, IonReader reader) private void loadFile(File file) throws IOException { - SourceName name = SourceName.forFile(file.getPath()); + ResourceDescriptor name = SourceName.forFile(file.getPath()); try (FileInputStream stream = new FileInputStream(file); IonReader reader = myReaderBuilder.build(stream)) diff --git a/runtime/src/main/java/dev/ionfusion/runtime/base/ResourcePosition.java b/runtime/src/main/java/dev/ionfusion/runtime/base/ResourcePosition.java index 01d46125..f03d1f5f 100644 --- a/runtime/src/main/java/dev/ionfusion/runtime/base/ResourcePosition.java +++ b/runtime/src/main/java/dev/ionfusion/runtime/base/ResourcePosition.java @@ -4,6 +4,7 @@ package dev.ionfusion.runtime.base; import java.io.IOException; +import java.io.UncheckedIOException; /** * A specific location within some resource. @@ -66,4 +67,26 @@ default ResourceIdentifier getResourceId() */ void display(Appendable out) throws IOException; + + + /** + * Displays this position in a human-readable form, in terms of line, column, and + * resource. Additional semantic context may also be included. + * + * @return not null. + */ + default String display() + { + StringBuilder out = new StringBuilder(); + try + { + display(out); + } + catch (IOException e) + { + // StringBuilder shouldn't throw this, but let's be safe. + throw new UncheckedIOException(e); + } + return out.toString(); + } }