@@ -590,21 +590,56 @@ impl<'a> FunParser<'a> {
590590 // App, Tup, Num Op
591591 if self . starts_with ( "(" ) {
592592 self . advance_one ( ) ;
593-
594- // Opr but maybe a tup
595593 self . skip_trivia ( ) ;
594+
595+ // Opr but maybe something else
596+ // ( +/-n , -> Tup with Int/Float
597+ // ( +/-n ) -> Int/Float
598+ // ( +/-n term -> App with Int/Float
599+ // ( * , -> Tup with Era
600+ // ( * ) -> Era
601+ // ( opr -> Num Op
596602 if let Some ( opr) = self . try_parse_oper ( ) {
603+ if ( opr == Op :: ADD || opr == Op :: SUB ) && self . peek_one ( ) . map_or ( false , |c| "0123456789" . contains ( c) )
604+ {
605+ unexpected_tag ( self ) ?;
606+ * self . index ( ) -= 1 ;
607+ let num = self . parse_number ( ) ?;
608+ let head = Term :: Num { val : num } ;
609+ self . skip_trivia ( ) ;
610+
611+ if self . starts_with ( "," ) {
612+ self . consume_exactly ( "," ) ?;
613+ let tail = self . list_like ( |p| p. parse_term ( ) , "" , ")" , "," , true , 1 ) ?;
614+ let els = [ head] . into_iter ( ) . chain ( tail) . collect ( ) ;
615+ return Ok ( Term :: Fan { fan : FanKind :: Tup , tag : tag. unwrap_or ( Tag :: Static ) , els } ) ;
616+ }
617+
618+ if self . starts_with ( ")" ) {
619+ self . consume_exactly ( ")" ) ?;
620+ return Ok ( head) ;
621+ }
622+
623+ let els = self . list_like ( |p| p. parse_term ( ) , "" , ")" , "" , false , 0 ) ?;
624+ let term = els. into_iter ( ) . fold ( head, |fun, arg| Term :: App {
625+ tag : tag. clone ( ) . unwrap_or ( Tag :: Static ) ,
626+ fun : Box :: new ( fun) ,
627+ arg : Box :: new ( arg) ,
628+ } ) ;
629+ return Ok ( term) ;
630+ }
631+
597632 self . skip_trivia ( ) ;
598633
599- // jk, actually a tuple
600- if self . starts_with ( "," ) && opr == Op :: MUL {
634+ if opr == Op :: MUL && self . starts_with ( "," ) {
601635 self . consume_exactly ( "," ) ?;
602636 let tail = self . list_like ( |p| p. parse_term ( ) , "" , ")" , "," , true , 1 ) ?;
603637 let els = [ Term :: Era ] . into_iter ( ) . chain ( tail) . collect ( ) ;
604638 return Ok ( Term :: Fan { fan : FanKind :: Tup , tag : tag. unwrap_or ( Tag :: Static ) , els } ) ;
605639 }
606640
607- if opr == Op :: MUL && self . try_consume ( ")" ) {
641+ if opr == Op :: MUL && self . starts_with ( ")" ) {
642+ self . consume_exactly ( ")" ) ?;
608643 return Ok ( Term :: Era ) ;
609644 }
610645
0 commit comments