Repository navigation
Description
Having inline keyword call syntax would be nice. It would allow using keywords in places where currently you'd normally just have plain strings (or variables). Example usages are listed below and possible syntax alternatives discussed in separate comments.
-
Arguments to other keywords. At the moment you need to this in two steps:
${result} = Keyword argument Another Keyword ${result}In Python and other "real" programming languages you use something like
another_keyword(keyword('argument')), but in Robot's syntaxAnother Keyword Keyword argumentis parsed as
Another Keywordgetting two arguments. This cannot be changed so new syntax is needed. -
Condition to the forthcoming
IF/ELSEsyntax (Native support forIF/ELSEsyntax #3074). Currently (well, in the future once IF/ELSE is supported), you need to use:${status} = Keyword IF ${status} Another Keyword ENDand
IF Keyword Another Keyword ENDwould be parsed as
Keywordbeing the expression to evaluate. -
Similarly existing FOR loops would benefit from this.
-
Inline keyword call syntax would also allow adding support to create variables in the
Variablessection based on keyword return values. Currently that's not possible at all, and creating suite level variables dynamically requires using Suite Setup. Being able to do something like this is a pretty common request:*** Variables *** ${EXAMPLE} = Keyword argument
The hardest thing related to this issue is coming up with a good syntax. I've been thinking about this for some time and have some ideas but no clear candidate I like best. I'll explain these ideas in separate comments below. 👍 and 👎 reactions, comments and other syntax ideas are all highly appreciated!
Activity
pekkaklarck commentedon May 16, 2019
My first idea was using
[Keyword|argument]syntax with single spaces allowed like[ Keyword | argument ]as well. Examples:Pros:
[ | ]visually match Robot's tabular syntax and looks pretty good in general.Cons:
[Documentation]. This probably wouldn't be a technical problem because inline keyword calls probably wouldn't be allowed in places where settings are allowed, but same syntax would still be confusing to users.@{list}and&{dict}variables allow. Most importantly this means that usage with FOR loops so that one keyword returns all values to iterate wouldn't be supported.pekkaklarck commentedon May 16, 2019
Second syntax ideas is using
${[ Keyword | argument ]}. Example:Pros:
@{[list]}and&{[dict]}syntax.${{expression}}(Inline Python evaluation support using${{expression}}syntax #3179).[Documentation].Cons:
${[xxx]},${{xxx}}and${xxx}all look pretty similar.pekkaklarck commentedon May 16, 2019
Yet another idea is using a variation of the current variable syntax
$[ Keyword | argument ]. Example:Pros:
${[ Keyword | argument ]}syntax.Cons:
[ Keyword | arguments ].$[xxx]and${xxx}still look similar.aaltat commentedon May 16, 2019
For me
$[ keyword | argument ]looks very close to the variable syntax.${is pretty same as$[. Although I have to admit that I don't have better idea and IDE can highlight the syntax better.pekkaklarck commentedon May 17, 2019
It's true that
$[Something]looks very much like${Something}so the benefits of using that instead of${[Something]}wouldn't be that big. If we'd use$[Something]with inline keyword calls, we could also consider using$(expression)with inline Python evaluation (#3179). But I'm not sure is${var},$(expr),$[kw]really better than${var},${{expr}},${[kw]}.HelioGuilherme66 commentedon May 17, 2019
What if to be more clear that it is not a variable we double the []?
sebastianciupinski commentedon May 21, 2019
What about pipelines or redirecting? I know it may be problematic with keyword accepting varargs, but anyway (pipeline symbols, i.e. '<$' and '$>' are just an idea):
could be:
But according to proposed approaches, I think following !{} which mean 'Evaluate what is inside'
or to distinguish what is returned:
looks better than proposed:
because using !{} does not mix two ways of separating keywords and arguments (one with tabulators, second with pipe symbol)
rainydew commentedon Jun 18, 2019
it that more natural?
parentheses may be better
I use pycharm and IntelliBot, but it may be ugly in RIDE cell view
boakley commentedon Jun 27, 2019
backticks would have a little bit of symmetry with some languages, as well as with markdown:
Perhaps the rule would be "any cell that begins with a backtick will be treated as an inline keyword invocation, up until a cell that ends with a backtick`" All parsing inside the backticks wouldn't change -- you would still use two spaces between cells.
sebastianciupinski commentedon Jun 27, 2019
36 remaining items
Nagesh389 commentedon Jul 29, 2022
Hi Team,
Im trying to Pass a keyword result as an argument to another keyword in the same line in Robot framework and getting error like Keyword expected 1 argument, got 2. Tried many ways as mentioned above but still getting the same issue.
Can you help on this.
Regards,
Nagesh K
JFoederer commentedon Jul 29, 2022
Hi @Nagesh389 ,
The syntax mentioned in this issue, is not currently available in any Robot framework release yet. It is planned for a future release.
Snooz82 commentedon Sep 26, 2022
@pekkaklarck i know that Lisp has a different approach. but i doubt that this approach would be a good one for our community.
We have in my opinion started a path that now should be followed.
${scalar}, @{unpacke_list}, &{unpacked_dict} is a concept that is known by more advanced users.
Beginners already struggle with that.
Now introducing a totally new concept like lisp does, would just make it more complex and complicated to use.
Square brackets [ ] is really not an unpacked list, but a closed one
So using [ keyword] as unpacking the results does feel really strange to me.
Snooz82 commentedon Sep 26, 2022
I still think that this would be the most readable and understandable syntax:
Log $((keyword | arg1 | arg2))JFoederer commentedon Oct 23, 2022
For the people who want to gain some experience in using inline keywords, before we decide on the final syntax. With this robotnl library you can now add inline keyword support to your libraries. Compared to the full version as discussed in this issue, there are two limitations. Evaluation is at runtime and inline keywords are limited to a single cell, occupying only the argument's position. But even with these limitations, for me, it works in most situations where I have the need for inline keywords. Feel free to give it a try.
mkorpela commentedon Oct 24, 2022
@JFoederer I like what you have there :)
There are (at least) 2 really nice ideas:
Both are on their own sides solving the problem of verbosity in RF.
stylpe commentedon Mar 14, 2023
I have a proposal that I think is a reasonable balance between all the different constraints that have been discussed:
!{Keyword}and possibly!{Keyword | arg}.!was chosen to be somewhat intuitive and representative of its executive effect. It should also be largely backwards compatible; it doesn't seem likely to me that this character sequence would be used in tests already, and the risk can be mitigated with a command line feature flag. And it could of course be changed to any other symbol the maintainers would prefer.@and&to also unpack the return values, e.g.@!{Returns list}and&!{Returns dict}.!{Keyword}, and make the!{Keyword | arg}feature a separate milestone, to keep the scope and effort manageable and shippable.Keyword 1 !{Keyword 2}would be logged similarly to if you had written${temp}= Keyword 2 \n Keyword 1 ${temp}I also have some general thoughts to share, independent from that proposal: Like @HelioGuilherme66 and others have said, the most important need to meet here is that of simplification. It's ok to have some limitations for inline keywords regardless of syntax particulars, similar to what for example the setup and teardown keywords already have and with the same recommendations of making dedicated keywords if you need more complicated expressions, though potentially with the added escape hatch of using pipes to supply arguments. The number one use case for this is going to be to slap in a quick short utility keyword without If you feel you need something more complex like nested keywords, you should instead try to keep readability in mind and either use intermediate variables as before, or make helper keywords, or better yet drop down to Python code, because that's where this belongs.
Hope that helps! I'm hoping some version of this makes it into a release eventually 👍
pekkaklarck commentedon Aug 25, 2023
This is too big for RF 7 especially when we haven't yet agreed on the design.
sebastianciupinski commentedon Dec 5, 2024
@stylpe
except similar approach has been proposed already: #3187 (comment)