@top T { (Single | Open "." Close)+ }

@skip { spaces }

@tokens {
  spaces { " "+ }

  Single { "`" toEnd }

  toEnd { "`" | ![`$] toEnd | "$" afterDollarToEnd }

  afterDollarToEnd { "`" | ![`{$] toEnd | "$" afterDollarToEnd }

  Open { "`" toBrace }

  toBrace { ![`$] toBrace | "$" afterDollarToBrace }

  afterDollarToBrace { "{" | ![`\{$] toBrace | "$" afterDollarToBrace }

  Close { "}" toEnd }
}

# Single part

`foo`

==> T(Single)

# Interpolation

`foo${.}bar`

==> T(Open, Close)

# Dollar signs

`$$` `$` `$${.}`

==> T(Single, Single, Open, Close)
