Merge pull request #6360 from roc-lang/more-dollars

Use $(...) in examples and code base, have `roc format` change to `$`
This commit is contained in:
Anton-4 2024-02-28 10:59:20 +01:00 committed by GitHub
commit 660d2b2b25
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 27 additions and 36 deletions

View File

@ -45,7 +45,7 @@ pub fn canonical_string_literal<'a>(_arena: &Bump, _raw: &'a str, _region: Regio
// )? {
// let expr = Expr::Var(ident);
// // +2 for `\(` and then another +1 for `)` at the end
// // +2 for `$(` and then another +1 for `)` at the end
// let parsed_length = buf.len() + 2 + ident.len() + 1;
// // Casting should always succeed in this section, because

View File

@ -612,18 +612,7 @@ fn format_str_segment(seg: &StrSegment, buf: &mut Buf, indent: u16) {
buf.push('\\');
buf.push(escaped.to_parsed_char());
}
DeprecatedInterpolated(loc_expr) => {
buf.push_str("\\(");
// e.g. (name) in "Hi, $(name)!"
loc_expr.value.format_with_options(
buf,
Parens::NotNeeded, // We already printed parens!
Newlines::No, // Interpolations can never have newlines
indent,
);
buf.push(')');
}
Interpolated(loc_expr) => {
DeprecatedInterpolated(loc_expr) | Interpolated(loc_expr) => {
buf.push_str("$(");
// e.g. (name) in "Hi, $(name)!"
loc_expr.value.format_with_options(

View File

@ -4530,7 +4530,7 @@ mod test_reporting {
test_report!(
record_type_tab,
"f : { foo \t }",
@r"
@r###"
TAB CHARACTER in tmp/record_type_tab/Test.roc
I encountered a tab character:
@ -4538,14 +4538,14 @@ mod test_reporting {
4 f : { foo }
^
Tab characters are not allowed, use spaces instead.
"
Tab characters are not allowed in Roc code. Please use spaces instead!
"###
);
test_report!(
comment_with_tab,
"# comment with a \t\n4",
@r"
@r###"
TAB CHARACTER in tmp/comment_with_tab/Test.roc
I encountered a tab character:
@ -4553,8 +4553,8 @@ mod test_reporting {
4 # comment with a
^
Tab characters are not allowed, use spaces instead.
"
Tab characters are not allowed in Roc code. Please use spaces instead!
"###
);
test_report!(
@ -5407,7 +5407,7 @@ mod test_reporting {
test_report!(
weird_escape,
r#""abc\qdef""#,
@r#"
@r###"
WEIRD ESCAPE in tmp/weird_escape/Test.roc
I was partway through parsing a string literal, but I got stuck here:
@ -5424,8 +5424,8 @@ mod test_reporting {
- An escaped quote: \"
- An escaped backslash: \\
- A unicode code point: \u(00FF)
- An interpolated string: \(myVariable)
"#
- An interpolated string: $(myVariable)
"###
);
test_report!(

View File

@ -974,7 +974,7 @@ fn to_str_report<'a>(
suggestion("An escaped quote: ", "\\\""),
suggestion("An escaped backslash: ", "\\\\"),
suggestion("A unicode code point: ", "\\u(00FF)"),
suggestion("An interpolated string: ", "\\(myVariable)"),
suggestion("An interpolated string: ", "$(myVariable)"),
])
.indent(4),
]);
@ -1021,7 +1021,7 @@ fn to_str_report<'a>(
alloc.region_with_subregion(lines.convert_region(surroundings), region),
alloc.concat([
alloc.reflow(r"You could change it to something like "),
alloc.parser_suggestion("\"The count is \\(count\\)\""),
alloc.parser_suggestion("\"The count is $(count)\""),
alloc.reflow("."),
]),
]);
@ -1098,9 +1098,9 @@ fn to_str_report<'a>(
ESingleQuote::InterpolationNotAllowed => {
alloc.stack([
alloc.concat([
alloc.reflow("I am part way through parsing this scalar literal (character literal), "),
alloc.reflow("but I encountered a string interpolation like \"\\(this)\", which is not "),
alloc.reflow("allowed in scalar literals."),
alloc.reflow("I am part way through parsing this single-quote literal, "),
alloc.reflow("but I encountered a string interpolation like \"$(this)\","),
alloc.reflow("which is not allowed in single-quote literals."),
]),
alloc.region_with_subregion(lines.convert_region(surroundings), region),
alloc.concat([
@ -3955,7 +3955,9 @@ fn to_space_report<'a>(
let doc = alloc.stack([
alloc.reflow("I encountered a tab character:"),
alloc.region(region),
alloc.reflow("Tab characters are not allowed, use spaces instead."),
alloc.reflow(
"Tab characters are not allowed in Roc code. Please use spaces instead!",
),
]);
Report {

View File

@ -18,7 +18,7 @@ appendRenderedStatic = \buffer, node ->
Str.concat buffer content
Element name _ attrs children ->
withTagName = "\(buffer)<\(name)"
withTagName = "$(buffer)<$(name)"
withAttrs =
if List.isEmpty attrs then
withTagName
@ -30,12 +30,12 @@ appendRenderedStatic = \buffer, node ->
if Str.isEmpty styles then
attrBuffer
else
"\(attrBuffer) style=\"\(styles)\""
"$(attrBuffer) style=\"$(styles)\""
withTag = Str.concat withAttrs ">"
withChildren = List.walk children withTag appendRenderedStatic
"\(withChildren)</\(name)>"
"$(withChildren)</$(name)>"
None -> buffer
@ -43,12 +43,12 @@ appendRenderedStaticAttr : { buffer : Str, styles : Str }, Attribute [] -> { buf
appendRenderedStaticAttr = \{ buffer, styles }, attr ->
when attr is
HtmlAttr key value ->
newBuffer = "\(buffer) \(key)=\"\(value)\""
newBuffer = "$(buffer) $(key)=\"$(value)\""
{ buffer: newBuffer, styles }
Style key value ->
newStyles = "\(styles) \(key): \(value);"
newStyles = "$(styles) $(key): $(value);"
{ buffer, styles: newStyles }
@ -87,10 +87,10 @@ insertRocScript = \document, initData, wasmUrl, hostJavaScript ->
script = (element "script") [] [
text
"""
\(hostJavaScript)
$(hostJavaScript)
(function(){
const initData = \(jsInitData);
const wasmUrl = \(jsWasmUrl);
const initData = $(jsInitData);
const wasmUrl = $(jsWasmUrl);
window.roc = roc_init(initData, wasmUrl);
})();
""",