1{-# OPTIONS_GHC -Wall #-}
2{-# LANGUAGE OverloadedStrings #-}
10import qualified Data.List as List
11import Data.Monoid ((<>))
12import Data.Text (Text)
13import qualified Data.Text.Lazy as LazyText
14import Data.Text.Lazy.Builder (Builder, fromText, toLazyText)
16import qualified AST.Literal as L
17import qualified AST.Pattern as P
18import qualified AST.Variable as Var
19import qualified Reporting.Annotation as A
27 = Ctor Var.Canonical [Pattern]
33fromCanonicalPattern :: P.Canonical -> Pattern
34fromCanonicalPattern (A.A _ pattern) =
36 P.Ctor name patterns ->
37 Ctor name (map fromCanonicalPattern patterns)
42 P.Alias _ subPattern ->
43 fromCanonicalPattern subPattern
51 P.Literal (L.Boolean True) ->
54 P.Literal (L.Boolean False) ->
65toText :: Pattern -> Text
67 LazyText.toStrict (toLazyText (toBuilder False pattern))
70toBuilder :: Bool -> Pattern -> Builder
71toBuilder needsParens pattern =
73 Ctor tag [first,rest] | Var.isCons tag ->
74 toBuilder (isCons first) first <> " :: " <> toBuilder False rest
77 if Var.isTuple tag then
78 if null args then "()" else
80 <> mconcat (List.intersperse ", " (map (toBuilder False) args))
84 addParensIf (needsParens && not (null args)) $
85 mconcat (List.intersperse " " (fromText (Var.toText tag) : map (toBuilder True) args))
94addParensIf :: Bool -> Builder -> Builder
95addParensIf needsParens str =
103isCons :: Pattern -> Bool
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