-- ==========================================================--
--
pgAlts :: [Parser a] -> Parser a

pgAlts ps env toks
   = let
        useAlts [] bestErrTok 
           = PFail bestErrTok
        useAlts (p:ps) bestErrTok
           = case p env toks of
                PFail someErrTok -> useAlts ps (further someErrTok bestErrTok)
                successful_parse -> successful_parse
        further x1@(l1, n1, w1, t1) x2@(l2, n2, w2, t2)
           =      if l2 > l1 then x2
             else if l1 > l2 then x1
             else if n1 > n2 then x1
             else x2
     in
        useAlts ps (head (toks ++ [pgEOF]))
pgAlts :: [Parser a] -> Parser a
pgAlts ps env toks
   = let
        useAlts [] bestErrTok 
           = PFail bestErrTok
        useAlts (p:ps) bestErrTok
           = case p env toks of
                PFail someErrTok -> useAlts ps (further someErrTok bestErrTok)
                successful_parse -> successful_parse
        further x1@(l1, n1, w1, t1) x2@(l2, n2, w2, t2)
           =      if l2 > l1 then x2
             else if l1 > l2 then x1
             else if n1 > n2 then x1
             else x2
     in
        useAlts ps (head (toks ++ [pgEOF]))
pgAlts ps env toks
   = let
        useAlts [] bestErrTok 
           = PFail bestErrTok
        useAlts (p:ps) bestErrTok
           = case p env toks of
                PFail someErrTok -> useAlts ps (further someErrTok bestErrTok)
                successful_parse -> successful_parse
        further x1@(l1, n1, w1, t1) x2@(l2, n2, w2, t2)
           =      if l2 > l1 then x2
             else if l1 > l2 then x1
             else if n1 > n2 then x1
             else x2
     in
        useAlts ps (head (toks ++ [pgEOF]))