macro findAllAndPrint(n: untyped) =
      result = n
      result.forNode(
        {nnkIntLit..nnkUInt64Lit},
        proc(x: NimNode): NimNode =
          if x.kind in {nnkIntLit..nnkUInt64Lit}:
            echo repr x, ": ", x.kind
            return x
          return x
      )
    
    proc test(a: int, b: int16, c: int32) =
      discard
    
    proc main() {.findAllAndPrint.} =
      test(
        1,
        2,
        3
      )
    
    main()
    
    
    Run

This proc is quite simple, just finds the literals and replaces them with the 
Node you want. For simplicity in this code, it simply returns the same Node.
    
    
    proc forNode*(node: NimNode,
                      kind: NimNodeKind or NimNodeKinds,
                      action: proc (x: NimNode): NimNode): NimNode = ...
    
    
    Run

Output:
    
    
    1: nnkIntLit
    2: nnkIntLit
    3: nnkIntLit
    
    
    Run

But I expected this:
    
    
    1: nnkIntLit
    2: nnkInt16Lit
    3: nnkInt32Lit
    
    
    Run

@Araq please help :) 

Reply via email to