Skip to content

Commit

Permalink
Another string interpolation test case
Browse files Browse the repository at this point in the history
  • Loading branch information
camdenorrb committed Jan 3, 2022
1 parent 9be072e commit a44978f
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -956,11 +956,12 @@ object CrescentParser {
continue
}

if (nextChar != '$') {
if (nextChar != '$' || (!iterator.peekNext().isLetter() && iterator.peekNext() != '{')) {
builder.append(nextChar)
continue
}


if (builder.isNotEmpty() || (builder.isEmpty() && nodes.isEmpty())) {
nodes += CrescentAST.Node.Primitive.String(builder.toString())
builder.clear()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ internal class CrescentLexerTests {
Data.Comment("Should println dollar sign next to the letter x"),
Key("println"), Parenthesis.OPEN, Data.String("\\\$x"), Parenthesis.CLOSE,

Key("println"), Parenthesis.OPEN, Data.String("$ x"), Parenthesis.CLOSE,

Bracket.CLOSE,
),
tokens
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ internal class CrescentParserTests {

IdentifierCall("println", listOf(Expression(listOf(String(""), Char('$'), ADD)))),
IdentifierCall("println", listOf(String("\$x"))),

IdentifierCall("println", listOf(String("$ x"))),
),
mainFunction.innerCode.nodes,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ internal class CrescentVMTests {
Hello 0Hello0Hello0 Hello
$
${'$'}x
$ x
""".trimIndent(),
collectSystemOut {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ internal object TestCode {
# Should println dollar sign next to the letter x
println("\${'$'}x")
println("$ x")
}
"""

Expand Down

0 comments on commit a44978f

Please sign in to comment.