String to AST

2024-05-18 Thread xealits
Yes, the goal was the control flow of the program. Yeah, looking more at what `PNode` tree contains, I see that it is really just syntax. (The `if` statement `PNode` contains things like `nkIdent` ":".) I need the _semantic [tree](https://forum.nim-lang.org/postActivity.xml#tree) of the code. B

String to AST

2024-05-18 Thread xealits
Unfortunately, the new URL leads to few information on the compiler architecture for a user like I am. My idea was to use Nim's first-class meta-programming features to plot simple control flow graphs. >From >[parseString](https://github.com/nim-lang/Nim/blob/devel/compiler/parser.nim#L2574) >

String to AST

2024-05-13 Thread xealits
Aha, I just had to install `nimble install compiler`. Otherwise it did not find the package `compiler/parser`: $ cat parse_nimcode.nim import compiler/parser ... $ nim c -r parse_nimcode.nim Hint: used config file '/.../.local/nim/config/nim.cfg' [Conf] Hint:

String to AST

2024-05-13 Thread xealits
OK, this works: import compiler/parser import compiler/idents import compiler/options let code_string: string = "echo \"Hello world!\"" let code_ident = IdentCache() code_conf = ConfigRef() code_ast = parseString(code_string, code_ide

String to AST

2024-04-28 Thread xealits
can I revive this question? How to import [the compiler parser module](https://nim-lang.org/docs/intern.html#the-compiler-s-architecture) and its procs in nim 2.0? E.g. [parseString()](https://nim-lang.org/docs/compiler/parser.html#parseString%2Cstring%2CIdentCache%2CConfigRef%2Cstring%2Cint%2CE

Is it impossible to declare an _empty enum_ under quote in order to populate it later in a macro?

2024-02-19 Thread xealits
Thanks for the links! I think it may actually be a good idiom to declare dummy nodes and delete them in the macro. The dummy nodes can serve as a demo for other developers of what you intend to do in the macro.

Is it impossible to declare an _empty enum_ under quote in order to populate it later in a macro?

2024-02-19 Thread xealits
It looks like `newEnum` also requires the enum to have at least one field: macro ... = enumDef = newEnum(`enumName`, [], true, true) $ nim c -r -d:release basic_macro.nim ... /.../.local/nim/lib/core/macros.nim(1272, 10) Error: Enum must contain at least one fi

Is it impossible to declare an _empty enum_ under quote in order to populate it later in a macro?

2024-02-18 Thread xealits
I would like to generate an enum and a matching array of strings in a macro, as in [this example](https://peterme.net/metaprogramming-and-read-and-maintainability-in-nim.html) but with `quote` [instead of direct tree nodes](https://gist.github.com/xealits/2c7f1468cff736c129b251317aa2bbda) like