aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar cel 🌸 <cel@blos.sm>2024-06-21 16:05:31 +0100
committerLibravatar cel 🌸 <cel@blos.sm>2024-06-21 16:05:31 +0100
commit0a353135c04d1639cad7b0b881dd7b464a1989e1 (patch)
tree8819c076121336fa2201a7d0f62e18ff1a412746
parent9307f48d174c7657ac01444694e1cd96139bd800 (diff)
downloadpeanuts-0a353135c04d1639cad7b0b881dd7b464a1989e1.tar.gz
peanuts-0a353135c04d1639cad7b0b881dd7b464a1989e1.tar.bz2
peanuts-0a353135c04d1639cad7b0b881dd7b464a1989e1.zip
WIP: CDSect parsers
Diffstat (limited to '')
-rw-r--r--src/parser.rs58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/parser.rs b/src/parser.rs
index bec5313..f882064 100644
--- a/src/parser.rs
+++ b/src/parser.rs
@@ -269,6 +269,30 @@ pub fn pi_target(input: &str) -> IResult<&str, PITarget> {
}
}
+type CDSect<'s> = (CDStart<'s>, CData<'s>, CDEnd<'s>);
+/// [18] CDSect ::= CDStart CData CDEnd
+pub fn cd_sect(input: &str) -> IResult<&str, CDSect> {
+ tuple((cd_start, cdata, cd_end))(input)
+}
+
+type CDStart<'s> = &'s str;
+/// [19] CDStart ::= '<![CDATA['
+pub fn cd_start(input: &str) -> IResult<&str, CDStart> {
+ tag("<![CDATA[")(input)
+}
+
+type CData<'s> = &'s str;
+/// [20] CData ::= (Char* - (Char* ']]>' Char*))
+pub fn cdata(input: &str) -> IResult<&str, CData> {
+ recognize(many_till(xmlchar, peek(tag("]]>"))))(input)
+}
+
+type CDEnd<'s> = &'s str;
+/// [21] CDEnd ::= ']]>'
+pub fn cd_end(input: &str) -> IResult<&str, CDEnd> {
+ tag("]]>")(input)
+}
+
type Prolog<'s> = (
Option<XMLDecl>,
Vec<Misc<'s>>,
@@ -400,4 +424,38 @@ mod tests {
pi_target("xMl ")
);
}
+
+ #[test]
+ fn test_cd_sect() {
+ assert_eq!(
+ Ok((
+ "",
+ ("<![CDATA[", "<greeting>Hello, world!</greeting>", "]]>")
+ )),
+ cd_sect("<![CDATA[<greeting>Hello, world!</greeting>]]>")
+ )
+ }
+
+ #[test]
+ fn test_cd_start() {
+ assert_eq!(Ok(("asdf", "<![CDATA[")), cd_start("<![CDATA[asdf"))
+ }
+
+ #[test]
+ fn test_cdata() {
+ assert_eq!(Ok(("]]>asdf", "asdf")), cdata("asdf]]>asdf"));
+ assert_eq!(
+ Ok(("]]>asdf", "<![CDATA[asdf")),
+ cdata("<![CDATA[asdf]]>asdf")
+ );
+ assert_eq!(
+ Ok(("]]>asdf", "<greeting>Hello, world!</greeting>")),
+ cdata("<greeting>Hello, world!</greeting>]]>asdf")
+ )
+ }
+
+ #[test]
+ fn test_cd_end() {
+ assert_eq!(Ok(("asdf", "]]>")), cd_end("]]>asdf"))
+ }
}