From feb13be926cbfb5204fa651d7c86809e20954f9d Mon Sep 17 00:00:00 2001 From: cel 🌸 Date: Sat, 22 Jun 2024 13:41:34 +0100 Subject: WIP: element parsing --- src/parser.rs | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/src/parser.rs b/src/parser.rs index 2acd579..d049c5c 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -25,11 +25,6 @@ enum ContentItem<'s> { type Content<'s> = Option>>; -struct Attribute<'s> { - key: &'s str, - value: &'s str, -} - struct DoctypeDecl<'s> { name: &'s str, // TODO: doctype declaration parsing @@ -39,16 +34,6 @@ pub fn doctypedecl(input: &str) -> IResult<&str, DoctypeDecl> { todo!() } -struct Element<'s> { - name: &'s str, - attributes: Vec>, - content: Content<'s>, -} -/// Element -pub fn element(input: &str) -> IResult<&str, Element> { - todo!() -} - type Document<'s> = (Prolog<'s>, Element<'s>, Vec>); /// [1] document ::= prolog element Misc* pub fn document(input: &str) -> IResult<&str, Document> { @@ -388,6 +373,27 @@ pub fn sd_decl(input: &str) -> IResult<&str, SDDecl> { )(input) } +// (Productions 33 through 38 have been removed.) + +struct Element<'s> { + name: &'s str, + attributes: Vec>, + content: Content<'s>, +} +/// [39] element ::= EmptyElemTag | STag content ETag +pub fn element(input: &str) -> IResult<&str, Element> { + alt(( + empty_elem_tag, + map(tuple((s_tag, content, e_tag)), |(start, content, end)| {}), + ))(input) +} + +let +/// [40] STag ::= '<' Name (S Attribute)* S? '>' + +type Attribute<'s> = (&'s str, &'s str) +/// [41] Attribute ::= Name Eq AttValue + pub fn reference(input: &str) -> IResult<&str, char> { todo!() } -- cgit