You could of course write a macro like this which simply makes the last 
argument explicitly be the actions argument:
    
    
    let Chrome = "Chrome"
    
    template webSessionImpl*(
      sessionInfo: untyped,
      baseURL: string,
      browser = Chrome,
      headless = true,
      actions: untyped
      ) =
      block:
        # Mock open session
        var sessionInfo =
          "open Session(" &
          "baseURL=" & "\"" & baseURL & "\", " &
          "browser=" & $browser & ", " &
          "headless=" & $headless & ")"
        
        actions
        
        # Mock session cleanup
        echo "close Session"
    
    import macros
    
    macro webSession(nodes: varargs[untyped]): untyped =
      result = newCall("webSessionImpl")
      for i, node in nodes:
        if i != nodes.len - 1:
          result.add node
        else:
          result.add nnkExprEqExpr.newTree(newIdentNode("actions"), node)
    
    webSession(mySite, "https://mysite.com";, Chrome, false):
      echo mySite
    
    webSession(mySite, "https://mysite.com";):
      echo mySite
    
    webSession(mySite, "https://mysite.com";, headless = false):
      echo mySite
    
    webSession(mySite, "https://mysite.com";, browser = "Firefox"):
      echo mySite
    
    
    Run

Note that I also wrapped your template in a block to avoid redefinition of 
`mySite` but I'm not sure you'd actually want that.

Reply via email to