fix NCName and AttValue parsers
This commit is contained in:
parent
622634b3a5
commit
593cad573b
|
@ -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)
|
||||
}),
|
||||
|
|
Loading…
Reference in New Issue