Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
Expand All @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package dev.ionfusion.runtime.base;

import java.io.IOException;
import java.io.UncheckedIOException;

/**
* A specific location within some resource.
Expand Down Expand Up @@ -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();
}
}
Loading