1module SourceSyntax.Pattern where
3import Data.List (intercalate)
4import SourceSyntax.Helpers as Help
5import SourceSyntax.PrettyPrint
6import Text.PrettyPrint as PP
7import SourceSyntax.Literal as Literal
9data Pattern = PData String [Pattern]
11 | PAlias String Pattern
14 | PLiteral Literal.Literal
15 deriving (Eq, Ord, Show)
17cons h t = PData "::" [h,t]
20tuple es = PData ("_Tuple" ++ show (length es)) es
23instance Pretty Pattern where
27 PLiteral lit -> pretty lit
28 PRecord fs -> PP.braces (commaCat $ map variable fs)
29 PAlias x p -> prettyParens p <+> PP.text "as" <+> variable x
30 PAnything -> PP.text "_"
31 PData "::" [hd,tl] -> parensIf isCons (pretty hd) <+> PP.text "::" <+> pretty tl
32 where isCons = case hd of
37 PP.parens . commaCat $ map pretty ps
38 else sep (PP.text name : map prettyParens ps)
40prettyParens pattern = parensIf needsThem (pretty pattern)
44 PData name (_:_) | not (isTuple name) -> True
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list