Skip to content

Inline IF support #4093

Closed
Closed

Description

@pekkaklarck

As discussed in the comments of #4079, having support for inline IF constructs would shorten and also simplify cases where a single keyword or some other statement (e.g. planned RETURN (#4078) and CONTINUE/BREAK (#4079)) is to be executed conditionally. In the aforementioned comments, @ericbjones proposed an inline IF syntax that looks pretty good to me. For example,

IF    $condition1
    Keyword    arg
END
IF    $condition2
    BREAK
END

could be replaced with

IF    $condition1    Keyword    arg
IF    $condition2    BREAK

As I commented that original proposal, we probably should also support for IF ELSE and ELSE:

IF    $condition1    Keyword    arg    ELSE IF    $condition2    Another Keyword    ELSE    Yet another keyword

Supporting assignment could be useful as well:

${var} =    IF    condition    Keyword    arg    ELSE    Another Keyword

Although this is just syntactic sugar, I consider this pretty important especially if/when we add support for RETURN, BREAK and CONTINUE. I thus add this tentatively to RF 5.0 scope.

Activity

  1. added this to the v5.0 milestone on Sep 20, 2021
  2. pekkaklarck commented on Sep 20, 2021

    @pekkaklarck
    MemberAuthor

    The parser can detect inline IF simply by checking is there anything after the condition on the same line. That is currently an error so adding this support is backwards compatible. We shouldn't require an END at the end, instead it should be an error.

    On the parsing model (AST) inline IF may be able to use the current If node but it would need to be enhanced to support assignment. It could be that adding separate InlineIf node is cleaner.

    On the execution model we most likely can use the current If class but need to add assignment support to it.

    In the log file we probably can show inline IFs exactly like normal IFs, but need to figure out a way how to show possible assignment.

  3. added a commit that references this issue on Jan 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions