mirror of
https://github.com/zaphar/ucg.git
synced 2025-07-23 18:29:50 -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"));
|
assert_build(include_str!("../../integration_tests/tuple_test.ucg"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_lists() {
|
||||||
|
assert_build(include_str!("../../integration_tests/list_test.ucg"));
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_comparisons() {
|
fn test_comparisons() {
|
||||||
assert_build(include_str!("../../integration_tests/comparisons_test.ucg"));
|
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 {
|
Value::List(ListDef {
|
||||||
elems: elems,
|
elems: elems.unwrap_or_else(|| Vec::new()),
|
||||||
pos: pos.into(),
|
pos: pos.into(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -342,7 +342,7 @@ make_fn!(
|
|||||||
list_value<SliceIter<Token>, Value>,
|
list_value<SliceIter<Token>, Value>,
|
||||||
do_each!(
|
do_each!(
|
||||||
start => punct!("["),
|
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.
|
_ => optional!(punct!(",")), // nom's opt! macro doesn't preserve error types properly but this one does.
|
||||||
_ => punct!("]"),
|
_ => punct!("]"),
|
||||||
(tuple_to_list(start.pos, elements))
|
(tuple_to_list(start.pos, elements))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user