src/pylib/pysugar/stmt/tonim

Source   Edit  

Limits

global/nonlocal for nonexisting variable

In Python using global/nonlocal to declare a new variable is allowed, but here it may be impossible to implement, as Nim is statically-typed, we must know its type when declaring a variable, while getting a type from AST whose type is untyped is almostly impossible.

global/nonlocal only means not local, with some limited checks

  • Currently using global name where name is declared in previous frames is not supported
  • Currently using nonlocal name where name is used for globals is not supported

Procs

proc parsePyBody(mparser; body: NimNode): NimNode {....raises: [Exception],
    tags: [RootEffect], forbids: [].}
Source   Edit  
proc parsePyBodyWithDoc(mparser; body: NimNode): NimNode {....raises: [Exception],
    tags: [RootEffect], forbids: [].}
Source   Edit  
proc parsePyBodyWithDoc(mparser; body: NimNode; docNode: var NimNode): NimNode {.
    ...raises: [Exception], tags: [RootEffect], forbids: [].}
Rewrites doc-string to CommentStmtNode and assign to docNode (as nnkStmtList) and map each stmt with parsePyStmt. Source   Edit  
proc parsePyStmt(mparser; statement: NimNode): NimNode {....raises: [Exception],
    tags: [RootEffect], forbids: [].}

Rewrites statement from Python-favor to Nim

statement shall not be nnkStmtList

Source   Edit  

Templates

template parsePyBody(body: NimNode): NimNode
Source   Edit