1{-# OPTIONS_GHC -Wall #-}
2{-# LANGUAGE OverloadedStrings #-}
10import qualified Data.List as List
11import Data.Monoid ((<>))
12import qualified Data.Text.Lazy as LazyText
13import Data.Text.Lazy.Builder (Builder, fromText, toLazyText)
15import qualified AST.Literal as L
16import qualified AST.Pattern as P
17import qualified AST.Variable as Var
18import qualified Reporting.Annotation as A
26 = Ctor Var.Canonical [Pattern]
32fromCanonicalPattern :: P.Canonical -> Pattern
33fromCanonicalPattern (A.A _ pattern) =
35 P.Ctor name patterns ->
36 Ctor name (map fromCanonicalPattern patterns)
41 P.Alias _ subPattern ->
42 fromCanonicalPattern subPattern
50 P.Literal (L.Boolean True) ->
51 Ctor (Var.builtin "True") []
53 P.Literal (L.Boolean False) ->
54 Ctor (Var.builtin "False") []
64toString :: Pattern -> String
66 LazyText.unpack (toLazyText (toBuilder False pattern))
69toBuilder :: Bool -> Pattern -> Builder
70toBuilder needsParens pattern =
72 Ctor tag [first,rest] | Var.toText tag == "::" ->
73 toBuilder (isCons first) first <> " :: " <> toBuilder False rest
76 if Var.isTuple tag then
77 if null args then "()" else
79 <> mconcat (List.intersperse ", " (map (toBuilder False) args))
83 addParensIf (needsParens && not (null args)) $
84 mconcat (List.intersperse " " (fromText (Var.toText tag) : map (toBuilder True) args))
93addParensIf :: Bool -> Builder -> Builder
94addParensIf needsParens str =
102isCons :: Pattern -> Bool
106 Var.toText tag == "::"
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