@@ -57,47 +57,45 @@ fn build_exprs(tokens: &[CirruLexItem]) -> Result<Vec<Cirru>, String> {
5757  loop  { 
5858    let  chunk = pull_token ( ) ; 
5959
60-     if  chunk. is_none ( )  { 
61-       return  Ok ( acc) ; 
62-     } 
63-     match  chunk. unwrap ( )  { 
64-       CirruLexItem :: Open  => { 
65-         let  mut  pointer:  Vec < Cirru >  = vec ! [ ] ; 
66-         // guess a nested level of 16 
67-         let  mut  pointer_stack:  Vec < Vec < Cirru > >  = Vec :: with_capacity ( 16 ) ; 
68-         loop  { 
69-           let  cursor = pull_token ( ) ; 
70-           if  cursor. is_none ( )  { 
71-             return  Err ( String :: from ( "unexpected end of file" ) ) ; 
72-           } 
73-           match  cursor. unwrap ( )  { 
74-             CirruLexItem :: Close  => { 
75-               if  pointer_stack. is_empty ( )  { 
76-                 acc. push ( Cirru :: List ( pointer. to_owned ( ) ) ) ; 
77-                 break ; 
78-               }  else  { 
79-                 let  v = pointer_stack. pop ( ) ; 
80-                 let  prev_p = pointer; 
81-                 match  v { 
82-                   Some ( collected)  => { 
83-                     pointer = collected; 
84-                     pointer. push ( Cirru :: List ( prev_p) ) 
60+     match  & chunk { 
61+       None  => return  Ok ( acc) , 
62+       Some ( ck)  => { 
63+         match  ck { 
64+           CirruLexItem :: Open  => { 
65+             let  mut  pointer:  Vec < Cirru >  = vec ! [ ] ; 
66+             // guess a nested level of 16 
67+             let  mut  pointer_stack:  Vec < Vec < Cirru > >  = Vec :: with_capacity ( 16 ) ; 
68+             loop  { 
69+               let  cursor = pull_token ( ) ; 
70+ 
71+               match  & cursor { 
72+                 None  => return  Err ( String :: from ( "unexpected end of file" ) ) , 
73+                 Some ( c)  => match  c { 
74+                   CirruLexItem :: Close  => match  pointer_stack. pop ( )  { 
75+                     None  => { 
76+                       acc. push ( Cirru :: List ( pointer) ) ; 
77+                       break ; 
78+                     } 
79+                     Some ( v)  => { 
80+                       let  prev_p = pointer; 
81+                       pointer = v; 
82+                       pointer. push ( Cirru :: List ( prev_p) ) ; 
83+                     } 
84+                   } , 
85+                   CirruLexItem :: Open  => { 
86+                     pointer_stack. push ( pointer) ; 
87+                     pointer = vec ! [ ] ; 
8588                  } 
86-                   None  => return  Err ( String :: from ( "unknown close item" ) ) , 
87-                 } 
89+                   CirruLexItem :: Str ( s)  => pointer. push ( Cirru :: Leaf ( ( * * s) . into ( ) ) ) , 
90+                   CirruLexItem :: Indent ( n)  => return  Err ( format ! ( "unknown indent: {}" ,  n) ) , 
91+                 } , 
8892              } 
8993            } 
90-             CirruLexItem :: Open  => { 
91-               pointer_stack. push ( pointer) ; 
92-               pointer = vec ! [ ] ; 
93-             } 
94-             CirruLexItem :: Str ( s)  => pointer. push ( Cirru :: Leaf ( s. as_str ( ) . into ( ) ) ) , 
95-             CirruLexItem :: Indent ( n)  => return  Err ( format ! ( "unknown indent: {}" ,  n) ) , 
9694          } 
95+           CirruLexItem :: Close  => return  Err ( String :: from ( "unexpected \" )\" " ) ) , 
96+           a => return  Err ( format ! ( "unknown item: {:?}" ,  a) ) , 
9797        } 
9898      } 
99-       CirruLexItem :: Close  => return  Err ( String :: from ( "unexpected \" )\" " ) ) , 
100-       a => return  Err ( format ! ( "unknown item: {:?}" ,  a) ) , 
10199    } 
102100  } 
103101} 
@@ -151,28 +149,28 @@ pub fn lex(initial_code: &str) -> Result<CirruLexItemList, String> {
151149      } , 
152150      CirruLexState :: Token  => match  c { 
153151        ' '  => { 
154-           acc. push ( CirruLexItem :: Str ( buffer) ) ; 
152+           acc. push ( CirruLexItem :: Str ( buffer. into ( ) ) ) ; 
155153          state = CirruLexState :: Space ; 
156154          buffer = String :: from ( "" ) ; 
157155        } 
158156        '"'  => { 
159-           acc. push ( CirruLexItem :: Str ( buffer) ) ; 
157+           acc. push ( CirruLexItem :: Str ( buffer. into ( ) ) ) ; 
160158          state = CirruLexState :: Str ; 
161159          buffer = String :: from ( "" ) ; 
162160        } 
163161        '\n'  => { 
164-           acc. push ( CirruLexItem :: Str ( buffer) ) ; 
162+           acc. push ( CirruLexItem :: Str ( buffer. into ( ) ) ) ; 
165163          state = CirruLexState :: Indent ; 
166164          buffer = String :: from ( "" ) ; 
167165        } 
168166        '('  => { 
169-           acc. push ( CirruLexItem :: Str ( buffer) ) ; 
167+           acc. push ( CirruLexItem :: Str ( buffer. into ( ) ) ) ; 
170168          acc. push ( CirruLexItem :: Open ) ; 
171169          state = CirruLexState :: Space ; 
172170          buffer = String :: from ( "" ) 
173171        } 
174172        ')'  => { 
175-           acc. push ( CirruLexItem :: Str ( buffer) ) ; 
173+           acc. push ( CirruLexItem :: Str ( buffer. into ( ) ) ) ; 
176174          acc. push ( CirruLexItem :: Close ) ; 
177175          state = CirruLexState :: Space ; 
178176          buffer = String :: from ( "" ) 
@@ -184,7 +182,7 @@ pub fn lex(initial_code: &str) -> Result<CirruLexItemList, String> {
184182      } , 
185183      CirruLexState :: Str  => match  c { 
186184        '"'  => { 
187-           acc. push ( CirruLexItem :: Str ( buffer) ) ; 
185+           acc. push ( CirruLexItem :: Str ( buffer. into ( ) ) ) ; 
188186          state = CirruLexState :: Space ; 
189187          buffer = String :: from ( "" ) ; 
190188        } 
@@ -270,7 +268,7 @@ pub fn lex(initial_code: &str) -> Result<CirruLexItemList, String> {
270268  match  state { 
271269    CirruLexState :: Space  => Ok ( acc) , 
272270    CirruLexState :: Token  => { 
273-       acc. push ( CirruLexItem :: Str ( buffer) ) ; 
271+       acc. push ( CirruLexItem :: Str ( buffer. into ( ) ) ) ; 
274272      Ok ( acc) 
275273    } 
276274    CirruLexState :: Escape  => Err ( String :: from ( "unknown escape" ) ) , 
0 commit comments