Skip to content

Conversation

@antonmedv
Copy link
Member

No description provided.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds support for else if chaining in conditional expressions, allowing multiple conditional branches without deep nesting. The implementation leverages recursive parsing to handle arbitrary chains of else if statements.

Key changes:

  • Modified the parser to recognize and handle else if syntax by recursively calling parseConditionalIf() when "if" follows "else"
  • Added test cases covering basic else if functionality, error handling, end-to-end execution, and AST printing

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
parser/parser.go Added conditional logic to check for "if" token after "else" and recursively parse nested conditionals
parser/parser_test.go Added test case for basic else if parsing and error test for malformed else followed by identifier
expr_test.go Added end-to-end test verifying correct evaluation of else if expressions
ast/print_test.go Added test verifying else if expressions print as nested ternary operators with proper parenthesization

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +662 to +671
{
"if a { 1 } else if b { 2 } else { 3 }",
&ConditionalNode{
Cond: &IdentifierNode{Value: "a"},
Exp1: &IntegerNode{Value: 1},
Exp2: &ConditionalNode{
Cond: &IdentifierNode{Value: "b"},
Exp1: &IntegerNode{Value: 2},
Exp2: &IntegerNode{Value: 3}}},
},
Copy link

Copilot AI Dec 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a test case for multiple chained else if statements to verify that the recursive implementation correctly handles chains longer than two conditionals. For example: if a { 1 } else if b { 2 } else if c { 3 } else { 4 } would test that the parser can handle arbitrarily long chains of conditionals.

Copilot uses AI. Check for mistakes.
Comment on lines +1393 to +1396
{
`if 1 == 2 { "no" } else if 1 == 1 { "yes" } else { "maybe" }`,
"yes",
},
Copy link

Copilot AI Dec 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a test case with multiple chained else if statements to ensure the feature works correctly for longer chains. For example: if 1 == 2 { "a" } else if 2 == 3 { "b" } else if 3 == 3 { "c" } else { "d" } with expected result "c".

Copilot uses AI. Check for mistakes.
@antonmedv antonmedv merged commit eb73788 into master Dec 14, 2025
18 of 20 checks passed
@antonmedv antonmedv deleted the add-else-if branch December 14, 2025 19:37
@antonmedv antonmedv mentioned this pull request Dec 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants