Skip to content

Commit

Permalink
Add support for \N.
Browse files Browse the repository at this point in the history
  • Loading branch information
progval committed Jun 17, 2018
1 parent cd6159b commit 51d26e7
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ nom = "^4.0"
#nom_locate = { path = "../nom_locate/" }
nom_locate = { git = "https://github.com/fflorent/nom_locate" }
unicode-xid = "^0.1"
#unicode_names = "^0.1.7"
unicode_names2 = "^0.2.1"
num-traits = { version="^0.2.4", optional=true }
num-bigint = { version="^0.2.0", optional=true }
wtf8 = { version="^0.0.3", optional=true }
Expand Down
4 changes: 4 additions & 0 deletions src/expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,10 @@ mod tests {
assert_parse_eq(atom(make_strspan(r#"'\x8a'"#)), Ok((make_strspan(""),
Box::new(Expression::String(vec![new_pystring("", "\u{8a}")])))
));

assert_parse_eq(atom(make_strspan(r#"'\N{snowman}'"#)), Ok((make_strspan(""),
Box::new(Expression::String(vec![new_pystring("", "☃")])))
));
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ extern crate nom_locate;
extern crate pretty_assertions;

extern crate unicode_xid;
//extern crate unicode_names;
extern crate unicode_names2;

#[cfg(feature="bigint")]
extern crate num_traits;
Expand Down
9 changes: 5 additions & 4 deletions src/strings.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use nom::anychar;

use unicode_names2;

#[cfg(feature="wtf8")]
use wtf8;

Expand Down Expand Up @@ -51,10 +53,9 @@ named!(escapedchar<StrSpan, Option<PyStringCodePoint>>,
_ => unreachable!(),
}
}
//| preceded!(char!('N'), delimited!(char!('{'), none_of!("}"), char!('}'))) => { |name|
// unicode_names::character(name)
// }
| char!('N') => { |_| unimplemented!() }
| preceded!(char!('N'), delimited!(char!('{'), many1!(none_of!("}")), char!('}'))) => { |name: Vec<char>|
unicode_names2::character(&name.iter().collect::<String>()).map(cp_from_char)
}
| preceded!(char!('u'), count!(one_of!("0123456789abcdefABCDEF"), 4)) => { |v: Vec<char>| {
let it: Vec<u32> = v.iter().map(|c| c.to_digit(16).unwrap()).collect();
if let [d1, d2, d3, d4] = &it[..] {
Expand Down

0 comments on commit 51d26e7

Please sign in to comment.