on master help sign in
Create an `isOp` function for strings.
commit1ffaad1f5c59437f469d1f854cf80fa67faca39d authorEvan Czaplicki <info@elm-lang.org> dateTue 16 Jul 2013, 21:37 (13 years ago) parent91be5a0
3 files changed+12−7
compiler/Parse/Helpers.hs+2−2 compiler/SourceSyntax/Expression.hs+4−1 compiler/SourceSyntax/Helpers.hs+6−4
compiler/Parse/Helpers.hs+2−2
@@ -4,7 +4,7 @@ import Control.Applicative ((<$>),(<*>))
44import Control.Monad
55import Control.Monad.State
66import Data.Char (isUpper)
7−import SourceSyntax.Helpers (isOp)
7+import SourceSyntax.Helpers as Help
88import SourceSyntax.Location as Location
99import SourceSyntax.Expression
1010import SourceSyntax.Rename (deprime)
@@ -59,7 +59,7 @@ anyOp :: IParser String
5959anyOp = betwixt '`' '`' var <|> symOp <?> "infix operator (e.g. +, *, ||)"
6060
6161symOp :: IParser String
62−symOp = do op <- many1 (satisfy isOp)
62+symOp = do op <- many1 (satisfy Help.isSymbol)
6363 guard (op `notElem` [ "=", "..", "->", "--", "|", "\8594", ":" ])
6464 case op of
6565 "." -> notFollowedBy lower >> return op
compiler/SourceSyntax/Expression.hs+4−1
@@ -43,11 +43,14 @@ tuple es = Data ("_Tuple" ++ show (length es)) es
4343delist (Location.L _ _ (Data "::" [h,t])) = h : delist t
4444delist _ = []
4545
46+dummyLet defs =
47+ Location.none $ Let defs (Location.none . Literal $ Literal.IntNum 42)
48+
4649instance Pretty (Expr t v) where
4750 pretty expr =
4851 case expr of
4952 Literal lit -> pretty lit
50− Var x@(c:_) -> parensIf (Help.isOp c) (P.text x)
53+ Var x -> parensIf (Help.isOp x) (P.text x)
5154 Range e1 e2 -> P.brackets (pretty e1 <> P.text ".." <> pretty e2)
5255 ExplicitList es -> P.brackets (commaCat (map pretty es))
5356 Binop op e1 e2 -> P.sep [ prettyParens e1 <+> P.text op, prettyParens e2 ]
compiler/SourceSyntax/Helpers.hs+6−4
@@ -1,12 +1,14 @@
11
22module SourceSyntax.Helpers where
33
4−import Data.Char (isSymbol,isDigit)
4+import qualified Data.Char as Char
55
66brkt s = "{ " ++ s ++ " }"
77
88isTuple name =
9− take 6 name == "_Tuple" && all isDigit (drop 6 name)
9+ take 6 name == "_Tuple" && all Char.isDigit (drop 6 name)
1010
11−isOp c =
12− isSymbol c || elem c "+-/*=.$<>:&|^?%#@~!"
11+isOp = all isSymbol
12+
13+isSymbol c =
14+ Char.isSymbol c || elem c "+-/*=.$<>:&|^?%#@~!"