[][src]Module autumn::list

Persistent linked-list data structure

This list data structure is used as it reduces the number of duplicates maintained in the parser as it considers multiple potentially valid alternative parses.

It is used internally to maintain the set of errors produces for a particular parse as well as for parsers returning lists of values.

The list is actually implemented as a first-in last-out stack structure so items in a parser that produce a list will be the reverse of the order in which they were parsed.

Lists are also iterators over their elements. The iterator item of the list is an Rc of its elements.

let values = &[0, 1, 2, 3, 4, 5, 6, 7, 8];
let list_a = values[1..5].iter().fold(List::single(0), |list, value| list.push(*value));
let list_b = values[5..9].iter().fold(List::new(), |list, value| list.push(*value));
let joined = list_a.concat(&list_b);

for (list_value, array_value) in joined.reverse().zip(values.iter()) {
    assert_eq!(*list_value, *array_value);
}

Structs

Drain

Remove the items from a List in reverse order

Iter

An iterator over the items of a List

List

Persistent linked-list data structure