-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Support optional else-branch for if-then-elif-end #2598
Conversation
Not sure if seen as bug fix or feature, but can maybe wait until after current master has been released. |
src/parser.y
Outdated
@@ -619,6 +619,9 @@ ElseBody: | |||
"elif" Exp "then" Exp ElseBody { | |||
$$ = gen_cond($2, $4, $5); | |||
} | | |||
"elif" Exp "then" Exp "end" { | |||
$$ = gen_cond($2, $4, gen_noop()); | |||
} | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can probably be done in some cleverer way but this way feels straight forward
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having optional then in different places looks confusing. You can move both in ElseBody
;
Exp:
...
"if" Exp "then" Exp ElseBody {
$$ = gen_cond($2, $4, $5);
} |
"if" Exp "then" error {
FAIL(@$, "Possibly unterminated 'if' statement");
$$ = $2;
} |
...
ElseBody:
"elif" Exp "then" Exp ElseBody {
$$ = gen_cond($2, $4, $5);
} |
"else" Exp "end" {
$$ = $2;
} |
"end" {
$$ = gen_noop();
}
159a76f
to
2b33ef9
Compare
@owenthereal CI for a PR seems to work |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should maybe wait with any changes that are not absolutely needed for next release or what do ppl think? @itchyny @liquidaty |
Personally I think it would be nice to see changes incorporated in stages and/or separate releases:
|
2b33ef9
to
ddb74f3
Compare
Rebased on master. macOS build fail seems to be some homebrew temporary error |
src/parser.y
Outdated
@@ -619,6 +619,9 @@ ElseBody: | |||
"elif" Exp "then" Exp ElseBody { | |||
$$ = gen_cond($2, $4, $5); | |||
} | | |||
"elif" Exp "then" Exp "end" { | |||
$$ = gen_cond($2, $4, gen_noop()); | |||
} | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having optional then in different places looks confusing. You can move both in ElseBody
;
Exp:
...
"if" Exp "then" Exp ElseBody {
$$ = gen_cond($2, $4, $5);
} |
"if" Exp "then" error {
FAIL(@$, "Possibly unterminated 'if' statement");
$$ = $2;
} |
...
ElseBody:
"elif" Exp "then" Exp ElseBody {
$$ = gen_cond($2, $4, $5);
} |
"else" Exp "end" {
$$ = $2;
} |
"end" {
$$ = gen_noop();
}
ddb74f3
to
e9f5391
Compare
@itchyny Thanks, yes that is better |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Fixes #2481