fn __intellij_lalrpop (params) where where_clauses
),
+ * without the opening brace.
+ *
+ * @param withReturnType add the return type? You usually want this to be true, but during type resolution of a nonterminal
+ * like A = B => do_something(<>);
, to use the return type we should know it first, but to know it we must
+ * infer it with the rust plugin, but to infer it we need the header, and this would lead to infinite indirect recursion.
+ */
+fun LpAction.actionCodeFunctionHeader(withReturnType: Boolean = true): String {
+ val alternative = parentOfType<>
and replaces them with something based on evalOfAngleBracketsExpressions and
+ * where they are in the action code (parentheses / brackets / braces).
+ *
+ * @param actionCode The action code in the source lalrpop file
+ * @param evalOfAngleBracketsExpression The list of names for "selected types"
+ *
+ * @return The final rust form the action code will have.
+ */
+fun actionCodeEscape(actionCode: String, evalOfAngleBracketsExpression: List+ Infers the type of a nonterminal and sets the result on said nonterminal. +
+ + + + \ No newline at end of file diff --git a/src/test/kotlin/com/mdrobnak/lalrpop/psi/ext/LpActionLiteralTextEscaperTest.kt b/src/test/kotlin/com/mdrobnak/lalrpop/psi/ext/LpActionLiteralTextEscaperTest.kt new file mode 100644 index 0000000..f105b13 --- /dev/null +++ b/src/test/kotlin/com/mdrobnak/lalrpop/psi/ext/LpActionLiteralTextEscaperTest.kt @@ -0,0 +1,61 @@ +package com.mdrobnak.lalrpop.psi.ext + +import com.mdrobnak.lalrpop.psi.LpSelectedType +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test + +class LpActionLiteralTextEscaperTest { + @Test + fun `no replacements`() { + assertEquals("", actionCodeEscape("", listOf())) + assertEquals("X::Y::new()", actionCodeEscape("X::Y::new()", listOf())) + } + + @Test + fun `simple inside-parentheses replacements`() { + assertEquals( + "X::new(p1, p2, p3)", + actionCodeEscape( + "X::new(<>)", listOf( + LpSelectedType.WithName(name = "p1", type = ""), + LpSelectedType.WithName(name = "p2", type = ""), + LpSelectedType.WithName(name = "p3", type = "") + ) + ) + ) + assertEquals( + "X::new(a, b, c, p1, p2, p3)", + actionCodeEscape( + "X::new(a, b, c, <>)", listOf( + LpSelectedType.WithName(name = "p1", type = ""), + LpSelectedType.WithName(name = "p2", type = ""), + LpSelectedType.WithName(name = "p3", type = "") + ) + ) + ) + } + + @Test + fun `simple inside-braces replacements`() { + assertEquals( + "X {p1: p1, p2: p2, p3: p3}", + actionCodeEscape( + "X {<>}", listOf( + LpSelectedType.WithName(name = "p1", type = ""), + LpSelectedType.WithName(name = "p2", type = ""), + LpSelectedType.WithName(name = "p3", type = "") + ) + ) + ) + assertEquals( + "X {a, b, c, p1: p1, p2: p2, p3: p3}", + actionCodeEscape( + "X {a, b, c, <>}", listOf( + LpSelectedType.WithName(name = "p1", type = ""), + LpSelectedType.WithName(name = "p2", type = ""), + LpSelectedType.WithName(name = "p3", type = "") + ) + ) + ) + } +} \ No newline at end of file