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_ident, code_conf)
#code_ast = parseString(code_string)
echo code_ast.repr
# code_ast.treeRepr - unfortunately:
# Error: undeclared field: 'treeRepr' for type ast.PNode
Run
The output:
PNode(typ: nil, info: TLineInfo(line: 1, col: 0, fileIndex: 0), flags: {},
kind: nkStmtList,
sons: @[PNode(typ: nil, info: TLineInfo(line: 1, col: 0, fileIndex: 0),
flags: {}, kind: nkCommand,
sons: @[PNode(typ: nil, info: TLineInfo(line: 1, col: 0, fileIndex: 0),
flags: {}, kind: nkIdent, ident: PIdent(id: -1, s: "echo", next: nil, h:
-3990281224686746450)),
PNode(typ: nil, info: TLineInfo(line: 1, col: 5, fileIndex: 0),
flags: {}, kind: nkStrLit, strVal: "Hello world!")])])
Run