I think this source is outdated: 
[https://flenniken.net/blog/nim-macros](https://flenniken.net/blog/nim-macros)/ 
Compiler complains there's no children field in nim node. When look at official 
documentation, I found sons field. Should I use sons? Also, I look inside some 
system file of nim and there's NimNode declared as an reference to Node. Should 
I use rectangle operator to access NimNode fields? My code now looks like this: 
    
    
    macro get_decl_name(decl: untyped): untyped =
      for a in decl.children:
        if a is nnkTypeDef:
          for c in a.children:
            if c is IdentNode:
              return c
    type
      progress_specenum = object
        map: seq[string]
    
    var generated: string
    
    macro generate_specenum*(names_of_values: static[seq[string]]; decl: 
untyped): untyped =
      var name = get_decl_name(decl)
      var code = fmt"var\n  progress_specenum_{name}: progress_specenum = 
progress_specenum(map: name_of_values)\n"
      code &= fmt"proc get_str_repr_of_specenum_{name}(val: {name}): string =\n 
 "
      code &= fmt"for a in progress_specenum_{name}.map:\n    "
      code &= fmt"if a == val: return a\n  "
      code &= fmt"return nil"
      
      code &= fmt"proc get_val_of_specenum_{name}_from_str(val: string): {name} 
=\n  "
      code &= fmt"var curr: {name}\n  "
      code &= fmt"for a in progress_specenum_{name}.map:\n    "
      code &= fmt"if a == val: return curr\n    "
      code &= fmt"succ(curr)\n  "
      code &= fmt"return BAD"
      
      generated &= code
    
    macro flush_ruleset_rel_code*() =
      result = parseStmt(generated)
      generated = ""
    
    
    Run

But compiler complains there's no field children inside NimNode.

Reply via email to