@@ -1166,7 +1166,7 @@ impl Stack {
1166
1166
/// at the top.
1167
1167
pub fn get < ' l > ( & ' l self , idx : uint ) -> StackElement < ' l > {
1168
1168
match self . stack [ idx] {
1169
- InternalIndex ( i) => { Index ( i) }
1169
+ InternalIndex ( i) => Index ( i) ,
1170
1170
InternalKey ( start, size) => {
1171
1171
Key ( str:: from_utf8 (
1172
1172
self . str_buffer [ start as uint .. start as uint + size as uint ] ) . unwrap ( ) )
@@ -1643,69 +1643,65 @@ impl<T: Iterator<char>> Parser<T> {
1643
1643
fn parse_start ( & mut self ) -> JsonEvent {
1644
1644
let val = self . parse_value ( ) ;
1645
1645
self . state = match val {
1646
- Error ( _) => { ParseFinished }
1647
- ArrayStart => { ParseArray ( true ) }
1648
- ObjectStart => { ParseObject ( true ) }
1649
- _ => { ParseBeforeFinish }
1646
+ Error ( _) => ParseFinished ,
1647
+ ArrayStart => ParseArray ( true ) ,
1648
+ ObjectStart => ParseObject ( true ) ,
1649
+ _ => ParseBeforeFinish ,
1650
1650
} ;
1651
1651
return val;
1652
1652
}
1653
1653
1654
1654
fn parse_array ( & mut self , first : bool ) -> JsonEvent {
1655
1655
if self . ch_is ( ']' ) {
1656
1656
if !first {
1657
- return self . error_event ( InvalidSyntax ) ;
1658
- }
1659
- if self . stack . is_empty ( ) {
1660
- self . state = ParseBeforeFinish ;
1657
+ self . error_event ( InvalidSyntax )
1661
1658
} else {
1662
- self . state = if self . stack . last_is_index ( ) {
1659
+ self . state = if self . stack . is_empty ( ) {
1660
+ ParseBeforeFinish
1661
+ } else if self . stack . last_is_index ( ) {
1663
1662
ParseArrayComma
1664
1663
} else {
1665
1664
ParseObjectComma
1666
- }
1665
+ } ;
1666
+ self . bump ( ) ;
1667
+ ArrayEnd
1667
1668
}
1668
- self . bump ( ) ;
1669
- return ArrayEnd ;
1670
- }
1671
- if first {
1672
- self . stack . push_index ( 0 ) ;
1669
+ } else {
1670
+ if first {
1671
+ self . stack . push_index ( 0 ) ;
1672
+ }
1673
+ let val = self . parse_value ( ) ;
1674
+ self . state = match val {
1675
+ Error ( _) => ParseFinished ,
1676
+ ArrayStart => ParseArray ( true ) ,
1677
+ ObjectStart => ParseObject ( true ) ,
1678
+ _ => ParseArrayComma ,
1679
+ } ;
1680
+ val
1673
1681
}
1674
-
1675
- let val = self . parse_value ( ) ;
1676
-
1677
- self . state = match val {
1678
- Error ( _) => { ParseFinished }
1679
- ArrayStart => { ParseArray ( true ) }
1680
- ObjectStart => { ParseObject ( true ) }
1681
- _ => { ParseArrayComma }
1682
- } ;
1683
- return val;
1684
1682
}
1685
1683
1686
1684
fn parse_array_comma_or_end ( & mut self ) -> Option < JsonEvent > {
1687
1685
if self . ch_is ( ',' ) {
1688
1686
self . stack . bump_index ( ) ;
1689
1687
self . state = ParseArray ( false ) ;
1690
1688
self . bump ( ) ;
1691
- return None ;
1689
+ None
1692
1690
} else if self . ch_is ( ']' ) {
1693
1691
self . stack . pop ( ) ;
1694
- if self . stack . is_empty ( ) {
1695
- self . state = ParseBeforeFinish ;
1692
+ self . state = if self . stack . is_empty ( ) {
1693
+ ParseBeforeFinish
1694
+ } else if self . stack . last_is_index ( ) {
1695
+ ParseArrayComma
1696
1696
} else {
1697
- self . state = if self . stack . last_is_index ( ) {
1698
- ParseArrayComma
1699
- } else {
1700
- ParseObjectComma
1701
- }
1702
- }
1697
+ ParseObjectComma
1698
+ } ;
1703
1699
self . bump ( ) ;
1704
- return Some ( ArrayEnd ) ;
1700
+ Some ( ArrayEnd )
1705
1701
} else if self . eof ( ) {
1706
- return Some ( self . error_event ( EOFWhileParsingArray ) ) ;
1702
+ Some ( self . error_event ( EOFWhileParsingArray ) )
1707
1703
} else {
1708
- return Some ( self . error_event ( InvalidSyntax ) ) ;
1704
+ Some ( self . error_event ( InvalidSyntax ) )
1709
1705
}
1710
1706
}
1711
1707
@@ -1718,15 +1714,13 @@ impl<T: Iterator<char>> Parser<T> {
1718
1714
self . stack . pop ( ) ;
1719
1715
}
1720
1716
}
1721
- if self . stack . is_empty ( ) {
1722
- self . state = ParseBeforeFinish ;
1717
+ self . state = if self . stack . is_empty ( ) {
1718
+ ParseBeforeFinish
1719
+ } else if self . stack . last_is_index ( ) {
1720
+ ParseArrayComma
1723
1721
} else {
1724
- self . state = if self . stack . last_is_index ( ) {
1725
- ParseArrayComma
1726
- } else {
1727
- ParseObjectComma
1728
- }
1729
- }
1722
+ ParseObjectComma
1723
+ } ;
1730
1724
self . bump ( ) ;
1731
1725
return ObjectEnd ;
1732
1726
}
@@ -1737,7 +1731,7 @@ impl<T: Iterator<char>> Parser<T> {
1737
1731
return self . error_event ( KeyMustBeAString ) ;
1738
1732
}
1739
1733
let s = match self . parse_str ( ) {
1740
- Ok ( s) => { s }
1734
+ Ok ( s) => s ,
1741
1735
Err ( e) => {
1742
1736
self . state = ParseFinished ;
1743
1737
return Error ( e) ;
@@ -1756,25 +1750,23 @@ impl<T: Iterator<char>> Parser<T> {
1756
1750
let val = self . parse_value ( ) ;
1757
1751
1758
1752
self . state = match val {
1759
- Error ( _) => { ParseFinished }
1760
- ArrayStart => { ParseArray ( true ) }
1761
- ObjectStart => { ParseObject ( true ) }
1762
- _ => { ParseObjectComma }
1753
+ Error ( _) => ParseFinished ,
1754
+ ArrayStart => ParseArray ( true ) ,
1755
+ ObjectStart => ParseObject ( true ) ,
1756
+ _ => ParseObjectComma ,
1763
1757
} ;
1764
1758
return val;
1765
1759
}
1766
1760
1767
1761
fn parse_object_end ( & mut self ) -> JsonEvent {
1768
1762
if self . ch_is ( '}' ) {
1769
- if self . stack . is_empty ( ) {
1770
- self . state = ParseBeforeFinish ;
1763
+ self . state = if self . stack . is_empty ( ) {
1764
+ ParseBeforeFinish
1765
+ } else if self . stack . last_is_index ( ) {
1766
+ ParseArrayComma
1771
1767
} else {
1772
- self . state = if self . stack . last_is_index ( ) {
1773
- ParseArrayComma
1774
- } else {
1775
- ParseObjectComma
1776
- }
1777
- }
1768
+ ParseObjectComma
1769
+ } ;
1778
1770
self . bump ( ) ;
1779
1771
ObjectEnd
1780
1772
} else if self . eof ( ) {
@@ -1852,23 +1844,23 @@ impl<T: Iterator<char>> Builder<T> {
1852
1844
}
1853
1845
1854
1846
fn build_value ( & mut self ) -> Result < Json , BuilderError > {
1855
- return match self . token {
1856
- Some ( NullValue ) => { Ok ( Null ) }
1857
- Some ( I64Value ( n) ) => { Ok ( I64 ( n) ) }
1858
- Some ( U64Value ( n) ) => { Ok ( U64 ( n) ) }
1859
- Some ( F64Value ( n) ) => { Ok ( F64 ( n) ) }
1860
- Some ( BooleanValue ( b) ) => { Ok ( Boolean ( b) ) }
1847
+ match self . token {
1848
+ Some ( NullValue ) => Ok ( Null ) ,
1849
+ Some ( I64Value ( n) ) => Ok ( I64 ( n) ) ,
1850
+ Some ( U64Value ( n) ) => Ok ( U64 ( n) ) ,
1851
+ Some ( F64Value ( n) ) => Ok ( F64 ( n) ) ,
1852
+ Some ( BooleanValue ( b) ) => Ok ( Boolean ( b) ) ,
1861
1853
Some ( StringValue ( ref mut s) ) => {
1862
1854
let mut temp = string:: String :: new ( ) ;
1863
1855
swap ( s, & mut temp) ;
1864
1856
Ok ( String ( temp) )
1865
1857
}
1866
- Some ( Error ( e) ) => { Err ( e) }
1867
- Some ( ArrayStart ) => { self . build_array ( ) }
1868
- Some ( ObjectStart ) => { self . build_object ( ) }
1869
- Some ( ObjectEnd ) => { self . parser . error ( InvalidSyntax ) }
1870
- Some ( ArrayEnd ) => { self . parser . error ( InvalidSyntax ) }
1871
- None => { self . parser . error ( EOFWhileParsingValue ) }
1858
+ Some ( Error ( e) ) => Err ( e) ,
1859
+ Some ( ArrayStart ) => self . build_array ( ) ,
1860
+ Some ( ObjectStart ) => self . build_object ( ) ,
1861
+ Some ( ObjectEnd ) => self . parser . error ( InvalidSyntax ) ,
1862
+ Some ( ArrayEnd ) => self . parser . error ( InvalidSyntax ) ,
1863
+ None => self . parser . error ( EOFWhileParsingValue ) ,
1872
1864
}
1873
1865
}
1874
1866
0 commit comments