Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle if and unless modifiers correctly #204

Closed
Tracked by #36
amomchilov opened this issue Aug 21, 2024 · 1 comment · Fixed by #301
Closed
Tracked by #36

Handle if and unless modifiers correctly #204

amomchilov opened this issue Aug 21, 2024 · 1 comment · Fixed by #301
Assignees
Labels
bug Something isn't working

Comments

@amomchilov
Copy link

amomchilov commented Aug 21, 2024

The current implementation from #31 and #203 will always produce parser::If nodes.

If if or unless are used as modifiers (example below), they should lower to parser::IfGuard and parser::UnlessGuard instead.

if p # `parser::If`
  "if body"
else
  "else body"
end

unless p # `parser::If`, with the blocks swapped
  "unless body"
else
  "else body"
end

"value" if p     # Should be `parser::IfGuard`,     but is `parser::If` today.
"value" unless p # Should be `parser::UnlessGuard`, but is `parser::If` today.
@amomchilov amomchilov added the bug Something isn't working label Aug 21, 2024
@amomchilov amomchilov changed the title Handle if and unless modifiers correctly. Handle if and unless modifiers correctly Aug 21, 2024
@st0012 st0012 self-assigned this Oct 24, 2024
@st0012
Copy link
Member

st0012 commented Oct 24, 2024

I'm not sure what changed, but I think IfGuard is only used in pattern matching now.

This script

if condition; end

"value" if condition

generates

Begin {
  stmts = [
    If {
      condition = Send {
        receiver = NULL
        method = <U condition>
        args = [
        ]
      }
      then_ = NULL
      else_ = NULL
    }
    If {
      condition = Send {
        receiver = NULL
        method = <U condition>
        args = [
        ]
      }
      then_ = String {
        val = <U value>
      }
      else_ = NULL
    }
  ]
}

Only If nodes are used.

I think currently only conditions in pattern matching cases generate IfGuard.

Like

case bar
in x if x == 1
  "one!"
end

generates

    CaseMatch {
      expr = Send {
        receiver = NULL
        method = <U bar>
        args = [
        ]
      }
      inBodies = [
        InPattern {
          pattern = MatchVar {
            name = <U x>
          }
          guard = IfGuard {
            condition = Send {
              receiver = LVar {
                name = <U x>
              }
              method = <U ==>
              args = [
                Integer {
                  val = "1"
                }
              ]
            }
          }
          body = String {
            val = <U one!>
          }
        }
      ]
      elseBody = NULL
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants