Skip to content

Commit d0f1002

Browse files
authored
Merge pull request #29 from fink-lang/fix-string
fix(strings): fix escape char handling for template expressions
2 parents e4b2a2f + 60613f8 commit d0f1002

File tree

4 files changed

+10
-4
lines changed

4 files changed

+10
-4
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"devDependencies": {
3636
"@fink/cli": "^2.1.0",
3737
"@fink/jest": "^1.1.0",
38-
"@fink/larix": "^4.5.2",
38+
"@fink/larix": "4.5.2",
3939
"@fink/loxia": "^4.5.1",
4040
"commitizen": "^4.0.3",
4141
"cz-conventional-changelog": "^3.1.0",

src/lang/literals/string.fnk

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ get_str_part = fn ctx, op:
2222
'`': collect_text(ctx, rx/`|\${/)
2323
else: collect_text(ctx, rx/'|\${/)
2424

25-
2625
# TODO: can we do the escapeing check in the regex above?
2726
[escaped] = text.match(rx/\\*$/)
2827

@@ -31,18 +30,19 @@ get_str_part = fn ctx, op:
3130
[{type: 'string:text', value: text, loc: {start, end}}, next_ctx]
3231

3332
else:
33+
# TODO: stop_value should come from prattler
34+
stop_value = curr_value(next_ctx)
3435
[str_part, final_ctx] = get_str_part(next_ctx, op)
3536

3637
[{
3738
type: 'string:text',
38-
value: `${text}${op}${str_part.value}`,
39+
value: `${text}${stop_value}${str_part.value}`,
3940
loc: {start, end: str_part.loc.end}
4041
}, final_ctx]
4142

4243

4344
get_parts = fn ctx, op:
4445
[str_part, next_ctx] = get_str_part(ctx, op)
45-
4646
match true:
4747
# TODO: should not need to escape `$` unless it is `${`
4848
curr_value(next_ctx) == '\$':

src/lang/literals/string.test.fnk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ describe:: 'strings', fn:
3131
parse_expr('` \$ \\n \\t \\` \\\\`') eq snapshot
3232
parse_expr(`' \$ \\n \\t \\' \\\\'`) eq snapshot
3333
parse_expr(`" \$ \\n \\t \\" \\\\"`) eq snapshot
34+
parse_expr(`'foo \\\${bar + spam}'`) eq snapshot
3435

3536

3637
it:: 'parses tagged strings', fn:

src/lang/literals/string.test.fnk.snap

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ string " (1:0-1:16)
3838
\` $ \\n \\t \\" \\\\\`
3939
`;
4040

41+
exports[`strings parses escape characters 4`] = `
42+
string ' (1:0-1:20)
43+
\`foo \\\${bar + spam}\`
44+
`;
45+
4146
exports[`strings parses multi line strings 1`] = `
4247
string ' (1:0-4:9)
4348
\`foobar

0 commit comments

Comments
 (0)