@@ -1,5 +1,6 @@
1module Parse.Binop (binops, infixStmt, OpTable) where
1module Parse.Binop (binops, infixStmt, OpTable) where
3+import Control.Applicative ((<$>))
3import Control.Monad.Error
4import Control.Monad.Error
4import Data.List (intercalate)
5import Data.List (intercalate)
5import qualified Data.Map as Map
6import qualified Data.Map as Map
@@ -38,15 +39,22 @@ opAssoc table op = Map.findWithDefault R op dict
38hasLevel :: OpTable -> Int -> (String, LExpr t v) -> Bool
39hasLevel :: OpTable -> Int -> (String, LExpr t v) -> Bool
39hasLevel table n (op,_) = opLevel table op == n
40hasLevel table n (op,_) = opLevel table op == n
41−binops :: OpTable -> IParser (LExpr t v) -> IParser String -> IParser (LExpr t v)
43+ -> IParser (LExpr t v)
44+ -> IParser (LExpr t v)
46+ -> IParser (LExpr t v)
42−binops table term anyOp =
47+binops table term last anyOp =
43 do e <- term
48 do e <- term
44− split (table ++ preludeTable) 0 e =<< many nextOp
49+ split (table ++ preludeTable) 0 e =<< nextOps
46− nextOp = commitIf (whitespace >> anyOp) $ do
51+ nextOps = choice [ commitIf (whitespace >> anyOp) $ do
47− whitespace ; op <- anyOp
52+ whitespace ; op <- anyOp ; whitespace
48− whitespace ; e <- term
53+ expr <- Left <$> try term <|> Right <$> last
55+ Left t -> (:) (op,t) <$> nextOps
49− return (op,e)
56+ Right e -> return [(op,e)]
51split :: OpTable
59split :: OpTable