Relax whitespace rules for edn vectors, lists, sets and maps

Signed-off-by: Victor Porof <vporof@mozilla.com>
This commit is contained in:
Victor Porof 2017-02-04 08:45:31 +01:00
parent 419db388da
commit a627f532f0
2 changed files with 66 additions and 8 deletions

View file

@ -107,17 +107,17 @@ pub keyword -> Value =
} }
pub list -> Value = pub list -> Value =
"(" v:(value)* ")" { "(" __ v:(value)* __ ")" {
Value::List(LinkedList::from_iter(v)) Value::List(LinkedList::from_iter(v))
} }
pub vector -> Value = pub vector -> Value =
"[" v:(value)* "]" { "[" __ v:(value)* __ "]" {
Value::Vector(v) Value::Vector(v)
} }
pub set -> Value = pub set -> Value =
"#{" v:(value)* "}" { "#{" __ v:(value)* __ "}" {
Value::Set(BTreeSet::from_iter(v)) Value::Set(BTreeSet::from_iter(v))
} }
@ -127,7 +127,7 @@ pair -> (Value, Value) =
} }
pub map -> Value = pub map -> Value =
"{" v:(pair)* "}" { "{" __ v:(pair)* __ "}" {
Value::Map(BTreeMap::from_iter(v)) Value::Map(BTreeMap::from_iter(v))
} }

View file

@ -185,6 +185,17 @@ fn test_vector() {
]); ]);
assert_eq!(vector(test).unwrap(), value); assert_eq!(vector(test).unwrap(), value);
let test = "[ ]";
let value = Vector(vec![
]);
assert_eq!(vector(test).unwrap(), value);
let test = "[1]";
let value = Vector(vec![
Integer(1),
]);
assert_eq!(vector(test).unwrap(), value);
let test = "[ 1 ]"; let test = "[ 1 ]";
let value = Vector(vec![ let value = Vector(vec![
Integer(1), Integer(1),
@ -246,6 +257,17 @@ fn test_list() {
])); ]));
assert_eq!(list(test).unwrap(), value); assert_eq!(list(test).unwrap(), value);
let test = "( )";
let value = List(LinkedList::from_iter(vec![
]));
assert_eq!(list(test).unwrap(), value);
let test = "(1)";
let value = List(LinkedList::from_iter(vec![
Integer(1),
]));
assert_eq!(list(test).unwrap(), value);
let test = "( 1 )"; let test = "( 1 )";
let value = List(LinkedList::from_iter(vec![ let value = List(LinkedList::from_iter(vec![
Integer(1), Integer(1),
@ -306,6 +328,17 @@ fn test_set() {
])); ]));
assert_eq!(set(test).unwrap(), value); assert_eq!(set(test).unwrap(), value);
let test = "#{ }";
let value = Set(BTreeSet::from_iter(vec![
]));
assert_eq!(set(test).unwrap(), value);
let test = "#{1}";
let value = Set(BTreeSet::from_iter(vec![
Integer(1),
]));
assert_eq!(set(test).unwrap(), value);
let test = "#{ 1 }"; let test = "#{ 1 }";
let value = Set(BTreeSet::from_iter(vec![ let value = Set(BTreeSet::from_iter(vec![
Integer(1), Integer(1),
@ -370,6 +403,17 @@ fn test_map() {
])); ]));
assert_eq!(map(test).unwrap(), value); assert_eq!(map(test).unwrap(), value);
let test = "{ }";
let value = Map(BTreeMap::from_iter(vec![
]));
assert_eq!(map(test).unwrap(), value);
let test = "{\"a\" 1}";
let value = Map(BTreeMap::from_iter(vec![
(Text("a".to_string()), Integer(1)),
]));
assert_eq!(map(test).unwrap(), value);
let test = "{ \"a\" 1 }"; let test = "{ \"a\" 1 }";
let value = Map(BTreeMap::from_iter(vec![ let value = Map(BTreeMap::from_iter(vec![
(Text("a".to_string()), Integer(1)), (Text("a".to_string()), Integer(1)),
@ -383,6 +427,13 @@ fn test_map() {
])); ]));
assert_eq!(map(test).unwrap(), value); assert_eq!(map(test).unwrap(), value);
let test = "{ nil 1 \"b\" 2 }";
let value = Map(BTreeMap::from_iter(vec![
(Nil, Integer(1)),
(Text("b".to_string()), Integer(2)),
]));
assert_eq!(map(test).unwrap(), value);
let test = "{nil 1, \"b\" 2, \"a\" 3}"; let test = "{nil 1, \"b\" 2, \"a\" 3}";
let value = Map(BTreeMap::from_iter(vec![ let value = Map(BTreeMap::from_iter(vec![
(Nil, Integer(1)), (Nil, Integer(1)),
@ -391,6 +442,14 @@ fn test_map() {
])); ]));
assert_eq!(map(test).unwrap(), value); assert_eq!(map(test).unwrap(), value);
let test = "{ nil 1 \"b\" 2 \"a\" 3}";
let value = Map(BTreeMap::from_iter(vec![
(Nil, Integer(1)),
(Text("a".to_string()), Integer(3)),
(Text("b".to_string()), Integer(2)),
]));
assert_eq!(map(test).unwrap(), value);
let test = "{:a 1, $b {:b/a nil, :b/b #{nil 5}}, c [1 2], d (3 4)}"; let test = "{:a 1, $b {:b/a nil, :b/b #{nil 5}}, c [1 2], d (3 4)}";
let value = Map( let value = Map(
BTreeMap::from_iter( BTreeMap::from_iter(
@ -398,7 +457,6 @@ fn test_map() {
(Keyword(symbols::Keyword::new("a")), Integer(1)), (Keyword(symbols::Keyword::new("a")), Integer(1)),
(s_plain("$b"), Map(BTreeMap::from_iter(vec![ (s_plain("$b"), Map(BTreeMap::from_iter(vec![
(k_ns("b", "a"), Nil), (k_ns("b", "a"), Nil),
(k_ns("b", "b"), (k_ns("b", "b"),
Set(BTreeSet::from_iter(vec![Nil, Integer(5),]))), Set(BTreeSet::from_iter(vec![Nil, Integer(5),]))),
]))), ]))),