Starting the rust-based parser of dust templates
This commit is contained in:
parent
d3b58c9a0e
commit
9b3084856b
@ -1,6 +1,7 @@
|
|||||||
//! This module contains a rust implementation of LinkedIn Dust
|
//! This module contains a rust implementation of LinkedIn Dust
|
||||||
|
|
||||||
mod node_invoker;
|
mod node_invoker;
|
||||||
|
mod parser;
|
||||||
|
|
||||||
pub use node_invoker::run_node_dust;
|
pub use node_invoker::run_node_dust;
|
||||||
pub use node_invoker::NodeError;
|
pub use node_invoker::NodeError;
|
||||||
|
54
src/duster/parser.rs
Normal file
54
src/duster/parser.rs
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
use nom::branch::alt;
|
||||||
|
use nom::bytes::complete::tag;
|
||||||
|
use nom::bytes::complete::take_until;
|
||||||
|
use nom::combinator::map;
|
||||||
|
use nom::combinator::value;
|
||||||
|
use nom::sequence::delimited;
|
||||||
|
use nom::IResult;
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
enum DustTag<'a> {
|
||||||
|
DTSpecial(Special),
|
||||||
|
DTComment(Comment<'a>),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
enum Special {
|
||||||
|
Space,
|
||||||
|
NewLine,
|
||||||
|
CarriageReturn,
|
||||||
|
LeftCurlyBrace,
|
||||||
|
RightCurlyBrace,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
struct Comment<'a> {
|
||||||
|
value: &'a str,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn dust_tag(i: &str) -> IResult<&str, DustTag> {
|
||||||
|
alt((
|
||||||
|
map(special, DustTag::DTSpecial),
|
||||||
|
map(comment, DustTag::DTComment),
|
||||||
|
))(i)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn special(i: &str) -> IResult<&str, Special> {
|
||||||
|
delimited(
|
||||||
|
tag("{~"),
|
||||||
|
alt((
|
||||||
|
value(Special::Space, tag("s")),
|
||||||
|
value(Special::NewLine, tag("s")),
|
||||||
|
value(Special::CarriageReturn, tag("s")),
|
||||||
|
value(Special::LeftCurlyBrace, tag("s")),
|
||||||
|
value(Special::RightCurlyBrace, tag("s")),
|
||||||
|
)),
|
||||||
|
tag("}"),
|
||||||
|
)(i)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn comment(i: &str) -> IResult<&str, Comment> {
|
||||||
|
map(delimited(tag("{!"), take_until("!}"), tag("!}")), |body| {
|
||||||
|
Comment { value: body }
|
||||||
|
})(i)
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user