Skip to content

Commit

Permalink
Merge pull request #61 from isaacvando/template-updates
Browse files Browse the repository at this point in the history
Update template code and index.md
  • Loading branch information
gvwilson authored Apr 27, 2024
2 parents 5744717 + 812193c commit 60b1a8b
Show file tree
Hide file tree
Showing 17 changed files with 712 additions and 304 deletions.
25 changes: 25 additions & 0 deletions template/CodeGen.roc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ generate = \templates ->
|> indent

"""
# Generated by RTL https://github.com/isaacvando/rtl
interface Pages
exposes [
$(names)
Expand All @@ -39,6 +41,7 @@ RenderNode : [
Text Str,
Conditional { condition : Str, trueBranch : List RenderNode, falseBranch : List RenderNode },
Sequence { item : Str, list : Str, body : List RenderNode },
WhenIs { expression : Str, cases : List { pattern : Str, branch : List RenderNode } },
]

renderTemplate : { name : Str, nodes : List Node } -> Str
Expand Down Expand Up @@ -91,6 +94,21 @@ toStr = \node ->
$(renderNodes body)
|> Str.joinWith ""
"""

WhenIs { expression, cases } ->
branches =
List.map cases \{ pattern, branch } ->
"""
$(pattern) ->
$(renderNodes branch)
"""
|> Str.joinWith "\n"
|> indent
"""
when $(expression) is
$(branches)
"""
indent block

condense : List Node -> List RenderNode
Expand All @@ -111,6 +129,13 @@ condense = \nodes ->
trueBranch: condense trueBranch,
falseBranch: condense falseBranch,
}

WhenIs { expression, cases } ->
WhenIs {
expression,
cases: List.map cases \{ pattern, branch } ->
{ pattern, branch: condense branch },
}
|> List.walk [] \state, elem ->
when (state, elem) is
([.. as rest, Text x], Text y) ->
Expand Down
Loading

0 comments on commit 60b1a8b

Please sign in to comment.