@@ -1,84 +0,0 @@
1−module Parse.Binop (binops, infixOp) where
4− ( (<|>), choice, lookAhead, lower, many1
5− , notFollowedBy, satisfy, string, try
8−import qualified AST.Expression.Source as Src
9−import qualified AST.Helpers as Help
10−import Parse.Helpers (IParser, addLocation, commitIf, expecting, failure, whitespace)
11−import qualified Reporting.Annotation as A
18−binops :: IParser Src.RawExpr -> IParser Src.RawExpr -> IParser Src.RawExpr
19−binops parseTerm parseLastTerm =
22− (ops, last) <- binopsHelp parseTerm parseLastTerm expr
28− return (Src.Binop ops last)
32− :: IParser Src.RawExpr
33− -> IParser Src.RawExpr
35− -> IParser ([(Src.RawExpr, A.Located String)], Src.RawExpr)
36−binopsHelp parseTerm parseLastTerm expr =
38− [ commitIf (whitespace >> infixOpWith (fail "")) $
40− op <- addLocation infixOp
43− [ do (ops, last) <- binopsHelp parseTerm parseLastTerm =<< try parseTerm
44− return ( (expr, op) : ops, last )
45− , (,) [(expr, op)] <$> parseLastTerm
47− , return ( [], expr )
55−infixOp :: IParser String
57− infixOpWith notReserved
60−infixOpWith :: IParser String -> IParser String
62− expecting "an infix operator like (+)" $
63− do op <- checker <|> many1 (satisfy Help.isSymbol)
65− "." -> notFollowedBy lower >> return op
69−notReserved :: IParser a
72− [ failOn "=" "The = operator is reserved for defining variables. Maybe you want == instead? Or maybe you are defining a variable, but there is whitespace before it?"
73− , failOn "->" "Arrows are reserved for cases and anonymous functions. Maybe you want > or >= instead?"
74− , failOn "|" "Vertical bars are reserved for use in union type declarations. Maybe you want || instead?"
75− , failOn ":" "A single colon is for type annotations. Maybe you want :: instead? Or maybe you are defining a type annotation, but there is whitespace before it?"
79−failOn :: String -> String -> IParser a
81− do try $ lookAhead $ do
83− notFollowedBy (satisfy Help.isSymbol)