@@ -1166,7 +1166,7 @@ impl Stack {
11661166 /// at the top.
11671167 pub fn get < ' l > ( & ' l self , idx : uint ) -> StackElement < ' l > {
11681168 match self . stack [ idx] {
1169- InternalIndex ( i) => { Index ( i) }
1169+ InternalIndex ( i) => Index ( i) ,
11701170 InternalKey ( start, size) => {
11711171 Key ( str:: from_utf8 (
11721172 self . str_buffer [ start as uint .. start as uint + size as uint ] ) . unwrap ( ) )
@@ -1643,69 +1643,65 @@ impl<T: Iterator<char>> Parser<T> {
16431643 fn parse_start ( & mut self ) -> JsonEvent {
16441644 let val = self . parse_value ( ) ;
16451645 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 ,
16501650 } ;
16511651 return val;
16521652 }
16531653
16541654 fn parse_array ( & mut self , first : bool ) -> JsonEvent {
16551655 if self . ch_is ( ']' ) {
16561656 if !first {
1657- return self . error_event ( InvalidSyntax ) ;
1658- }
1659- if self . stack . is_empty ( ) {
1660- self . state = ParseBeforeFinish ;
1657+ self . error_event ( InvalidSyntax )
16611658 } 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 ( ) {
16631662 ParseArrayComma
16641663 } else {
16651664 ParseObjectComma
1666- }
1665+ } ;
1666+ self . bump ( ) ;
1667+ ArrayEnd
16671668 }
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
16731681 }
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;
16841682 }
16851683
16861684 fn parse_array_comma_or_end ( & mut self ) -> Option < JsonEvent > {
16871685 if self . ch_is ( ',' ) {
16881686 self . stack . bump_index ( ) ;
16891687 self . state = ParseArray ( false ) ;
16901688 self . bump ( ) ;
1691- return None ;
1689+ None
16921690 } else if self . ch_is ( ']' ) {
16931691 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
16961696 } else {
1697- self . state = if self . stack . last_is_index ( ) {
1698- ParseArrayComma
1699- } else {
1700- ParseObjectComma
1701- }
1702- }
1697+ ParseObjectComma
1698+ } ;
17031699 self . bump ( ) ;
1704- return Some ( ArrayEnd ) ;
1700+ Some ( ArrayEnd )
17051701 } else if self . eof ( ) {
1706- return Some ( self . error_event ( EOFWhileParsingArray ) ) ;
1702+ Some ( self . error_event ( EOFWhileParsingArray ) )
17071703 } else {
1708- return Some ( self . error_event ( InvalidSyntax ) ) ;
1704+ Some ( self . error_event ( InvalidSyntax ) )
17091705 }
17101706 }
17111707
@@ -1718,15 +1714,13 @@ impl<T: Iterator<char>> Parser<T> {
17181714 self . stack . pop ( ) ;
17191715 }
17201716 }
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
17231721 } else {
1724- self . state = if self . stack . last_is_index ( ) {
1725- ParseArrayComma
1726- } else {
1727- ParseObjectComma
1728- }
1729- }
1722+ ParseObjectComma
1723+ } ;
17301724 self . bump ( ) ;
17311725 return ObjectEnd ;
17321726 }
@@ -1737,7 +1731,7 @@ impl<T: Iterator<char>> Parser<T> {
17371731 return self . error_event ( KeyMustBeAString ) ;
17381732 }
17391733 let s = match self . parse_str ( ) {
1740- Ok ( s) => { s }
1734+ Ok ( s) => s ,
17411735 Err ( e) => {
17421736 self . state = ParseFinished ;
17431737 return Error ( e) ;
@@ -1756,25 +1750,23 @@ impl<T: Iterator<char>> Parser<T> {
17561750 let val = self . parse_value ( ) ;
17571751
17581752 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 ,
17631757 } ;
17641758 return val;
17651759 }
17661760
17671761 fn parse_object_end ( & mut self ) -> JsonEvent {
17681762 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
17711767 } else {
1772- self . state = if self . stack . last_is_index ( ) {
1773- ParseArrayComma
1774- } else {
1775- ParseObjectComma
1776- }
1777- }
1768+ ParseObjectComma
1769+ } ;
17781770 self . bump ( ) ;
17791771 ObjectEnd
17801772 } else if self . eof ( ) {
@@ -1852,23 +1844,23 @@ impl<T: Iterator<char>> Builder<T> {
18521844 }
18531845
18541846 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) ) ,
18611853 Some ( StringValue ( ref mut s) ) => {
18621854 let mut temp = string:: String :: new ( ) ;
18631855 swap ( s, & mut temp) ;
18641856 Ok ( String ( temp) )
18651857 }
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 ) ,
18721864 }
18731865 }
18741866
0 commit comments