← Prev in month ← Prev in thread
Next in thread → Next in month →

New syntax for function calls

From
—
Date
2021-03-16T23:51:00+00:00
ID
<>
Thread
New syntax for function calls
Ah, you're right -- it's actually the double !! that would be a problem. We can choose a different character, like "@" or "%". I don't think this is a problem for "any string", as you say. Function calls can only exist within value assignments of properties, attributes, and parameters, and they must also be a YAML map with a single string key. On Tue, Mar 16, 2021 at 3:01 PM adam souzis < [email protected] > wrote: This is interesting idea but leading "!" is reserved in yaml for tags (see https://camel.readthedocs.io/en/latest/yamlref.html#tags ) and so these would always need to be quoted with is awkward. Also, I should note that since we currently accept any string with no constraints as a valid identifier any kind of syntax like this (or a syntax for generating template names like you previously proposed) are ambiguous. -- Adam á On Tue, Mar 16, 2021 at 10:56 AM Tal Liron < [email protected] > wrote: This is an old topic, but worth resurrecting. The problem with the current syntax: mynode: type: MyType properties: name: { get_input: site } Is that locks away the function name from being used as a map key. What do I mean? Let's rewrite it with a different notation, just to emphasize that it is indeed a map: mynode: type: MyType properties: name: get_input: site Now imagine this definition: MyType: properties: name: type: map As you can see, the parser has no trivial way to distinguish "get_input" from being a function call vs. being a literal key in a map with a single key. There's another more subtle problem. if someone tries to call a non-existent function, they would get a confusing error, e.g.: mynode: type: MyType properties: name: { get_output: site } There's currently no "get_output" function in TOSCA. But, the error would not be about a non-existing function, it would be about trying to assign a map to something that is not a map. Things could get even worse if the property type actually is a map! The service template will be silently processed, and the user would not even know that the supposed function was not processed! It could lead to very hard-to-find bugs. I propose adding a prefix character to all function calls. I'll arbitrarily choose "!". E.g.: mynode: type: MyType properties: name: { !get_input: site } All these problems now disappear. When encountering a "!" prefix for a map with a single key, the TOSCA parser will expect it to be a function call and will emit a clear error if the function name is not recognized. You might be asking how to handle a literal map with a single key that really has a "!" prefix. Well, we can support escaping using a double prefix, e.g. mynode: type: MyType properties: name: !!not-a-function: site The double "!!" will become a single "!" and it will not be treated as a function call. This is deterministic and, as long as it's documented, should not be confusing, especially since it would likely be a very rare use case.
← Prev in month ← Prev in thread
Next in thread → Next in month →