|
| 1 | +import micros |
| 2 | +# CaseStmt ConstDef ElIfBranch ElseBranch EnumDef EnumField ForLoop IdentDef IfStmt LetDef NimName ObjectDef OfBranch PragmaVal RoutineNode RoutineSym StmtList TypeDefs = (EnumDef or ObjectDef) VarDef VarDefs = (VarDef or LetDef or ConstDef) WhenStmt WhileLoop |
| 3 | + |
| 4 | +type |
| 5 | + Comment* = distinct NimNode |
| 6 | + Call* = distinct NimNode |
| 7 | + Infix* = distinct NimNode |
| 8 | + Command* = distinct NimNode |
| 9 | + Prefix* = distinct NimNode |
| 10 | + Calls* = Call | Infix | Command | Prefix |
| 11 | + ImportStmt* = distinct NimNode |
| 12 | + ImportFrom* = distinct NimNode |
| 13 | + ImportExcept* = distinct NimNode |
| 14 | + Imports* = ImportStmt | ImportFrom | ImportExcept |
| 15 | + ExportStmt* = distinct NimNode |
| 16 | + DotExpr* = distinct NimNode |
| 17 | + |
| 18 | +func isa*(n: NimNode, _: typedesc[Comment]): bool = |
| 19 | + n.checkIt {nnkCommentStmt} |
| 20 | + |
| 21 | +func comment*(n: NimNode): Comment = n.checkConv Comment |
| 22 | + |
| 23 | +func isa*(n: NimNode, _: typedesc[Call]): bool = |
| 24 | + n.checkIt {nnkCall} |
| 25 | + |
| 26 | +func call*(n: NimNode): Call = n.checkConv Call |
| 27 | + |
| 28 | +func isa*(n: NimNode, _: typedesc[Infix]): bool = |
| 29 | + n.checkIt {nnkInfix} |
| 30 | + |
| 31 | +func infix*(n: NimNode): Infix = n.checkConv Infix |
| 32 | + |
| 33 | +func isa*(n: NimNode, _: typedesc[Command]): bool = |
| 34 | + n.checkIt {nnkCommand} |
| 35 | + |
| 36 | +func command*(n: NimNode): Command = n.checkConv Command |
| 37 | + |
| 38 | +func isa*(n: NimNode, _: typedesc[Prefix]): bool = |
| 39 | + n.checkIt {nnkPrefix} |
| 40 | + |
| 41 | +func prefix*(n: NimNode): Prefix = n.checkConv Prefix |
| 42 | + |
| 43 | +func isa*(n: NimNode, T: typedesc[Calls]): bool = |
| 44 | + n.checkIt: |
| 45 | + when T is Call: |
| 46 | + {nnkCall} |
| 47 | + elif T is Infix: |
| 48 | + {nnkInfix} |
| 49 | + elif T is Command: |
| 50 | + {nnkCommand} |
| 51 | + elif T is Prefix: |
| 52 | + {nnkPrefix} |
| 53 | + |
| 54 | +func isa*(n: NimNode, _: typedesc[ImportStmt]): bool = |
| 55 | + n.checkIt {nnkImportStmt} |
| 56 | + |
| 57 | +func importStmt*(n: NimNode): ImportStmt = n.checkConv ImportStmt |
| 58 | + |
| 59 | +func isa*(n: NimNode, _: typedesc[ImportFrom]): bool = |
| 60 | + n.checkIt {nnkFromStmt} |
| 61 | + |
| 62 | +func importFrom*(n: NimNode): ImportFrom = n.checkConv ImportFrom |
| 63 | + |
| 64 | +func isa*(n: NimNode, _: typedesc[ImportExcept]): bool = |
| 65 | + n.checkIt {nnkImportExceptStmt} |
| 66 | + |
| 67 | +func importExcept*(n: NimNode): ImportExcept = n.checkConv ImportExcept |
| 68 | + |
| 69 | +func isa*(n: NimNode, _: typedesc[Imports]): bool = |
| 70 | + n.checkIt: |
| 71 | + when T is ImportStmt: |
| 72 | + {nnkImportStmt} |
| 73 | + elif T is From: |
| 74 | + {nnkFromStmt} |
| 75 | + elif T is ImportExcept: |
| 76 | + {nnkImportExceptStmt} |
| 77 | + |
| 78 | +func isa*(n: NimNode, _: typedesc[ExportStmt]): bool = n.checkIt {nnkExportStmt} |
| 79 | + |
| 80 | +func exportStmt*(n: NimNode): ExportStmt = n.checkConv ExportStmt |
| 81 | + |
| 82 | +func isa*(n: NimNode, _: typedesc[DotExpr]): bool = n.checkIt {nnkDotExpr} |
| 83 | + |
| 84 | +func dotExpr*(n: NimNode): DotExpr = n.checkConv DotExpr |
| 85 | + |
| 86 | +func quoted*(n: NimName): NimName = |
| 87 | + NimName nnkAccQuoted.newTree(n.NimNode) |
0 commit comments