Skip to content

Allow creating for loop using FOR (case-sensitive) in addition to :FOR (case-insensitive) #2990

Closed

Description

@pekkaklarck

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.

Activity

  1. added this to the v3.1 milestone on Oct 16, 2018
  2. pekkaklarck commented on Oct 16, 2018

    @pekkaklarck
    MemberAuthor

    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.

  3. pekkaklarck commented on Oct 16, 2018

    @pekkaklarck
    MemberAuthor

    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.

  4. pekkaklarck commented on Nov 21, 2018

    @pekkaklarck
    MemberAuthor

    Other for loop related enhancements:

  5. boakley commented on Nov 21, 2018

    @boakley

    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
    
  6. pekkaklarck commented on Nov 21, 2018

    @pekkaklarck
    MemberAuthor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions