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

Add else part for while statement #863

Merged
merged 7 commits into from Oct 28, 2019
Merged

Add else part for while statement #863

merged 7 commits into from Oct 28, 2019

Conversation

@0x005c
Copy link
Contributor

0x005c commented Oct 27, 2019

As shown in #820, while $false { echo a } else { echo b } emits error.
So, I fixed builtin_special.go to handle it, and added tests for that.
But, I did't add highlights for else part ( I don't know how to add a new highlight )

( I'm sorry I sent this PR with no comments by mistake, so I edited this comment )

@0x005c 0x005c changed the title Add else statement for while Add else part for while statement Oct 27, 2019
Copy link
Member

xiaq left a comment

Thanks!

For highlighting, you can find the logics for the "else" of "for" here:

if len(n.Args) >= 4 && n.Args[3].SourceText() == "else" {

}

func (op *whileOp) invoke(fm *Frame) error {
body := op.bodyOp.execlambdaOp(fm)
elseFn := op.elseOp.execlambdaOp(fm)
isFirstLoop := true

This comment has been minimized.

Copy link
@xiaq

xiaq Oct 27, 2019

Member

Can you use the same pattern as in the implementation of for, keeping track of whether any iteration has been executed at all, and execute the else body if no iteration has been executed?

@0x005c

This comment has been minimized.

Copy link
Contributor Author

0x005c commented Oct 28, 2019

Thank you for reviewing.
I fixed func invoke, added highlights for else part of while and test for highlights.

@xiaq xiaq merged commit 0b70b68 into elves:master Oct 28, 2019
2 checks passed
2 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@0x005c 0x005c deleted the 0x005c:add-while-else branch Oct 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.