mirror of
https://github.com/jfmengels/elm-review.git
synced 2024-12-23 17:53:35 +03:00
Re-implement collectNamesFromPattern in a TCO way
This commit is contained in:
parent
ba0013793d
commit
2b386ca80b
@ -5460,33 +5460,47 @@ parameters patterns =
|
||||
|
||||
collectNamesFromPattern : Node Pattern -> List (Node String)
|
||||
collectNamesFromPattern pattern =
|
||||
collectNamesFromPatternHelp [ pattern ] []
|
||||
|
||||
|
||||
collectNamesFromPatternHelp : List (Node Pattern) -> List (Node String) -> List (Node String)
|
||||
collectNamesFromPatternHelp patternsToVisit acc =
|
||||
case patternsToVisit of
|
||||
pattern :: restOfPatternsToVisit ->
|
||||
case Node.value pattern of
|
||||
Pattern.TuplePattern subPatterns ->
|
||||
List.concatMap collectNamesFromPattern subPatterns
|
||||
|
||||
Pattern.RecordPattern names ->
|
||||
names
|
||||
|
||||
Pattern.UnConsPattern left right ->
|
||||
List.concatMap collectNamesFromPattern [ left, right ]
|
||||
|
||||
Pattern.ListPattern subPatterns ->
|
||||
List.concatMap collectNamesFromPattern subPatterns
|
||||
|
||||
Pattern.VarPattern name ->
|
||||
[ Node (Node.range pattern) name ]
|
||||
collectNamesFromPatternHelp
|
||||
restOfPatternsToVisit
|
||||
(Node (Node.range pattern) name :: acc)
|
||||
|
||||
Pattern.NamedPattern _ subPatterns ->
|
||||
List.concatMap collectNamesFromPattern subPatterns
|
||||
collectNamesFromPatternHelp (subPatterns ++ restOfPatternsToVisit) acc
|
||||
|
||||
Pattern.AsPattern subPattern alias ->
|
||||
alias :: collectNamesFromPattern subPattern
|
||||
Pattern.RecordPattern names ->
|
||||
collectNamesFromPatternHelp
|
||||
restOfPatternsToVisit
|
||||
(names ++ acc)
|
||||
|
||||
Pattern.ParenthesizedPattern subPattern ->
|
||||
collectNamesFromPattern subPattern
|
||||
collectNamesFromPatternHelp (subPattern :: restOfPatternsToVisit) acc
|
||||
|
||||
Pattern.AsPattern subPattern alias ->
|
||||
collectNamesFromPatternHelp (subPattern :: restOfPatternsToVisit) (alias :: acc)
|
||||
|
||||
Pattern.TuplePattern subPatterns ->
|
||||
collectNamesFromPatternHelp (subPatterns ++ restOfPatternsToVisit) acc
|
||||
|
||||
Pattern.UnConsPattern left right ->
|
||||
collectNamesFromPatternHelp (left :: right :: restOfPatternsToVisit) acc
|
||||
|
||||
Pattern.ListPattern subPatterns ->
|
||||
collectNamesFromPatternHelp (subPatterns ++ restOfPatternsToVisit) acc
|
||||
|
||||
_ ->
|
||||
[]
|
||||
collectNamesFromPatternHelp restOfPatternsToVisit acc
|
||||
|
||||
[] ->
|
||||
acc
|
||||
|
||||
|
||||
collectModuleNamesFromPattern : ScopeModuleContext -> Node Pattern -> List ( Range, ModuleName )
|
||||
|
Loading…
Reference in New Issue
Block a user