Skip to content

Commit

Permalink
Fix escape sequences in Rust lexer
Browse files Browse the repository at this point in the history
As discussed in rouge-ruby#1075, escaped double quotes were not being interpreted
correctly. This was due to an escaped double quote not being included in
the escape sequence regex in the Rust lexer.

This commit adds the double quote and the numeral zero (the null
character). See:
https://static.rust-lang.org/doc/master/reference.html#characters-and-strings

This fixes rouge-ruby#1075.
  • Loading branch information
pyrmont committed May 19, 2019
1 parent e957c74 commit 5e75c99
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rouge/lexers/rust.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def macro_closed?
id = /[a-z_]\w*/i
hex = /[0-9a-f]/i
escapes = %r(
\\ ([nrt'\\] | x#{hex}{2} | u#{hex}{4} | U#{hex}{8})
\\ ([nrt'"\\0] | x#{hex}{2} | u#{hex}{4} | U#{hex}{8})
)x
size = /8|16|32|64/

Expand Down
5 changes: 5 additions & 0 deletions spec/visual/samples/rust
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ fn main() {

let mut f = File::open("username.txt")?;

println!("a\\");
println!("a\n");
println!("a\"b");
println!("a\'");

debug!("test %?", a.b);
debug!("test %u", a.c);
debug!("test %i", a.d);
Expand Down

0 comments on commit 5e75c99

Please sign in to comment.