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

Pretty print fails on separator separated lists #28

Open
RvanBaarle opened this issue Dec 17, 2021 · 1 comment
Open

Pretty print fails on separator separated lists #28

RvanBaarle opened this issue Dec 17, 2021 · 1 comment
Assignees
Labels
Prio-Medium Medium priority Project-Stratego2-Lang Stratego 2 language project Project-StrategoXT Stratego 1 compiler and libraries (from StrategoXT repo) State-Open Type-Bug

Comments

@RvanBaarle
Copy link

Describe the bug

When trying to pretty-print a term containing a separated list ({X ","}*), the pretty-printer fails on pp-H-list due to Cannot cast the following term from string to BoxLiteral: "," (full trace at observed behaviour).

Project

Stratego 2 strategolib library?

Versions

stratego@afde115891ba52b691690ae345ec1375031753c4
spoofax-pie@960c460f9d45d86e3bc09e59c39536bfdd10eb13
(Current heads of the spoofax3 branches)

To Reproduce

Create a project with the following SDF3:

module start

context-free start-symbols

  Start

context-free sorts

  Start
  Word

context-free syntax

  Start.WordList = <<{Word ","}*>>
  Word.Hello = <Hello>

lexical syntax

  LAYOUT = [\ \n\v\f\r]

context-free restrictions

  LAYOUT? -/- [\ \n\v\f\r]

