1{-# LANGUAGE DeriveDataTypeable #-}
2module SourceSyntax.Pattern where
4import Data.List (intercalate)
6import SourceSyntax.Helpers as Help
7import SourceSyntax.PrettyPrint
8import Text.PrettyPrint as PP
9import SourceSyntax.Literal as Literal
11data Pattern = PData String [Pattern]
13 | PAlias String Pattern
16 | PLiteral Literal.Literal
17 deriving (Eq, Ord, Data, Typeable, Show)
19cons h t = PData "::" [h,t]
22tuple es = PData ("_Tuple" ++ show (length es)) es
25instance Pretty Pattern where
29 PLiteral lit -> pretty lit
30 PRecord fs -> PP.braces (commaCat $ map variable fs)
31 PAlias x p -> prettyParens p <+> PP.text "as" <+> variable x
32 PAnything -> PP.text "_"
33 PData "::" [hd,tl] -> parensIf isCons (pretty hd) <+> PP.text "::" <+> pretty tl
34 where isCons = case hd of
39 PP.parens . commaCat $ map pretty ps
40 else sep (PP.text name : map prettyParens ps)
42prettyParens pattern = parensIf needsThem (pretty pattern)
46 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