Skip to content

Commit

Permalink
Fixes for raw strings tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pczarn committed Nov 24, 2023
1 parent b212b26 commit 4ebdf13
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 11 deletions.
8 changes: 2 additions & 6 deletions compiler/noirc_frontend/src/lexer/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
}
}

Expand Down
14 changes: 11 additions & 3 deletions compiler/noirc_frontend/src/parser/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand All @@ -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 },
Expand Down Expand Up @@ -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 },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
fn main() {
// Fails because of too many hashes for raw string (256+ hashes)
let _a = r##############################################################################################################################################################################################################################################################################"hello"##############################################################################################################################################################################################################################################################################;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "unit"
name = "raw_string"
type = "bin"
authors = [""]

Expand Down
2 changes: 1 addition & 1 deletion tooling/nargo_fmt/src/rewrite/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => {
Expand Down

0 comments on commit 4ebdf13

Please sign in to comment.