Starting stand-alone parsers for key value pairs
This commit is contained in:
parent
ffce2b0569
commit
8641e5a98b
@ -19,6 +19,7 @@ use nom::multi::many1;
|
||||
use nom::multi::separated_list;
|
||||
use nom::sequence::delimited;
|
||||
use nom::sequence::preceded;
|
||||
use nom::sequence::separated_pair;
|
||||
use nom::sequence::tuple;
|
||||
use nom::IResult;
|
||||
|
||||
@ -166,6 +167,15 @@ fn path(i: &str) -> IResult<&str, Path> {
|
||||
map(separated_list(tag("."), key), |body| Path { keys: body })(i)
|
||||
}
|
||||
|
||||
/// Either a literal or a path to a value
|
||||
fn rvalue(i: &str) -> IResult<&str, &str> {
|
||||
key(i)
|
||||
}
|
||||
|
||||
fn key_value_pair(i: &str) -> IResult<&str, (&str, Path)> {
|
||||
separated_pair(key, tag("="), path)(i)
|
||||
}
|
||||
|
||||
/// Display a value from the context
|
||||
fn reference(i: &str) -> IResult<&str, Reference> {
|
||||
let (remaining, (p, filters)) = delimited(tag("{"), tuple((path, many0(filter))), tag("}"))(i)?;
|
||||
@ -665,10 +675,13 @@ mod tests {
|
||||
assert_eq!(
|
||||
delimited(
|
||||
tag("{>"),
|
||||
tuple((key, opt(preceded(space1, separated_list(space1, key))),)),
|
||||
tuple((
|
||||
key,
|
||||
opt(preceded(space1, separated_list(space1, key_value_pair))),
|
||||
)),
|
||||
tag("/}"),
|
||||
)("{>foo bar/}"),
|
||||
Ok(("", ("foo", Some(vec!["bar"]))))
|
||||
)("{>foo bar=baz/}"),
|
||||
Ok(("", ("foo", Some(vec![("bar", Path { keys: vec!["baz"] })]))))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user