And the following SPT file (where <languagename> should be replaced by the name of the language:

module test

test pp test [[
Hello
]] run pp-<languagename>-string

Observed behaviour

The test fails with the following trace:

Test case failed:
ERROR @ (76, 96) : Invoking Stratego strategy 'pp-broken-string' failed exceptionally
Stratego stack trace:
	pp_H_list_1_1
	with_1_1
	prettyprint_broken_Start_0_0
	prettyprint_broken_start_symbols_0_0
	pp_broken_string_0_0
	pp_broken_string_0_0
Stratego input term:
WordList([Hello(){TermIndex("spt##/broken/test/test.spt!!pp test", 1)}]{TermIndex("spt##/broken/test/test.spt!!pp test", 4)}){TermIndex("spt##/broken/test/test.spt!!pp test", 5)}
mb.stratego.common.StrategoExceptions$ExceptionalFail: Invoking Stratego strategy 'pp-broken-string' failed exceptionally
Stratego stack trace:
	pp_H_list_1_1
	with_1_1
	prettyprint_broken_Start_0_0
	prettyprint_broken_start_symbols_0_0
	pp_broken_string_0_0
	pp_broken_string_0_0
Stratego input term:
WordList([Hello(){TermIndex("spt##/broken/test/test.spt!!pp test", 1)}]{TermIndex("spt##/broken/test/test.spt!!pp test", 4)}){TermIndex("spt##/broken/test/test.spt!!pp test", 5)}
Caused by: org.spoofax.interpreter.core.InterpreterException: Exception during evaluation: Cannot cast the following term from string to BoxLiteral:
","
	at org.spoofax.interpreter.core.Interpreter.evaluate(Interpreter.java:113)
	at org.spoofax.interpreter.core.Interpreter.invoke(Interpreter.java:80)
	at org.strategoxt.HybridInterpreter.invoke(HybridInterpreter.java:458)
	at mb.stratego.common.StrategoRuntime.invokeOrNull(StrategoRuntime.java:169)
	at mb.stratego.common.StrategoRuntime.invoke(StrategoRuntime.java:73)
	at mb.stratego.pie.BaseStrategoTransformTaskDef.lambda$exec$0(BaseStrategoTransformTaskDef.java:84)
	at mb.common.option.Option.mapOrElse(Option.java:137)
	at mb.common.result.Result.flatMapOrElse(Result.java:432)
	at mb.stratego.pie.BaseStrategoTransformTaskDef.exec(BaseStrategoTransformTaskDef.java:79)
	at mb.stratego.pie.BaseStrategoTransformTaskDef.exec(BaseStrategoTransformTaskDef.java:25)
	at mb.pie.api.Task.exec(Task.java:56)
	at mb.pie.runtime.exec.TaskExecutor.execInternal(TaskExecutor.java:130)
	at mb.pie.runtime.exec.TaskExecutor.exec(TaskExecutor.java:87)
	at mb.pie.runtime.exec.TopDownRunner.exec(TopDownRunner.java:194)
	at mb.pie.runtime.exec.TopDownRunner.executeOrGetExisting(TopDownRunner.java:139)
	at mb.pie.runtime.exec.TopDownRunner.require(TopDownRunner.java:81)
	at mb.pie.runtime.exec.TopDownRunner.requireInitial(TopDownRunner.java:59)
	at mb.pie.runtime.MixedSessionImpl.lambda$requireWithoutObserving$2(MixedSessionImpl.java:110)
	at mb.pie.runtime.SessionImpl.handleException(SessionImpl.java:215)
	at mb.pie.runtime.MixedSessionImpl.requireWithoutObserving(MixedSessionImpl.java:110)
	at mb.pie.runtime.MixedSessionImpl.requireWithoutObserving(MixedSessionImpl.java:104)
	at mb.broken.BrokenInstance.testRunStrategy(%2Fbroken%2Fbuild%2Fgenerated%2Fsources%2Fadapter%2Fmb%2Fbroken%2FBrokenInstance.java:699)
	at mb.spt.expectation.RunStrategoExpectation.evaluate(RunStrategoExpectation.java:79)
	at mb.spt.task.SptRunTestSuite.runTests(SptRunTestSuite.java:183)
	at mb.spt.task.SptRunTestSuite.lambda$runTests$2(SptRunTestSuite.java:158)
	at mb.common.option.Option.mapThrowingOrElse(Option.java:141)
	at mb.common.result.Result.mapThrowingOrElse(Result.java:372)
	at mb.spt.task.SptRunTestSuite.runTests(SptRunTestSuite.java:156)
	at mb.spt.task.SptRunTestSuite.lambda$exec$0(SptRunTestSuite.java:121)
	at mb.common.option.Option.mapThrowingOrElse(Option.java:141)
	at mb.common.result.Result.mapThrowingOrElse(Result.java:372)
	at mb.spt.task.SptRunTestSuite.exec(SptRunTestSuite.java:119)
	at mb.spt.task.SptRunTestSuite.exec(SptRunTestSuite.java:46)
	at mb.pie.api.Task.exec(Task.java:56)
	at mb.pie.runtime.exec.TaskExecutor.execInternal(TaskExecutor.java:130)
	at mb.pie.runtime.exec.TaskExecutor.exec(TaskExecutor.java:87)
	at mb.pie.runtime.exec.TopDownRunner.exec(TopDownRunner.java:194)
	at mb.pie.runtime.exec.TopDownRunner.executeOrGetExisting(TopDownRunner.java:139)
	at mb.pie.runtime.exec.TopDownRunner.require(TopDownRunner.java:81)
	at mb.pie.runtime.exec.ExecContextImpl.require(ExecContextImpl.java:118)
	at mb.pie.runtime.exec.ExecContextImpl.require(ExecContextImpl.java:98)
	at mb.spt.task.SptShowTestSuiteResults.exec(SptShowTestSuiteResults.java:61)
	at mb.spt.task.SptShowTestSuiteResults.exec(SptShowTestSuiteResults.java:20)
	at mb.pie.api.Task.exec(Task.java:56)
	at mb.pie.runtime.exec.TaskExecutor.execInternal(TaskExecutor.java:130)
	at mb.pie.runtime.exec.TaskExecutor.exec(TaskExecutor.java:87)
	at mb.pie.runtime.exec.TopDownRunner.exec(TopDownRunner.java:194)
	at mb.pie.runtime.exec.TopDownRunner.executeOrGetExisting(TopDownRunner.java:139)
	at mb.pie.runtime.exec.TopDownRunner.require(TopDownRunner.java:81)
	at mb.pie.runtime.exec.TopDownRunner.requireInitial(TopDownRunner.java:59)
	at mb.pie.runtime.MixedSessionImpl.lambda$requireWithoutObserving$2(MixedSessionImpl.java:110)
	at mb.pie.runtime.SessionImpl.handleException(SessionImpl.java:215)
	at mb.pie.runtime.MixedSessionImpl.requireWithoutObserving(MixedSessionImpl.java:110)
	at mb.spoofax.eclipse.pie.PieRunner.requireWithoutObserving(PieRunner.java:490)
	at mb.spoofax.eclipse.pie.PieRunner.requireCommand(PieRunner.java:320)
	at mb.spoofax.eclipse.command.RunCommandJob.run(RunCommandJob.java:67)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)
