diff --git a/compiler/noirc_frontend/src/lexer/lexer.rs b/compiler/noirc_frontend/src/lexer/lexer.rs index fc1148c1750..3006ccdc5db 100644 --- a/compiler/noirc_frontend/src/lexer/lexer.rs +++ b/compiler/noirc_frontend/src/lexer/lexer.rs @@ -468,12 +468,8 @@ impl<'a> Lexer<'a> { let peek1 = self.peek_char().unwrap_or('X'); let peek2 = self.peek2_char().unwrap_or('X'); match (peek1, peek2) { - ('#', '#') | ('#', '"') | ('"', _) => { - self.eat_raw_string() - } - _ => { - self.eat_alpha_numeric('r') - } + ('#', '#') | ('#', '"') | ('"', _) => self.eat_raw_string(), + _ => self.eat_alpha_numeric('r'), } } diff --git a/compiler/noirc_frontend/src/parser/parser.rs b/compiler/noirc_frontend/src/parser/parser.rs index e223a2d7e2d..ec480734b77 100644 --- a/compiler/noirc_frontend/src/parser/parser.rs +++ b/compiler/noirc_frontend/src/parser/parser.rs @@ -2562,7 +2562,11 @@ mod test { Case { source: r##" r#"\\"# "##, expect: r##"r#"\\"#"##, errors: 0 }, Case { source: r##" r#"\\\"# "##, expect: r##"r#"\\\"#"##, errors: 0 }, // escape sequence - Case { source: r##" r#"\t\n\\t\\n\\\t\\\n\\\\"# "##, expect: r##"r#"\t\n\\t\\n\\\t\\\n\\\\"#"##, errors: 0 }, + Case { + source: r##" r#"\t\n\\t\\n\\\t\\\n\\\\"# "##, + expect: r##"r#"\t\n\\t\\n\\\t\\\n\\\\"#"##, + errors: 0, + }, Case { source: r##" r#"\\\\\\\\"# "##, expect: r##"r#"\\\\\\\\"#"##, errors: 0 }, // mismatch - errors: Case { source: r###" r#"foo"## "###, expect: r###"r#"foo"#"###, errors: 1 }, @@ -2573,7 +2577,7 @@ mod test { // empty string Case { source: r####"r"""####, expect: r####"r"""####, errors: 0 }, Case { source: r####"r###""###"####, expect: r####"r###""###"####, errors: 0 }, - // miscelanneous + // miscellaneous Case { source: r###" r#\"foo\"# "###, expect: "plain::r", errors: 2 }, Case { source: r###" r\"foo\" "###, expect: "plain::r", errors: 1 }, Case { source: r###" r##"foo"# "###, expect: "(none)", errors: 2 }, @@ -2602,7 +2606,11 @@ mod test { Case { source: r##" r#"\\"# "##, expect: r##"r#"\\"#"##, errors: 0 }, Case { source: r##" r#"\\\"# "##, expect: r##"r#"\\\"#"##, errors: 0 }, // escape sequence - Case { source: r##" r#"\t\n\\t\\n\\\t\\\n\\\\"# "##, expect: r##"r#"\t\n\\t\\n\\\t\\\n\\\\"#"##, errors: 0 }, + Case { + source: r##" r#"\t\n\\t\\n\\\t\\\n\\\\"# "##, + expect: r##"r#"\t\n\\t\\n\\\t\\\n\\\\"#"##, + errors: 0, + }, Case { source: r##" r#"\\\\\\\\"# "##, expect: r##"r#"\\\\\\\\"#"##, errors: 0 }, // mismatch - errors: Case { source: r###" r#"foo"## "###, expect: r###"r#"foo"#"###, errors: 1 }, diff --git a/tooling/nargo_cli/tests/compile_failure/raw_string_huge/src/main.nr b/tooling/nargo_cli/tests/compile_failure/raw_string_huge/src/main.nr index eb00c723afe..7bca9942e7a 100644 --- a/tooling/nargo_cli/tests/compile_failure/raw_string_huge/src/main.nr +++ b/tooling/nargo_cli/tests/compile_failure/raw_string_huge/src/main.nr @@ -1,3 +1,4 @@ fn main() { + // Fails because of too many hashes for raw string (256+ hashes) let _a = r##############################################################################################################################################################################################################################################################################"hello"##############################################################################################################################################################################################################################################################################; } diff --git a/tooling/nargo_cli/tests/compile_success_empty/raw_string/Nargo.toml b/tooling/nargo_cli/tests/compile_success_empty/raw_string/Nargo.toml index 7a15bd803c0..81147e65f34 100644 --- a/tooling/nargo_cli/tests/compile_success_empty/raw_string/Nargo.toml +++ b/tooling/nargo_cli/tests/compile_success_empty/raw_string/Nargo.toml @@ -1,5 +1,5 @@ [package] -name = "unit" +name = "raw_string" type = "bin" authors = [""] diff --git a/tooling/nargo_fmt/src/rewrite/expr.rs b/tooling/nargo_fmt/src/rewrite/expr.rs index 4d7279815df..e9a511921ef 100644 --- a/tooling/nargo_fmt/src/rewrite/expr.rs +++ b/tooling/nargo_fmt/src/rewrite/expr.rs @@ -101,7 +101,7 @@ pub(crate) fn rewrite( format_parens(None, visitor.fork(), shape, exprs.len() == 1, exprs, span, false) } ExpressionKind::Literal(literal) => match literal { - Literal::Integer(_) | Literal::Bool(_) | Literal::Str(_) | Literal::FmtStr(_) => { + Literal::Integer(_) | Literal::Bool(_) | Literal::Str(_) | Literal::RawStr(..) | Literal::FmtStr(_) => { visitor.slice(span).to_string() } Literal::Array(ArrayLiteral::Repeated { repeated_element, length }) => {