Skip to content

Commit

Permalink
Add Node around QualifiedNameRef in DestructurePatterns
Browse files Browse the repository at this point in the history
  • Loading branch information
jfmengels committed May 30, 2022
1 parent edb9e19 commit 3cbe410
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
6 changes: 3 additions & 3 deletions src/Elm/Parser/Declarations.elm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Elm.Parser.Declarations exposing (caseBlock, caseStatement, caseStatements, declaration, expression, function, functionArgument, functionSignature, letBlock, letBody, letExpression, signature)

import Combine exposing (Parser, choice, lazy, many, maybe, modifyState, or, sepBy1, string, succeed, withLocation)
import Elm.Parser.DestructurePatterns as DestructurPatterns exposing (destructurPattern)
import Elm.Parser.DestructurePatterns as DestructurPatterns exposing (destructurePattern)
import Elm.Parser.Infix as Infix
import Elm.Parser.Layout as Layout
import Elm.Parser.Node as Node
Expand Down Expand Up @@ -149,7 +149,7 @@ portDeclaration =

functionArgument : Parser State (Node DestructurePattern)
functionArgument =
DestructurPatterns.destructurPattern
DestructurPatterns.destructurePattern



Expand Down Expand Up @@ -502,7 +502,7 @@ letBody =
let
blockElement : Parser State LetDeclaration
blockElement =
destructurPattern
destructurePattern
|> Combine.andThen
(\(Node r p) ->
case p of
Expand Down
10 changes: 5 additions & 5 deletions src/Elm/Parser/DestructurePatterns.elm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Elm.Parser.DestructurePatterns exposing (destructurPattern)
module Elm.Parser.DestructurePatterns exposing (destructurePattern)

import Combine exposing (Parser, between, lazy, many, maybe, parens, sepBy, string)
import Elm.Parser.Base as Base
Expand Down Expand Up @@ -27,8 +27,8 @@ tryToCompose x =
)


destructurPattern : Parser State (Node DestructurePattern)
destructurPattern =
destructurePattern : Parser State (Node DestructurePattern)
destructurePattern =
composablePattern |> Combine.andThen tryToCompose


Expand All @@ -37,7 +37,7 @@ parensPattern =
Combine.lazy
(\() ->
Node.parser
(parens (sepBy (string ",") (Layout.maybeAroundBothSides destructurPattern))
(parens (sepBy (string ",") (Layout.maybeAroundBothSides destructurePattern))
|> Combine.map
(\c ->
case c of
Expand Down Expand Up @@ -100,7 +100,7 @@ qualifiedPattern consumeArgs =
(\args ->
Node
(Range.combine (range :: List.map (\(Node r _) -> r) args))
(NamedPattern_ (QualifiedNameRef mod name) args)
(NamedPattern_ (Node range (QualifiedNameRef mod name)) args)
)
)

Expand Down
18 changes: 11 additions & 7 deletions src/Elm/Syntax/DestructurePattern.elm
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ For example:
-}

import Elm.Json.Util exposing (decodeTyped, encodeTyped)
import Elm.Syntax.ModuleName as ModuleName exposing (ModuleName)
import Elm.Syntax.ModuleName as ModuleName
import Elm.Syntax.Node as Node exposing (Node)
import Elm.Syntax.Pattern exposing (QualifiedNameRef)
import Json.Decode as JD exposing (Decoder)
Expand All @@ -47,7 +47,7 @@ type DestructurePattern
| TuplePattern_ (List (Node DestructurePattern))
| RecordPattern_ (List (Node String))
| VarPattern_ String
| NamedPattern_ QualifiedNameRef (List (Node DestructurePattern))
| NamedPattern_ (Node QualifiedNameRef) (List (Node DestructurePattern))
| AsPattern_ (Node DestructurePattern) (Node String)
| ParenthesizedPattern_ (Node DestructurePattern)

Expand Down Expand Up @@ -92,10 +92,14 @@ encode pattern =
encodeTyped "named" <|
JE.object
[ ( "qualified"
, JE.object
[ ( "moduleName", ModuleName.encode qualifiedNameRef.moduleName )
, ( "name", JE.string qualifiedNameRef.name )
]
, Node.encode
(\{ moduleName, name } ->
JE.object
[ ( "moduleName", ModuleName.encode moduleName )
, ( "name", JE.string name )
]
)
qualifiedNameRef
)
, ( "patterns", JE.list (Node.encode encode) patterns )
]
Expand Down Expand Up @@ -127,7 +131,7 @@ decoder =
, ( "tuple", JD.field "value" (JD.list (Node.decoder decoder)) |> JD.map TuplePattern_ )
, ( "record", JD.field "value" (JD.list (Node.decoder JD.string)) |> JD.map RecordPattern_ )
, ( "var", JD.field "value" JD.string |> JD.map VarPattern_ )
, ( "named", JD.map2 NamedPattern_ (JD.field "qualified" decodeQualifiedNameRef) (JD.field "patterns" (JD.list (Node.decoder decoder))) )
, ( "named", JD.map2 NamedPattern_ (JD.field "qualified" (Node.decoder decodeQualifiedNameRef)) (JD.field "patterns" (JD.list (Node.decoder decoder))) )
, ( "as", JD.map2 AsPattern_ (JD.field "pattern" (Node.decoder decoder)) (JD.field "name" (Node.decoder JD.string)) )
, ( "parentisized", JD.map ParenthesizedPattern_ (JD.field "value" (Node.decoder decoder)) )
]
Expand Down
2 changes: 1 addition & 1 deletion src/Elm/Writer.elm
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ writeDestructurPattern (Node _ p) =
VarPattern_ var ->
string var

NamedPattern_ qnr others ->
NamedPattern_ (Node _ qnr) others ->
spaced
[ writeQualifiedNameRef qnr
, spaced (List.map writeDestructurPattern others)
Expand Down

0 comments on commit 3cbe410

Please sign in to comment.