Class BacktickString

java.lang.Object
org.ek9lang.compiler.support.BacktickString

public final class BacktickString extends Object
THE rewrite of a double-quoted String's text as a backtick String — use this; never re-derive it.

EK9 has two String literals. A double-quoted String is plain text and is never interpolated, so a ${...} inside one prints as those characters — almost always a misunderstanding carried from Kotlin, Groovy, Dart, PHP or a shell, where double quotes DO interpolate. The compiler therefore rejects ${ in a double-quoted String (E07901). A backtick String is interpolated: ${...} evaluates, and \$ writes a literal dollar.

🔑 So such a text has exactly two backtick spellings, and both come from here: interpolating(String) (every ${...} evaluates — what the writer almost always meant) and literal(String) (every ${ kept as characters). Both escape what a backtick String needs and a double-quoted one does not — a $ that opens no interpolation, and a backtick — write \" as a plain " (a backtick String needs no escape for it), and carry every other escape pair (\n, \$, ...) over as written. The concatenation rewriter renders its literal segments through literal(String) too, so there is one rule for all three.

The compiler's E07901 message and the tooling's applied repair both call this, so the spelling the message names is always the spelling the repair writes.

  • Method Details

    • holdsInterpolation

      public static boolean holdsInterpolation(String doubleQuotedText)
      Does the text between a double-quoted String's quotes hold ${?
    • interpolating

      public static String interpolating(String doubleQuotedText)
      The backtick String, delimiters included, in which every ${...} of the text evaluates.
    • literal

      public static String literal(String doubleQuotedText)
      The backtick String, delimiters included, whose value keeps every ${ as characters.