1module Nitpick.Pattern where
3import qualified Data.List as List
4import qualified Data.Set as Set
6import qualified AST.Literal as L
7import qualified AST.Pattern as P
8import qualified AST.Variable as Var
9import qualified Reporting.Annotation as A
13 = Data Var.Canonical [Pattern]
15 | Alias String Pattern
19 | AnythingBut (Set.Set L.Literal)
23fromCanonicalPattern :: P.CanonicalPattern -> Pattern
24fromCanonicalPattern (A.A _ pattern) =
26 P.Data tag patterns ->
27 Data tag (map fromCanonicalPattern patterns)
32 P.Alias name pattern ->
33 Alias name (fromCanonicalPattern pattern)
47toString :: Bool -> Pattern -> String
48toString needsParens pattern =
50 Data tag [first,rest] | Var.toString tag == "::" ->
51 toString (isCons first) first
53 ++ toString False rest
56 if Var.isTuple tag then
57 "(" ++ List.intercalate ", " (map (toString False) args) ++ ")"
60 addParensIf (needsParens && not (null args)) $
61 List.intercalate " " (Var.toString tag : map (toString True) args)
64 "{ " ++ List.intercalate ", " fields ++ " }"
66 Alias alias realPattern ->
67 addParensIf needsParens $
68 toString False realPattern ++ " as " ++ alias
79 AnythingBut literalSet ->
80 List.intercalate " " ("<values besides:" : map L.toString (Set.toList literalSet) ++ [">"])
83addParensIf :: Bool -> String -> String
84addParensIf needsParens str =
92isCons :: Pattern -> Bool
96 Var.toString 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