Skip to content

elsif node incorrectly included inside IfNode#statements instead of represented as nested IfNode in consequent #3946

@tu6ge

Description

@tu6ge

Description

When parsing an if / elsif / else construct using Prism (Rust bindings),
the elsif branch appears to be included inside the parent IfNode#statements
instead of being represented as a nested IfNode in the consequent field.

This causes structural ambiguity in the AST and makes it impossible to
distinguish between:

  • a normal statement inside the if body
  • an elsif branch

From the Ruby grammar perspective, elsif should be modeled as a nested
IfNode inside the consequent of the previous IfNode.

However, what I observe is that the elsif appears inside the statements
list of the parent IfNode.


Example

Input

if a
  foo
elsif b
  bar
else
  baz
end

Expected AST Structure (Simplified)

IfNode
  predicate: a
  statements:
    - foo
  consequent:
    IfNode
      predicate: b
      statements:
        - bar
      consequent:
        Statements:
          - baz

Actual Behavior

The elsif branch appears inside the parent IfNode#statements
instead of being represented as a nested IfNode in consequent.

This makes elsif indistinguishable from a regular statement
when traversing statements.

Environment

  • Rust bindings version: ruby-prism 1.9.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions