Repair errors exposed by parse tests in rust
This commit is contained in:
parent
755a8bc73b
commit
e8c0a2565e
|
@ -313,6 +313,18 @@ impl<'de, 'src, N: NestedValue, Dec: DomainParse<N::Embedded>, S: BinarySource<'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn read_set(&mut self, read_annotations: bool) -> io::Result<N> {
|
||||||
|
let items = self.upto(b'}', read_annotations)?;
|
||||||
|
let mut s = Set::<N>::new();
|
||||||
|
for i in items {
|
||||||
|
if s.contains(&i) {
|
||||||
|
return Err(io_syntax_error("Duplicate set element"));
|
||||||
|
}
|
||||||
|
s.insert(i);
|
||||||
|
}
|
||||||
|
Ok(N::new(s))
|
||||||
|
}
|
||||||
|
|
||||||
fn read_dictionary(&mut self, read_annotations: bool) -> io::Result<N> {
|
fn read_dictionary(&mut self, read_annotations: bool) -> io::Result<N> {
|
||||||
let mut d = Map::new();
|
let mut d = Map::new();
|
||||||
loop {
|
loop {
|
||||||
|
@ -326,6 +338,9 @@ impl<'de, 'src, N: NestedValue, Dec: DomainParse<N::Embedded>, S: BinarySource<'
|
||||||
if self.next_byte()? != b':' {
|
if self.next_byte()? != b':' {
|
||||||
return Err(io_syntax_error("Missing expected key/value separator"));
|
return Err(io_syntax_error("Missing expected key/value separator"));
|
||||||
}
|
}
|
||||||
|
if d.contains_key(&k) {
|
||||||
|
return Err(io_syntax_error("Duplicate key"));
|
||||||
|
}
|
||||||
let v = Reader::<N>::demand_next(self, read_annotations)?;
|
let v = Reader::<N>::demand_next(self, read_annotations)?;
|
||||||
d.insert(k, v);
|
d.insert(k, v);
|
||||||
}
|
}
|
||||||
|
@ -392,13 +407,12 @@ impl<'de, 'src, N: NestedValue, Dec: DomainParse<N::Embedded>, S: BinarySource<'
|
||||||
for TextReader<'de, 'src, N, Dec, S>
|
for TextReader<'de, 'src, N, Dec, S>
|
||||||
{
|
{
|
||||||
fn next(&mut self, read_annotations: bool) -> io::Result<Option<N>> {
|
fn next(&mut self, read_annotations: bool) -> io::Result<Option<N>> {
|
||||||
self.skip_whitespace();
|
match self.peek() {
|
||||||
let c = match self.peek() {
|
|
||||||
Ok(c) => c,
|
|
||||||
Err(e) if is_eof_io_error(&e) => return Ok(None),
|
Err(e) if is_eof_io_error(&e) => return Ok(None),
|
||||||
Err(e) => return Err(e.into()),
|
_ => (),
|
||||||
};
|
}
|
||||||
Ok(Some(match c {
|
self.skip_whitespace();
|
||||||
|
Ok(Some(match self.peek()? {
|
||||||
b'"' => {
|
b'"' => {
|
||||||
self.skip()?;
|
self.skip()?;
|
||||||
N::new(self.read_string(b'"')?)
|
N::new(self.read_string(b'"')?)
|
||||||
|
@ -429,9 +443,7 @@ impl<'de, 'src, N: NestedValue, Dec: DomainParse<N::Embedded>, S: BinarySource<'
|
||||||
match self.next_byte()? {
|
match self.next_byte()? {
|
||||||
b'f' => N::new(false),
|
b'f' => N::new(false),
|
||||||
b't' => N::new(true),
|
b't' => N::new(true),
|
||||||
b'{' => N::new(Set::from_iter(
|
b'{' => self.read_set(read_annotations)?,
|
||||||
self.upto(b'}', read_annotations)?.into_iter(),
|
|
||||||
)),
|
|
||||||
b'"' => self.read_literal_binary()?,
|
b'"' => self.read_literal_binary()?,
|
||||||
b'x' => match self.next_byte()? {
|
b'x' => match self.next_byte()? {
|
||||||
b'"' => N::new(&self.read_hex_binary()?[..]),
|
b'"' => N::new(&self.read_hex_binary()?[..]),
|
||||||
|
|
Loading…
Reference in New Issue