From 9b367fa2d26468bcaf3b63f61e38be179d907b1a Mon Sep 17 00:00:00 2001 From: Jeremy Wall Date: Fri, 11 Aug 2017 23:16:13 -0500 Subject: [PATCH] Allow '-' and '_' in symbols. --- src/parse.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/parse.rs b/src/parse.rs index e2742e4..3c9c64d 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -154,9 +154,13 @@ named!(equal, tag!("=")); named!(semicolon, tag!(";")); named!(fatcomma, tag!("=>")); +fn is_symbol_char(c: u8) -> bool { + is_alphanumeric(c) || c == '-' as u8 || c == '_' as u8 +} + // a field is the building block of symbols and tuple field names. named!(field, - map_res!(preceded!(peek!(alpha), take_while!(is_alphanumeric)), + map_res!(preceded!(peek!(alpha), take_while!(is_symbol_char)), |s| from_utf8(s).map(|s| s.to_string()) ) ); @@ -1023,6 +1027,10 @@ mod test { fn test_symbol_parsing() { assert_eq!(symbol(&b"foo"[..]), IResult::Done(&b""[..], Value::Symbol("foo".to_string())) ); + assert_eq!(symbol(&b"foo-bar"[..]), + IResult::Done(&b""[..], Value::Symbol("foo-bar".to_string())) ); + assert_eq!(symbol(&b"foo_bar"[..]), + IResult::Done(&b""[..], Value::Symbol("foo_bar".to_string())) ); } #[test]