Skip to content

Commit

Permalink
Scala gen enhancements (#143)
Browse files Browse the repository at this point in the history
* Fix elm-syntax version in CLI.

* Fix elm-syntax operator precedence.

* Use better literal wrappers in generated Scala.

* Generate case objects for no-argument type constructors. #105

* Flatten nested let expressions. #140

* Use val instead of def when there are no arguments. #141

* Cosmetic improvement.

* Add type information to vals. #141
  • Loading branch information
AttilaMihaly committed Sep 1, 2020
1 parent e1faadf commit ee37dbb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/Morphir/Scala/AST.elm
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ type MemberDecl
| ValueDecl
{ modifiers : List Mod
, pattern : Pattern
, valueType : Maybe Type
, value : Value
}
| FunctionDecl
Expand Down
2 changes: 2 additions & 0 deletions src/Morphir/Scala/Backend.elm
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,7 @@ mapValue value =
Scala.ValueDecl
{ modifiers = []
, pattern = Scala.NamedMatch (defName |> Name.toCamelCase)
, valueType = Just (mapType def.outputType)
, value = mapValue def.body
}

Expand Down Expand Up @@ -544,6 +545,7 @@ mapValue value =
[ Scala.ValueDecl
{ modifiers = []
, pattern = mapPattern bindPattern
, valueType = Nothing
, value = mapValue bindValue
}
]
Expand Down
16 changes: 15 additions & 1 deletion src/Morphir/Scala/PrettyPrinter.elm
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ mapMemberDecl opt memberDecl =
concat
[ "val "
, mapPattern decl.pattern
, case decl.valueType of
Just tpe ->
concat [ ": ", mapType opt tpe ]

Nothing ->
empty
, " = "
, mapValue opt decl.value
]
Expand Down Expand Up @@ -395,12 +401,20 @@ mapValue opt value =
[ "if "
, parens (mapValue opt condValue)
, " "
, statementBlock opt [ trueValue |> mapValue opt ]
, case trueValue of
Block _ _ ->
mapValue opt trueValue

_ ->
statementBlock opt [ mapValue opt trueValue ]
, " else "
, case falseValue of
IfElse _ _ _ ->
mapValue opt falseValue

Block _ _ ->
mapValue opt falseValue

_ ->
statementBlock opt [ mapValue opt falseValue ]
]
Expand Down

0 comments on commit ee37dbb

Please sign in to comment.