Using Spoofax Core (version 2.1), you can:

  1. Use the ISpoofaxInputUnitService to create an ISpoofaxInputUnit from a string (i.e. without FileObject as source).
  2. Use the ISpoofaxSyntaxService to parse the ISpoofaxInputUnit and get an ISpoofaxParseUnit.
  3. Use the ISpoofaxParseUnit to analyze and get a ISpoofaxAnalyzeResult.

If there are messages (e.g. errors), then Spoofax uses the TracingService, which in turn uses the SourceAttachment, to determine the filename that contains the error. Since there is no file to begin with (remember: we created the parse from a string, not a file), this throws a big nasty exception:

java.lang.IllegalArgumentException
	at org.apache.commons.vfs2.impl.DefaultFileSystemManager.resolveFile(DefaultFileSystemManager.java:793)
	at org.apache.commons.vfs2.impl.DefaultFileSystemManager.resolveFile(DefaultFileSystemManager.java:726)
	at org.metaborg.core.resource.ResourceService.resolve(ResourceService.java:75)
	at org.metaborg.spoofax.core.syntax.SourceAttachment.getResource(SourceAttachment.java:60)
	at org.metaborg.spoofax.core.tracing.TracingService.tokenLocation(TracingService.java:52)
	at org.metaborg.spoofax.core.tracing.TracingService.location(TracingService.java:42)
	at org.metaborg.spoofax.core.tracing.TracingService.location(TracingService.java:1)
	at org.metaborg.spoofax.core.analysis.AnalysisCommon.messages(AnalysisCommon.java:52)
	at org.metaborg.spoofax.core.analysis.taskengine.TaskEngineAnalyzer.result(TaskEngineAnalyzer.java:213)
	at org.metaborg.spoofax.core.analysis.taskengine.TaskEngineAnalyzer.analyzeAll(TaskEngineAnalyzer.java:164)
	at org.metaborg.spoofax.core.analysis.taskengine.TaskEngineAnalyzer.analyzeAll(TaskEngineAnalyzer.java:112)
	at org.metaborg.spoofax.core.analysis.taskengine.TaskEngineAnalyzer.analyze(TaskEngineAnalyzer.java:88)
	at org.metaborg.spoofax.core.analysis.taskengine.TaskEngineAnalyzer.analyze(TaskEngineAnalyzer.java:1)
	at org.metaborg.core.analysis.AnalysisService.analyze(AnalysisService.java:27)
	at org.metaborg.spoofax.core.analysis.SpoofaxAnalysisService.analyze(SpoofaxAnalysisService.java:17)

I worked around this issue by storing the program in a file on the VFS, but it might be worth fixing this issue (or mentioning in the docs that analysis with NaBL1 does not work on programs that do not originate from a file). With NaBL2 being the future (and NaBL1 being deprecated), it’s not a pressing issue anyway.

Submitted by Martijn on 11 May 2017 at 18:45

Log in to post comments