Created
June 13, 2015 14:59
-
-
Save taotetek/c16f441066363f38e262 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
wow.nim(10, 30) Error: type mismatch: got (NimNode) | |
but expected one of: | |
macros.newIdentNode(i: NimIdent) | |
macros.newIdentNode(i: string) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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