Skip to content

Commit

Permalink
Added support for newlines in string literals
Browse files Browse the repository at this point in the history
  • Loading branch information
theangrydev committed May 13, 2021
1 parent 1d44be3 commit 223f0d9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
Expand Up @@ -271,12 +271,12 @@ PIPE

DOUBLE_STRING
:
'"' ( '\\"' | ~[\n] )*? '"'
'"' ( '\\"' | . )*? '"'
;

SINGLE_STRING
:
'\'' ( '\\\'' | ~[\n] )*? '\''
'\'' ( '\\\'' | . )*? '\''
;

EQ
Expand Down
Expand Up @@ -84,4 +84,29 @@ public Object apply(final String cruel, final Options options) throws IOExceptio
"block helpers with multiple params");
}

@Test
public void usingNewlinesInDoubleStringIsAllowed() throws IOException {
String string = "Message: {{{hello \"before\" \"multi\nline\" \"after\"}}}";
Hash helpers = $("hello", new Helper<String>() {
@Override
public Object apply(final String param, final Options options) throws IOException {
return "Hello " + param + " " + options.param(0) + " " + options.param(1);
}
});
shouldCompileTo(string, $, helpers, "Message: Hello before multi\nline after",
"template with an escaped String literal");
}

@Test
public void usingNewlinesInSingleStringIsAllowed() throws IOException {
String string = "Message: {{{hello 'before' 'multi\nline' 'after' }}}";
Hash helpers = $("hello", new Helper<String>() {
@Override
public Object apply(final String param, final Options options) throws IOException {
return "Hello " + param + " " + options.param(0) + " " + options.param(1);
}
});
shouldCompileTo(string, $, helpers, "Message: Hello before multi\nline after",
"template with an escaped String literal");
}
}

0 comments on commit 223f0d9

Please sign in to comment.