You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Allow creating for loop using FOR (case-sensitive) in addition to :FOR (case-insensitive) #2990
Currently for loops in Robot data are created using syntax :FOR where at least one colon is mandatory but FOR is case-insensitive. The idea behind the leading colon is making it explicit this is a control structure and not a keyword. I consider it somewhat ugly, though, and wouldn't like to use it if we add more control structures in the future.
An alternative way to make for loops stand out would be using FOR so that it must be all uppercase, and the same approach would work nicely with IF/ELSE and other possible control structures. Let's change the syntax in RF 3.1 so that FOR (case-sensitive) works like :FOR (case-insensitive). We may the in the future consider deprecating the :FOR variant.
This issue is a spin-off of #2783 which listed also other possible enhancements to for loops.
There's a very small possibility that this change causes backwards incompatibility problems:
If someone has a keyword For and uses it likes FOR, it will be recognized as a for loop. That's unlikely because For is a reserved keyword, and the problem could also be avoided by not using the keyword in all uppercase.
If a test with a template has set of data where the first item has an exact value FOR, it will be recognized as a for loop. This actually happened in Robot's own tests, but the problem is easily handled by escaping the item like \FOR.
We are not planning to deprecate anything in RF 3.1, but most likely the :FOR variant is eventually deprecated. Better to mention that in the release notes already now.
I would hate to see :FOR deprecated. That could break a lot of tests around the world.
Instead, I like the idea that a leading colon specifically designates the keyword as a compound keyword. The parser could look at the first character for ":" rather than the first three for "FOR". That would allow developers to create their own compound keywords.
For example, it would make it possible to run a local keyword if a keyword fails during a small block of code:
:WITH reset device on failure
do something
do something else
do something that might fail
END
It's true that changing :FOR to FOR requires changes in the test data and is in the end backwards incompatible change (so far we haven't even deprecated the :FOR syntax). We don't, however, want to require the colon if/when we add IF/ELSE and TRY/EXCEPT functionality in the future. If changing :FOR turns out to be too big a problem, we can pretty easily keep supporting it in addition to FOR. Other changes to the for loop syntax, mainly requiring END and omitting escaping with \, will require changes to the data as well, though, so keeping this old syntax around may not be that useful in practice.
The compound keyword idea could be nice, but I don't think it requires preserving the colon in our control structures. We could, for example, make it so that these new compound keywords must always start with a colon. That would nicely separate them for the build-in control structures.
Activity
pekkaklarck commentedon Oct 16, 2018
There's a very small possibility that this change causes backwards incompatibility problems:
If someone has a keyword
Forand uses it likesFOR, it will be recognized as a for loop. That's unlikely becauseForis a reserved keyword, and the problem could also be avoided by not using the keyword in all uppercase.If a test with a template has set of data where the first item has an exact value
FOR, it will be recognized as a for loop. This actually happened in Robot's own tests, but the problem is easily handled by escaping the item like\FOR.pekkaklarck commentedon Oct 16, 2018
We are not planning to deprecate anything in RF 3.1, but most likely the
:FORvariant is eventually deprecated. Better to mention that in the release notes already now.Oooops, missing from earlier commit.
pekkaklarck commentedon Nov 21, 2018
Other for loop related enhancements:
IN,IN RANGE,IN ZIPandIN ENUMERATEwill become case- and space-sensitive (Deprecate using for loops with other separators than exactIN,IN RANGE,IN ZIPandIN ENUMERATE#2991).ENDand escaping with\won't be needed (End for loops withENDand avoid escaping keywords inside loops #3009).boakley commentedon Nov 21, 2018
I would hate to see :FOR deprecated. That could break a lot of tests around the world.
Instead, I like the idea that a leading colon specifically designates the keyword as a compound keyword. The parser could look at the first character for ":" rather than the first three for "FOR". That would allow developers to create their own compound keywords.
For example, it would make it possible to run a local keyword if a keyword fails during a small block of code:
pekkaklarck commentedon Nov 21, 2018
It's true that changing
:FORtoFORrequires changes in the test data and is in the end backwards incompatible change (so far we haven't even deprecated the:FORsyntax). We don't, however, want to require the colon if/when we addIF/ELSEandTRY/EXCEPTfunctionality in the future. If changing:FORturns out to be too big a problem, we can pretty easily keep supporting it in addition toFOR. Other changes to the for loop syntax, mainly requiringENDand omitting escaping with\, will require changes to the data as well, though, so keeping this old syntax around may not be that useful in practice.The compound keyword idea could be nice, but I don't think it requires preserving the colon in our control structures. We could, for example, make it so that these new compound keywords must always start with a colon. That would nicely separate them for the build-in control structures.