I'm looking for some advice on how to implement a proper conditional access 
operator.

The one in elvis: <https://github.com/mattaylor/elvis/blob/master/elvis.nim> is 
limited to using a proc for its `right` argument.

I want to be able to chain the `?.` operator, e.g.: `data?.obj.?prop`

So I was looking into the experimental pattern operator `*`, 
<https://nim-lang.github.io/Nim/manual_experimental.html#pattern-operators-the-nimstar-operator>,
 but the argument types in my example could potentially be all different.

I was trying out something like:
    
    
    proc `?.`(s: varargs[NimNode]): NimNode =
      echo s.repr
    
    template condAccess{ `?.` * a }(a: untyped): untyped = ?.a
    
    type Prop = object
      val*: int
    
    type Data = object
      prop*: ptr Prop
    
    var data: ptr Data = cast[ptr Data](alloc(sizeof(Data)))
    
    data?.prop
    
    
    Run

But I'm getting an error about `undeclared identifier: 'prop'`

Reply via email to