AST walking similar to python

2024-03-18 Thread master234

AST walking similar to python

2024-03-12 Thread riscv
Some nodes were missing, found everything: import macros proc parseCustomStmt(code: string): NimNode {.compileTime.} = let tree = parseStmt(code) return tree macro parseAndVisit(code: static[string]): void = let tree = parseCustomStmt(code)

AST walking similar to python

2024-03-12 Thread riscv
Something similar to this partly works: import macros proc parseCustomStmt(code: string): NimNode {.compileTime.} = let tree = parseStmt(code) tree macro parseAndVisit(code: static[string]): void = let tree = parseCustomStmt(code)

AST walking similar to python

2024-03-12 Thread riscv
In Python, it is trivial to do this kind of AST walking for any valid python code that is provided as a string in a variable. import ast code_string = """ def foo(x, y): z = x + y return f(z, g(z)) """ module_node = ast.parse(code_string)