Add a basic reference implementation missing filter support

This commit is contained in:
Tom Alexander 2020-04-04 20:37:35 -04:00
parent 9b3084856b
commit 5127534609
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE

View File

@ -1,15 +1,20 @@
use nom::branch::alt; use nom::branch::alt;
use nom::bytes::complete::is_a;
use nom::bytes::complete::tag; use nom::bytes::complete::tag;
use nom::bytes::complete::take_until; use nom::bytes::complete::take_until;
use nom::combinator::map; use nom::combinator::map;
use nom::combinator::recognize;
use nom::combinator::value; use nom::combinator::value;
use nom::multi::separated_list;
use nom::sequence::delimited; use nom::sequence::delimited;
use nom::sequence::tuple;
use nom::IResult; use nom::IResult;
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
enum DustTag<'a> { enum DustTag<'a> {
DTSpecial(Special), DTSpecial(Special),
DTComment(Comment<'a>), DTComment(Comment<'a>),
DTReference(Reference<'a>),
} }
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
@ -26,10 +31,21 @@ struct Comment<'a> {
value: &'a str, value: &'a str,
} }
#[derive(Clone, Debug)]
struct Path<'a> {
keys: Vec<&'a str>,
}
#[derive(Clone, Debug)]
struct Reference<'a> {
path: Path<'a>,
}
fn dust_tag(i: &str) -> IResult<&str, DustTag> { fn dust_tag(i: &str) -> IResult<&str, DustTag> {
alt(( alt((
map(special, DustTag::DTSpecial), map(special, DustTag::DTSpecial),
map(comment, DustTag::DTComment), map(comment, DustTag::DTComment),
map(reference, DustTag::DTReference),
))(i) ))(i)
} }
@ -52,3 +68,22 @@ fn comment(i: &str) -> IResult<&str, Comment> {
Comment { value: body } Comment { value: body }
})(i) })(i)
} }
fn path(i: &str) -> IResult<&str, Path> {
map(
separated_list(
tag("."),
recognize(tuple((
is_a("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_$"),
is_a("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_$0123456789-"),
))),
),
|body| Path { keys: body },
)(i)
}
fn reference(i: &str) -> IResult<&str, Reference> {
// TODO: Add support for filters
let (remaining, p) = delimited(tag("{"), path, tag("}"))(i)?;
Ok((remaining, Reference { path: p }))
}