mirror of
https://github.com/zaphar/ucg.git
synced 2025-07-22 18:19:54 -04:00
BUGFIX: Allow empty lists in parsing.
This commit is contained in:
parent
0ff3472011
commit
a9b374bf33
1
integration_tests/list_test.ucg
Normal file
1
integration_tests/list_test.ucg
Normal file
@ -0,0 +1 @@
|
||||
let empty_list = [];
|
@ -33,6 +33,11 @@ fn test_tuples() {
|
||||
assert_build(include_str!("../../integration_tests/tuple_test.ucg"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_lists() {
|
||||
assert_build(include_str!("../../integration_tests/list_test.ucg"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_comparisons() {
|
||||
assert_build(include_str!("../../integration_tests/comparisons_test.ucg"));
|
||||
|
@ -331,9 +331,9 @@ make_fn!(
|
||||
)
|
||||
);
|
||||
|
||||
fn tuple_to_list<Sp: Into<Position>>(pos: Sp, elems: Vec<Expression>) -> Value {
|
||||
fn tuple_to_list<Sp: Into<Position>>(pos: Sp, elems: Option<Vec<Expression>>) -> Value {
|
||||
Value::List(ListDef {
|
||||
elems: elems,
|
||||
elems: elems.unwrap_or_else(|| Vec::new()),
|
||||
pos: pos.into(),
|
||||
})
|
||||
}
|
||||
@ -342,7 +342,7 @@ make_fn!(
|
||||
list_value<SliceIter<Token>, Value>,
|
||||
do_each!(
|
||||
start => punct!("["),
|
||||
elements => separated!(punct!(","), expression),
|
||||
elements => optional!(separated!(punct!(","), expression)),
|
||||
_ => optional!(punct!(",")), // nom's opt! macro doesn't preserve error types properly but this one does.
|
||||
_ => punct!("]"),
|
||||
(tuple_to_list(start.pos, elements))
|
||||
|
Loading…
x
Reference in New Issue
Block a user