fix NCName and AttValue parsers
This commit is contained in:
parent
622634b3a5
commit
593cad573b
|
@ -1,6 +1,6 @@
|
||||||
use nom::{
|
use nom::{
|
||||||
branch::alt,
|
branch::alt,
|
||||||
bytes::streaming::{is_a, tag, take, take_while},
|
bytes::streaming::{is_a, is_not, tag, take, take_while},
|
||||||
character::{
|
character::{
|
||||||
complete::one_of,
|
complete::one_of,
|
||||||
streaming::{char, none_of, satisfy},
|
streaming::{char, none_of, satisfy},
|
||||||
|
@ -61,16 +61,16 @@ impl Parser<'_, DefaultAttName> for DefaultAttName {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// [5] Name ::= NameStartChar (NameChar)*
|
||||||
/// [4] NCName ::= Name - (Char* ':' Char*)
|
/// [4] NCName ::= Name - (Char* ':' Char*)
|
||||||
impl<'s> Parser<'s, NCName<'s>> for NCName<'s> {
|
impl<'s> Parser<'s, NCName<'s>> for NCName<'s> {
|
||||||
fn parse(input: &'s str) -> IResult<&str, NCName<'s>> {
|
fn parse(input: &'s str) -> IResult<&str, NCName<'s>> {
|
||||||
map(
|
let (rest, name) = peek(recognize(Name::parse))(input)?;
|
||||||
recognize(pair(
|
if let Some(char) = name.find(':') {
|
||||||
recognize(NameStartChar::parse).and_then(satisfy(|c| c != ':')),
|
map(take(char), |nc_name| NCName(nc_name))(input)
|
||||||
many0(recognize(NameChar::parse).and_then(satisfy(|c| c != ':'))),
|
} else {
|
||||||
)),
|
map(recognize(Name::parse), |nc_name| NCName(nc_name))(input)
|
||||||
|nc_name| NCName(nc_name),
|
}
|
||||||
)(input)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -275,10 +275,7 @@ impl<'s> Parser<'s, AttValue<'s>> for AttValue<'s> {
|
||||||
delimited(
|
delimited(
|
||||||
char('"'),
|
char('"'),
|
||||||
many0(alt((
|
many0(alt((
|
||||||
map(
|
map(is_not("<&\""), |string| AttValueData::String(string)),
|
||||||
recognize(many_till(take(1usize), peek(one_of("%&\"")))),
|
|
||||||
|string| AttValueData::String(string),
|
|
||||||
),
|
|
||||||
map(Reference::parse, |reference| {
|
map(Reference::parse, |reference| {
|
||||||
AttValueData::Reference(reference)
|
AttValueData::Reference(reference)
|
||||||
}),
|
}),
|
||||||
|
@ -291,10 +288,7 @@ impl<'s> Parser<'s, AttValue<'s>> for AttValue<'s> {
|
||||||
delimited(
|
delimited(
|
||||||
char('\''),
|
char('\''),
|
||||||
many0(alt((
|
many0(alt((
|
||||||
map(
|
map(is_not("<&'"), |string| AttValueData::String(string)),
|
||||||
recognize(many_till(take(1usize), peek(one_of("%&'")))),
|
|
||||||
|string| AttValueData::String(string),
|
|
||||||
),
|
|
||||||
map(Reference::parse, |reference| {
|
map(Reference::parse, |reference| {
|
||||||
AttValueData::Reference(reference)
|
AttValueData::Reference(reference)
|
||||||
}),
|
}),
|
||||||
|
|
Loading…
Reference in New Issue