diff --git a/src/duster/mod.rs b/src/duster/mod.rs index fcd5e9b..3840047 100644 --- a/src/duster/mod.rs +++ b/src/duster/mod.rs @@ -1,6 +1,7 @@ //! This module contains a rust implementation of LinkedIn Dust mod node_invoker; +mod parser; pub use node_invoker::run_node_dust; pub use node_invoker::NodeError; diff --git a/src/duster/parser.rs b/src/duster/parser.rs new file mode 100644 index 0000000..42f51ec --- /dev/null +++ b/src/duster/parser.rs @@ -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) +}