aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar cel 🌸 <cel@bunny.garden>2024-11-02 22:50:50 +0000
committerLibravatar cel 🌸 <cel@bunny.garden>2024-11-02 22:50:50 +0000
commit593cad573baf239337c5869c92ea9e7aed61e847 (patch)
treef46445862522cb08a0d152d9ae141d4443375929
parent622634b3a56c897b600893dc2e2b0a57f90471d3 (diff)
downloadpeanuts-593cad573baf239337c5869c92ea9e7aed61e847.tar.gz
peanuts-593cad573baf239337c5869c92ea9e7aed61e847.tar.bz2
peanuts-593cad573baf239337c5869c92ea9e7aed61e847.zip
fix NCName and AttValue parsers
-rw-r--r--src/xml/parsers.rs26
1 files changed, 10 insertions, 16 deletions
diff --git a/src/xml/parsers.rs b/src/xml/parsers.rs
index 8bd07a8..3f67be7 100644
--- a/src/xml/parsers.rs
+++ b/src/xml/parsers.rs
@@ -1,6 +1,6 @@
use nom::{
branch::alt,
- bytes::streaming::{is_a, tag, take, take_while},
+ bytes::streaming::{is_a, is_not, tag, take, take_while},
character::{
complete::one_of,
streaming::{char, none_of, satisfy},
@@ -61,16 +61,16 @@ impl Parser<'_, DefaultAttName> for DefaultAttName {
}
}
+/// [5] Name ::= NameStartChar (NameChar)*
/// [4] NCName ::= Name - (Char* ':' Char*)
impl<'s> Parser<'s, NCName<'s>> for NCName<'s> {
fn parse(input: &'s str) -> IResult<&str, NCName<'s>> {
- map(
- recognize(pair(
- recognize(NameStartChar::parse).and_then(satisfy(|c| c != ':')),
- many0(recognize(NameChar::parse).and_then(satisfy(|c| c != ':'))),
- )),
- |nc_name| NCName(nc_name),
- )(input)
+ let (rest, name) = peek(recognize(Name::parse))(input)?;
+ if let Some(char) = name.find(':') {
+ map(take(char), |nc_name| NCName(nc_name))(input)
+ } else {
+ map(recognize(Name::parse), |nc_name| NCName(nc_name))(input)
+ }
}
}
@@ -275,10 +275,7 @@ impl<'s> Parser<'s, AttValue<'s>> for AttValue<'s> {
delimited(
char('"'),
many0(alt((
- map(
- recognize(many_till(take(1usize), peek(one_of("%&\"")))),
- |string| AttValueData::String(string),
- ),
+ map(is_not("<&\""), |string| AttValueData::String(string)),
map(Reference::parse, |reference| {
AttValueData::Reference(reference)
}),
@@ -291,10 +288,7 @@ impl<'s> Parser<'s, AttValue<'s>> for AttValue<'s> {
delimited(
char('\''),
many0(alt((
- map(
- recognize(many_till(take(1usize), peek(one_of("%&'")))),
- |string| AttValueData::String(string),
- ),
+ map(is_not("<&'"), |string| AttValueData::String(string)),
map(Reference::parse, |reference| {
AttValueData::Reference(reference)
}),