Caused by: org.strategoxt.lang.gradual.StrategoCastException: Cannot cast the following term from string to BoxLiteral:
","
	at org.strategoxt.lang.gradual.Cast.check(Cast.java:13)
	at mb.broken.strategies.pp_$H_list_1_1.invoke(%2Fbroken%2Fbuild%2Fgenerated%2Fsources%2FlanguageSpecification%2Fjava%2Fmb%2Fbroken%2Fstrategies%2Fpp_%24H_list_1_1.java:27)
	at mb.broken.strategies.prettyprint_broken_$Start_0_0_lifted0.invoke(%2Fbroken%2Fbuild%2Fgenerated%2Fsources%2FlanguageSpecification%2Fjava%2Fmb%2Fbroken%2Fstrategies%2Fprettyprint_broken_%24Start_0_0_lifted0.java:33)
	at strategolib.trans.with_1_1.invoke(with_1_1.java:17)
	at mb.broken.strategies.prettyprint_broken_$Start_0_0.invoke(%2Fbroken%2Fbuild%2Fgenerated%2Fsources%2FlanguageSpecification%2Fjava%2Fmb%2Fbroken%2Fstrategies%2Fprettyprint_broken_%24Start_0_0.java:29)
	at mb.broken.strategies.prettyprint_broken_start_symbols_0_0.invoke(%2Fbroken%2Fbuild%2Fgenerated%2Fsources%2FlanguageSpecification%2Fjava%2Fmb%2Fbroken%2Fstrategies%2Fprettyprint_broken_start_symbols_0_0.java:11)
	at mb.broken.strategies.pp_broken_string_0_0.invoke(%2Fbroken%2Fbuild%2Fgenerated%2Fsources%2FlanguageSpecification%2Fjava%2Fmb%2Fbroken%2Fstrategies%2Fpp_broken_string_0_0.java:15)
	at org.strategoxt.lang.Strategy.invokeDynamic(Strategy.java:33)
	at org.strategoxt.lang.InteropSDefT.evaluate(InteropSDefT.java:192)
	at org.strategoxt.lang.InteropSDefT.evaluate(InteropSDefT.java:183)
	at org.strategoxt.lang.InteropSDefT$StrategyBody.evaluate(InteropSDefT.java:245)
	at org.spoofax.interpreter.core.Interpreter.evaluate(Interpreter.java:105)
	... 56 more

Expected behaviour

The test succeeds, and the pp-<languagename>-string strategy should produce a pretty printed string of it's input).
Additional context
Add any other context about the problem here.

@Apanatshka Apanatshka added Prio-Blocking Blocking issue Project-Stratego2-Lang Stratego 2 language project Project-StrategoXT Stratego 1 compiler and libraries (from StrategoXT repo) State-Open and removed State-Triage labels Dec 17, 2021
@RvanBaarle
Copy link
Author

As a workaround the following can be added to a stratego file in the project:

signature
  sorts BoxLiteral
  constructors
    : string -> BoxLiteral

@Apanatshka Apanatshka added Prio-Medium Medium priority and removed Prio-Blocking Blocking issue labels Dec 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Prio-Medium Medium priority Project-Stratego2-Lang Stratego 2 language project Project-StrategoXT Stratego 1 compiler and libraries (from StrategoXT repo) State-Open Type-Bug
Projects
None yet
Development

No branches or pull requests

2 participants