Skip to content

Conversation

@timsueberkrueb
Copy link
Contributor

@timsueberkrueb timsueberkrueb commented Nov 5, 2025

Currently, it is very hard to write tests for core. There are two main reasons for this:

  1. The core parser is currently very rudimentary and it is not easy to write core programs. This would be addressed by a new core frontend (WIP: New core frontend #1152).
  2. The core pretty-printer is currently unable to produce code that can be re-parsed with the core parser. I would like to address this with this PR.

While a new core frontend would subsume both of these problems, it is a lot more effort than adding a re-parsable mode to the current core pretty-printer. This would allow us to compile source programs to core and pretty-print them to use them as golden output in core tests.

In particular, when developing the new normalizer (#1127), I would like to track its behavior in unit tests, but they are currently very time-consuming to write due to the fact I cannot just use pretty-printed core for comparison.

lazy val externBodyTemplate: P[Template[Expr]] =
(
(multilineString | stringLiteral) ~
rep((`++` ~> expr) ~ (`++` ~> (multilineString | stringLiteral)))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I chose the syntax "string" ++ (<expr> ++ "string")* for extern body template strings because it is easy to parse. Open to to other suggestions!

case _: kiama.util.StringSource => "string"
case _ => "source"
}
"<>" <+> s"@ \"$scheme://$name\":$from:$to"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: proper escaping

// FIXME: There is currently a limitation in TestRenamer in that it does not rename captures.
// This means, that in this example, captures for State[Int] and State[String] are both printed as "State",
// leading to a collapse of the capture set {State_1, State_2} to just {State}.
File("examples/pos/parametrized.effekt")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marzipankaiser this is what I just mentioned in person.

@timsueberkrueb timsueberkrueb marked this pull request as ready for review November 19, 2025 10:53
Copy link
Contributor

@jiribenes jiribenes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went over this in five minutes, see comments below. I'm fine with merging this if you need it (though it would be nice if somebody who actually knows something about core reviewed it)

@timsueberkrueb timsueberkrueb merged commit bd89bbc into master Nov 27, 2025
7 checks passed
@timsueberkrueb timsueberkrueb deleted the core-pretty-parity branch November 27, 2025 13:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants