Open dan-fritchman opened 2 years ago
Commit 73b2da2 has handling for this, at least in the first case described above, in which a "closure parameter" has its own .param
statement.
The .param
-statement parser now does something like:
def parse_param_statement(self) -> Union[ast.ParamDecls, ast.FunctionDef]:
"""
Parse a `.param` statement, which defines one of:
* (a) A set of parameter-declaration `ParamDecl`s, or
* (b) A *single* "parameter function" `FunctionDef`.
Netlist syntax mixing the two, e.g.
.param a=5 b=6 func(x,y) 'x*a +y*b'
```
is not supported.
"""
self.expect(Tokens.PARAM)
# Parse the first key-name, so we can see what follows
_ = self.parse_ident()
if self.nxt and self.nxt.tp == Tokens.LPAREN:
# This is a function definition.
returnfunc = self.parse_function_def
else: # Otherwise, parse a set of parameter-declarations
returnfunc = lambda: ast.ParamDecls(self.parse_param_declarations())
# Either way, push the first ident back on before calling `returnfunc`
self.rewind()
# And call the parsing function for either the `ParamDecls` or `FunctionDef`
return returnfunc()
As noted in that function signature, mixing "value parameters" and "closure parameters" (both made-up names) in the same `.param` statement, like so:
.param a=5 b=6 func(x,y) 'xa +yb'
is not supported.
It remains unclear (to me) whether such syntax is supported by any significant spice-class simulators.
In breaking news to me, parameters of the form of
closure_param
below:I don't know if they give such a thing a name. Here I will call it a "closure parameter", since it looks very much like a function-call which also captures some of its environment.
It is not yet clear whether nesting these among "regular parameters" like so is supported: