mirror of
https://github.com/zaphar/ucg.git
synced 2025-07-22 18:19:54 -04:00
FEATURE: Allow trailing commas in the tuple, copy, and list syntax
This commit is contained in:
parent
40494fb90e
commit
aa8d2cab29
9
TODO.md
9
TODO.md
@ -22,13 +22,18 @@ Some options here could be:
|
||||
* DSL's
|
||||
* Annotations
|
||||
|
||||
## Built In testing as a part of the language
|
||||
|
||||
* A DSL for assertions.
|
||||
* A DSL for identifying tests.
|
||||
* A way to run tests only during validation stage.
|
||||
|
||||
# Minor Fixes and Polish
|
||||
|
||||
* Strings as tuple fields?
|
||||
* Streaming Parsing
|
||||
* Casting between types?
|
||||
* Better error messages.
|
||||
* Allow trailing commas.
|
||||
* Flags should allow different seperators for prefixed flags.
|
||||
* YAML export
|
||||
* HCL export
|
||||
* Integration Testing framework
|
@ -115,7 +115,8 @@
|
||||
//!
|
||||
//! #### Lists
|
||||
//!
|
||||
//! Lists are surrounded with square brackets `[ ]` and have comma separated elements.
|
||||
//! Lists are surrounded with square brackets `[ ]` and have comma separated elements. Trailing
|
||||
//! commas are permitted in lists.
|
||||
//!
|
||||
//! ```ucg
|
||||
//! [1, 2, 3]; // A simple list of numbers.
|
||||
|
@ -180,6 +180,7 @@ named!(
|
||||
pos: pos >>
|
||||
punct!("{") >>
|
||||
v: field_list >>
|
||||
opt_res!(punct!(",")) >> // nom's opt! macro doesn't preserve error types properly but this one does.
|
||||
punct!("}") >>
|
||||
(pos, Some(v))
|
||||
),
|
||||
@ -199,6 +200,7 @@ named!(list_value<TokenIter, Value, error::Error>,
|
||||
do_parse!(
|
||||
start: punct!("[") >>
|
||||
elements: separated_list!(punct!(","), expression) >>
|
||||
opt_res!(punct!(",")) >> // nom's opt! macro doesn't preserve error types properly but this one does.
|
||||
punct!("]") >>
|
||||
(start.pos, elements)
|
||||
),
|
||||
@ -497,6 +499,7 @@ named!(copy_expression<TokenIter, Expression, error::Error>,
|
||||
selector: selector_list >>
|
||||
punct!("{") >>
|
||||
fields: field_list >>
|
||||
opt_res!(punct!(",")) >> // noms opt! macro does not preserve error types properly but this one does.
|
||||
punct!("}") >>
|
||||
(SelectorDef::new(selector, pos.line, pos.column as usize), fields)
|
||||
),
|
||||
|
@ -768,6 +768,19 @@ fn test_copy_parse() {
|
||||
pos: Position::new(1, 1),
|
||||
})
|
||||
);
|
||||
assert_parse!(
|
||||
copy_expression("foo{bar=1,}"),
|
||||
Expression::Copy(CopyDef {
|
||||
selector: make_selector!(make_expr!("foo", 1, 1), 1, 1),
|
||||
fields: vec![
|
||||
(
|
||||
make_tok!("bar", 1, 5),
|
||||
Expression::Simple(Value::Int(value_node!(1, 1, 9))),
|
||||
),
|
||||
],
|
||||
pos: Position::new(1, 1),
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -822,6 +835,17 @@ fn test_list_value_parse() {
|
||||
})
|
||||
);
|
||||
|
||||
assert_parse!(
|
||||
list_value("[1, 1,]"),
|
||||
Value::List(ListDef {
|
||||
elems: vec![
|
||||
Expression::Simple(Value::Int(value_node!(1, 1, 2))),
|
||||
Expression::Simple(Value::Int(value_node!(1, 1, 5))),
|
||||
],
|
||||
pos: Position::new(1, 1),
|
||||
})
|
||||
);
|
||||
|
||||
assert_parse!(
|
||||
list_value("// comment\n[1, 1]"),
|
||||
Value::List(ListDef {
|
||||
@ -992,6 +1016,23 @@ fn test_tuple_parse() {
|
||||
1
|
||||
))
|
||||
);
|
||||
assert_parse!(
|
||||
tuple("{ foo = 1, bar = {}, }"),
|
||||
Value::Tuple(value_node!(
|
||||
vec![
|
||||
(
|
||||
make_tok!("foo", 1, 3),
|
||||
Expression::Simple(Value::Int(value_node!(1, Position::new(1, 9)))),
|
||||
),
|
||||
(
|
||||
make_tok!("bar", 1, 12),
|
||||
Expression::Simple(Value::Tuple(value_node!(Vec::new(), Position::new(1, 17)))),
|
||||
),
|
||||
],
|
||||
1,
|
||||
1
|
||||
))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
Loading…
x
Reference in New Issue
Block a user