Skip to content

Commit

Permalink
can-lehmann#115 Fix parsing bug with as assignment
Browse files Browse the repository at this point in the history
The Syntax "<Widget>() as <someStateRefVariable>" did not work.
This was due to a parsing-oversight in parseGui.
This PR corrects that.
  • Loading branch information
PhilippMDoerner committed Jun 22, 2024
1 parent 56c88cb commit b4dba5f
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion owlkettle/guidsl.nim
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ proc parseAdder(node: NimNode): Adder =
error("Unable to parse adder argument from " & $child.kind, child)

proc parseGui(node: NimNode): Node =
if node.repr.contains "ScrolledWindow":
echo "Node: \n", node.repr
echo "Tree: \n", node.treeRepr
case node.kind:
of nnkCallKinds - {nnkInfix}:
if node[0].unwrapName().eqIdent("insert"):
Expand All @@ -99,7 +102,12 @@ proc parseGui(node: NimNode): Node =
let isRefAssignmentExpression = asNode.kind == nnkIdent and $asNode == "as"
if not isRefAssignmentExpression:
error("You can only use infix for assigning stateReferences. That must be done via '<Widget> as <stateRefVariable>' syntax")
let widgetName = node[1]
let widgetName = case node[1].kind:
of nnkIdent: node[1]
of nnkCall: node[1][0]
else:
error("Tried to use 'as' with invalid syntax", node)
newEmptyNode() # Forces the compiler to acknowlege that all branches of the case statement return a NimNode
let widgetRefVar = node[2]
let widgetContent = node[3]

Expand Down

0 comments on commit b4dba5f

Please sign in to comment.