experimental/ast_pattern_matching

  Source   Edit

Implements pattern matching for NimNode AST. This module is copied from https://github.com/krux02/ast-pattern-matching.

############################### Example Code #################################

Types

MatchingErrorKind = enum
  NoError, WrongKindLength, WrongKindValue, WrongIdent, WrongCustomCondition
  Source   Edit

Consts

nnkFloatLiterals = (a: nnkFloatLit, b: nnkFloat64Lit)
  Source   Edit
nnkIntLiterals = (a: nnkCharLit, b: nnkUInt64Lit)
  Source   Edit
nnkStringLiterals = (a: nnkStrLit, b: nnkTripleStrLit)
  Source   Edit

Procs

proc `$`(arg: MatchingError): string {....raises: [], tags: [].}
  Source   Edit
proc checkCustomExpr(arg: NimNode; cond: bool; exprstr: string): MatchingError {.
    ...raises: [], tags: [].}
  Source   Edit
proc failWithMatchingError(arg: MatchingError): void {.compileTime, noReturn,
    ...raises: [], tags: [].}
  Source   Edit
proc matchIdent(arg: NimNode; value: string): MatchingError {....raises: [],
    tags: [].}
  Source   Edit
proc matchLengthKind(arg: NimNode; kind: NimNodeKind; length: int): MatchingError {.
    compileTime, ...raises: [], tags: [].}
  Source   Edit
proc matchLengthKind(arg: NimNode; kind: set[NimNodeKind]; length: int): MatchingError {.
    compileTime, ...raises: [], tags: [].}
  Source   Edit
proc recursiveNodeVisiting(arg: NimNode; callback: proc (arg: NimNode): bool) {.
    ...raises: [], tags: [].}
if callback returns true, visitor continues to visit the children of arg otherwise it stops.   Source   Edit

Macros

macro matchAst(astExpr: NimNode; args: varargs[untyped]): untyped
  Source   Edit
macro matchAstRecursive(ast: NimNode; args: varargs[untyped]): untyped
  Source   Edit

Exports

owner, newEnum, ==, expectIdent, newNilLit, hint, boolVal, newLit, callsite, astGenRepr, treeRepr, newLit, varargsLen, getTypeImpl, newConstStmt, children, getAst, expectLen, newLit, sameType, basename=, NimSymKind, copyChildrenTo, CallNodes, [], newLetStmt, dumpAstGen, newCall, newIdentDefs, newLit, []=, findChild, intVal, newStrLitNode, newStmtList, newLit, nodeID, newLit, typeKind, eqIdent, newLit, [], newLit, [], name, BindSymRule, $, newEmptyNode, newCommentStmtNode, infix, strVal, unpackPrefix, unpackInfix, body, newLit, bindSym, addPragma, newTree, newLit, newVarStmt, prefix, newLit, getTypeInst, nnkLiterals, nnkCallKinds, nestList, $, getTypeImpl, expectLen, basename, params, newPar, or, NimNodeKind, len, getAlign, newLit, dumpLisp, getTypeInst, genSym, postfix, newAssignment, LineInfo, intVal=, newIdentNode, getSize, getCustomPragmaVal, nnkRequireInitKinds, newLit, lineInfo, addIdentIfAbsent, newLit, eqIdent, copy, newNimNode, NimTypeKind, copyLineInfo, expectMinLen, floatVal=, add, insert, quote, pragma=, strVal=, newCall, copyNimNode, hasArgOfName, newLit, error, newIntLitNode, kind, newFloatLitNode, getImpl, symBodyHash, pairs, expandMacros, ident, newLit, hasCustomPragma, lineInfoObj, getProjectPath, parseExpr, NimNodeKinds, newLit, getOffset, newLit, RoutineNodes, newIfStmt, isExported, warning, newDotExpr, dumpTree, last, expectKind, newLit, params=, newLit, parseStmt, getType, eqIdent, copyNimTree, newProc, unpackVarargs, toStrLit, newColonExpr, extractDocCommentsAndRunnables, del, isInstantiationOf, newLit, getImplTransformed, newBlockStmt, name=, symKind, newLit, unpackPostfix, floatVal, newPar, lispRepr, items, body=, expectKind, pragma, []=, getType, add, newBlockStmt, eqIdent, nestList, signatureHash, AtomicNodes