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