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 =
"(" v:(value)* ")" {
"(" __ v:(value)* __ ")" {
Value::List(LinkedList::from_iter(v))
}
pub vector -> Value =
"[" v:(value)* "]" {
"[" __ v:(value)* __ "]" {
Value::Vector(v)
}
pub set -> Value =
"#{" v:(value)* "}" {
"#{" __ v:(value)* __ "}" {
Value::Set(BTreeSet::from_iter(v))
}
@ -127,7 +127,7 @@ pair -> (Value, Value) =
}
pub map -> Value =
"{" v:(pair)* "}" {
"{" __ v:(pair)* __ "}" {
Value::Map(BTreeMap::from_iter(v))
}

View file

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