mirror of
https://github.com/zaphar/ucg.git
synced 2025-07-22 18:19:54 -04:00
FEATURE: Allow Quoted strings as a field name in Tuples.
Also add tuple specific regression tests.
This commit is contained in:
parent
4795945caf
commit
6bcf822c41
1
TODO.md
1
TODO.md
@ -14,7 +14,6 @@ compiled configuration.
|
|||||||
# Minor Fixes and Polish
|
# Minor Fixes and Polish
|
||||||
|
|
||||||
* Compiler caching (interface has been defined)
|
* Compiler caching (interface has been defined)
|
||||||
* Strings as tuple fields?
|
|
||||||
* Streaming Parsing?
|
* Streaming Parsing?
|
||||||
* Casting between types?
|
* Casting between types?
|
||||||
* Better error messages.
|
* Better error messages.
|
||||||
|
24
integration_tests/tuple_test.ucg
Normal file
24
integration_tests/tuple_test.ucg
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
let simpletpl = {
|
||||||
|
foo = "bar"
|
||||||
|
};
|
||||||
|
|
||||||
|
let stringfieldtpl = {
|
||||||
|
"field 1" = 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
let nestedtpl = {
|
||||||
|
inner = {
|
||||||
|
field = "value",
|
||||||
|
},
|
||||||
|
scalar = 1,
|
||||||
|
list = [1, 2, 3, 4],
|
||||||
|
};
|
||||||
|
|
||||||
|
assert |simpletpl.foo == "bar"|;
|
||||||
|
assert |stringfieldtpl."field 1" == 1|;
|
||||||
|
assert |nestedtpl.scalar == 1|;
|
||||||
|
assert |nestedtpl.inner.field == "value"|;
|
||||||
|
assert |nestedtpl.list.0 == 1|;
|
||||||
|
assert |nestedtpl.list.1 == 2|;
|
||||||
|
assert |nestedtpl.list.2 == 3|;
|
||||||
|
assert |nestedtpl.list.3 == 4|;
|
@ -28,6 +28,11 @@ fn assert_build(input: &str) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_tuples() {
|
||||||
|
assert_build(include_str!("../../integration_tests/tuple_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"));
|
||||||
|
@ -139,7 +139,7 @@
|
|||||||
//!
|
//!
|
||||||
//! Tuple's are an ordered collection of name, value pairs. They are bounded by curly braces `{ }`
|
//! Tuple's are an ordered collection of name, value pairs. They are bounded by curly braces `{ }`
|
||||||
//! and contain name = value pairs separated by commas. Trailing commas are permitted. The name must
|
//! and contain name = value pairs separated by commas. Trailing commas are permitted. The name must
|
||||||
//! be a bareword without quotes.
|
//! be either a bareword without quotes or a quoted string.
|
||||||
//!
|
//!
|
||||||
//! ```ucg
|
//! ```ucg
|
||||||
//! let mytuple = {
|
//! let mytuple = {
|
||||||
@ -160,7 +160,7 @@
|
|||||||
//!
|
//!
|
||||||
//! Selectors are references to a bound value in ucg. They can index arbitrarily deep into either tuples or lists.
|
//! Selectors are references to a bound value in ucg. They can index arbitrarily deep into either tuples or lists.
|
||||||
//! The head of a selector can be a tuple or list or symbol. Optionally a selector can also be followed by either a
|
//! The head of a selector can be a tuple or list or symbol. Optionally a selector can also be followed by either a
|
||||||
//! bareword to index a tuple field or an integer to index a list position.
|
//! bareword or string to index a tuple field or an integer to index a list position.
|
||||||
//!
|
//!
|
||||||
//! The simplest selector is just a reference to a bound value by name.
|
//! The simplest selector is just a reference to a bound value by name.
|
||||||
//!
|
//!
|
||||||
|
@ -273,7 +273,7 @@ named!(boolean_value<TokenIter, Value, error::Error>,
|
|||||||
named!(
|
named!(
|
||||||
field_value<TokenIter, (Token, Expression), error::Error>,
|
field_value<TokenIter, (Token, Expression), error::Error>,
|
||||||
do_parse!(
|
do_parse!(
|
||||||
field: match_type!(BAREWORD) >>
|
field: alt!(match_type!(BAREWORD) | match_type!(STR)) >>
|
||||||
punct!("=") >>
|
punct!("=") >>
|
||||||
value: expression >>
|
value: expression >>
|
||||||
(field, value)
|
(field, value)
|
||||||
@ -442,7 +442,7 @@ fn selector_list(input: TokenIter) -> NomResult<SelectorList> {
|
|||||||
let (rest, list) = match separated_list!(
|
let (rest, list) = match separated_list!(
|
||||||
rest,
|
rest,
|
||||||
punct!("."),
|
punct!("."),
|
||||||
alt!(match_type!(BAREWORD) | match_type!(DIGIT))
|
alt!(match_type!(BAREWORD) | match_type!(DIGIT) | match_type!(STR))
|
||||||
) {
|
) {
|
||||||
IResult::Done(rest, val) => (rest, val),
|
IResult::Done(rest, val) => (rest, val),
|
||||||
IResult::Incomplete(i) => {
|
IResult::Incomplete(i) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user