Skip to content

Instantly share code, notes, and snippets.

@taotetek
Created June 13, 2015 14:59
Show Gist options
  • Save taotetek/c16f441066363f38e262 to your computer and use it in GitHub Desktop.
Save taotetek/c16f441066363f38e262 to your computer and use it in GitHub Desktop.
wow.nim(10, 30) Error: type mismatch: got (NimNode)
but expected one of:
macros.newIdentNode(i: NimIdent)
macros.newIdentNode(i: string)
import os, streams, parsexml, strutils, macros
macro makeAConst(myName: string, myValue: string): stmt =
result = newNimNode(nnkStmtList)
var
section = newNimNode(nnkConstSection)
constDef = newNimNode(nnkConstDef)
constDef.add(newIdentNode(myName))
constDef.add(newEmptyNode())
constDef.add(newIntLitNode(parseInt(myValue)))
section.add(constDef)
result.add(section)
if paramCount() < 1:
quit("Usage: parse filename[.xml]")
var filename = addfileExt(paramStr(1), "xml")
var s = newFileStream(filename, fmRead)
if s == nil: quit("Cannot open the file" & filename)
var x: XmlParser
open(x, s, filename)
next(x)
while true:
case x.kind
of xmlEof: break
of xmlElementOpen, xmlElementStart:
if x.elementName == "constant":
x.next
var itemname = x.attrValue
x.next
var itemval = x.attrValue
echo itemname, " : ", itemval
makeAConst(itemname, itemval)
else: discard
next(x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment