Skip to content

Commit

Permalink
Correctly handle closing paren for multiline parenthesized expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
avh4 committed Oct 20, 2015
1 parent 9e6540f commit 66074bf
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion parser/src/AST/Expression.hs
Expand Up @@ -50,7 +50,7 @@ data Expr'
| AccessFunction String
| Update Expr [(String, Expr, Bool)]
| Record [(String, Expr, Bool)]
| Parens Expr
| Parens Expr Bool
-- for type checking and code gen only
| Port PortImpl
| GLShader String String Literal.GLShaderTipe
Expand Down
2 changes: 1 addition & 1 deletion parser/src/Parse/Expression.hs
Expand Up @@ -114,7 +114,7 @@ parensTerm =
return $
case expressions of
[expression] ->
A.at start end (E.Parens expression)
A.at start end (E.Parens expression multiline)
_ ->
A.at start end (E.Tuple expressions multiline)

Expand Down
5 changes: 4 additions & 1 deletion src/Format.hs
Expand Up @@ -408,12 +408,15 @@ formatExpression inList aexpr =
]
in
vbox2 vStart $ vboxlist vPrefix ", " "}" pair pairs
AST.Expression.Parens expr ->
AST.Expression.Parens expr False ->
hbox
[ text "("
, formatExpression False expr
, text ")"
]
AST.Expression.Parens expr True->
vboxlist "( " "" ")" (formatExpression True) [expr]

AST.Expression.Port _ -> text "<port>"
AST.Expression.GLShader _ _ _ -> text "<glshader>"

Expand Down
17 changes: 17 additions & 0 deletions tests/test-files/good/AllSyntax.elm
Expand Up @@ -198,6 +198,23 @@ parenthesizedExpressions =
(1 + (2 * 3) / 4) |> ((+) 0)


multilineParenthesizedExpressions =
graphHeight
/ ( if range == 0 then
0.1
else
toFloat range
)


multilineParenthesizedExpressions =
( if range == 0 then
0.1
else
toFloat range
)


recordAccess r =
r.f1

Expand Down

0 comments on commit 66074bf

Please sign in to comment.