Skip to content

Commit

Permalink
ntAccQuoted handler replace str format with multiReplace
Browse files Browse the repository at this point in the history
Signed-off-by: George Lemon <[email protected]>
  • Loading branch information
georgelemon committed Aug 4, 2023
1 parent 68955a6 commit d336f30
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/bropkg/engine/compiler.nim
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,19 @@ proc toString(c: var Compiler, v: Node, scope: ScopeTable = nil): string =
of ntArray: jsony.toJson(v.arrayItems)
of ntObject: jsony.toJson(v.pairsVal)
of ntAccQuoted:
var accValues: seq[string]
var accValues: seq[(string, string)]
for accVar in v.accVars:
add accValues, "bro" & $(hash(accVar.callIdent[1..^1])) # variable name without `$`
add accValues, c.toString(c.getValue(accVar, scope))
v.accVal.format(accValues)
var accVal: (string, string)
accVal[0] = "$bro"
case accVar.nt
of ntCall:
add accVal[0], $(hash(accVar.callIdent[1..^1])) # variable name without `$`
of ntInt:
add accVal[0], $(hash($accVar.iVal))
else: discard
accVal[1] = c.toString(c.getValue(accVar, scope))
add accValues, accVal
v.accVal.multiReplace(accValues)
of ntStream:
toString(v.streamContent)
else: ""
Expand Down Expand Up @@ -303,6 +311,7 @@ proc handleCommand(c: var Compiler, node: Node, scope: ScopeTable = nil) =
# "[[" & $(node.cmdValue.nodeType) & "]]")
else:
let varValue = c.getValue(node.cmdValue, scope)
# echo varValue
if likely(varValue != nil):
var output: string
case varValue.nt:
Expand Down
5 changes: 5 additions & 0 deletions src/bropkg/engine/handlers/pLiteral.nim
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ newPrefixProc "parseAccQuoted":
if likely(varNode != nil):
add result.accVars, varNode
else: return nil
else:
let prefixInfixNode = p.getPrefixOrInfix(scope, includeOnly = {tkInteger})
if likely(prefixInfixNode != nil):
add result.accVars, prefixInfixNode
else: return nil
walk p # tkRC
else:
add result.accVal, indent(p.curr.value, p.curr.wsno)
Expand Down

0 comments on commit d336f30

Please sign in to comment.