Add support for filters
This commit is contained in:
parent
5127534609
commit
ac2ee2c756
@ -5,8 +5,10 @@ use nom::bytes::complete::take_until;
|
||||
use nom::combinator::map;
|
||||
use nom::combinator::recognize;
|
||||
use nom::combinator::value;
|
||||
use nom::multi::many0;
|
||||
use nom::multi::separated_list;
|
||||
use nom::sequence::delimited;
|
||||
use nom::sequence::preceded;
|
||||
use nom::sequence::tuple;
|
||||
use nom::IResult;
|
||||
|
||||
@ -39,6 +41,18 @@ struct Path<'a> {
|
||||
#[derive(Clone, Debug)]
|
||||
struct Reference<'a> {
|
||||
path: Path<'a>,
|
||||
filters: Vec<Filter>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
enum Filter {
|
||||
HtmlEncode,
|
||||
DisableHtmlEncode,
|
||||
JavascriptStringEncode,
|
||||
EncodeUri,
|
||||
EncodeUriComponent,
|
||||
JsonStringify,
|
||||
JsonParse,
|
||||
}
|
||||
|
||||
fn dust_tag(i: &str) -> IResult<&str, DustTag> {
|
||||
@ -83,7 +97,27 @@ fn path(i: &str) -> IResult<&str, Path> {
|
||||
}
|
||||
|
||||
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 }))
|
||||
let (remaining, (p, filters)) = delimited(tag("{"), tuple((path, many0(filter))), tag("}"))(i)?;
|
||||
Ok((
|
||||
remaining,
|
||||
Reference {
|
||||
path: p,
|
||||
filters: filters,
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
fn filter(i: &str) -> IResult<&str, Filter> {
|
||||
preceded(
|
||||
tag("|"),
|
||||
alt((
|
||||
value(Filter::JsonStringify, tag("js")),
|
||||
value(Filter::JsonParse, tag("jp")),
|
||||
value(Filter::EncodeUriComponent, tag("uc")),
|
||||
value(Filter::HtmlEncode, tag("h")),
|
||||
value(Filter::DisableHtmlEncode, tag("s")),
|
||||
value(Filter::JavascriptStringEncode, tag("j")),
|
||||
value(Filter::EncodeUri, tag("u")),
|
||||
)),
|
||||
)(i)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user