Skip to content

Commit 51d26e7

Browse files
committed
Add support for \N.
1 parent cd6159b commit 51d26e7

File tree

4 files changed

+11
-6
lines changed

4 files changed

+11
-6
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ nom = "^4.0"
1717
#nom_locate = { path = "../nom_locate/" }
1818
nom_locate = { git = "https://github.com/fflorent/nom_locate" }
1919
unicode-xid = "^0.1"
20-
#unicode_names = "^0.1.7"
20+
unicode_names2 = "^0.2.1"
2121
num-traits = { version="^0.2.4", optional=true }
2222
num-bigint = { version="^0.2.0", optional=true }
2323
wtf8 = { version="^0.0.3", optional=true }

src/expressions.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,10 @@ mod tests {
631631
assert_parse_eq(atom(make_strspan(r#"'\x8a'"#)), Ok((make_strspan(""),
632632
Box::new(Expression::String(vec![new_pystring("", "\u{8a}")])))
633633
));
634+
635+
assert_parse_eq(atom(make_strspan(r#"'\N{snowman}'"#)), Ok((make_strspan(""),
636+
Box::new(Expression::String(vec![new_pystring("", "☃")])))
637+
));
634638
}
635639

636640
#[test]

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ extern crate nom_locate;
99
extern crate pretty_assertions;
1010

1111
extern crate unicode_xid;
12-
//extern crate unicode_names;
12+
extern crate unicode_names2;
1313

1414
#[cfg(feature="bigint")]
1515
extern crate num_traits;

src/strings.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use nom::anychar;
22

3+
use unicode_names2;
4+
35
#[cfg(feature="wtf8")]
46
use wtf8;
57

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

0 commit comments

Comments
 (0)