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

In REPL, evaluates only when parens are closed #402

Merged
merged 4 commits into from
Jul 31, 2024
Merged

Conversation

yihozhang
Copy link
Collaborator

Currently, the REPL mode evaluates programs line by line, which means egglog < main.egg almost certainly won't work because most expressions are multi-lines. Moreover, simply concatenating all lines in the source file (e.g., tr -d "\n" < main.egg | egglog) also does not work if the source file contains comments.

This PR fixes this by only evaluating a multi-line block when all the parentheses are closed. So that the program

(extract "1
2
3 
)
"
) (extract
";;;""))"
)

will only call parse_and_run_program once once at the end of the program

@yihozhang yihozhang requested a review from a team as a code owner July 30, 2024 08:55
@yihozhang yihozhang requested review from saulshanabrook and mwillsey and removed request for a team July 30, 2024 08:55
@yihozhang yihozhang changed the title Evaluates only when parens are closed In REPL, evaluates only when parens are closed Jul 30, 2024
Copy link
Member

@saulshanabrook saulshanabrook left a comment

Choose a reason for hiding this comment

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

If it isn't too much work, might be nice to add a test or two for this?

src/main.rs Outdated Show resolved Hide resolved
@yihozhang
Copy link
Collaborator Author

I added a small test

@yihozhang yihozhang merged commit e0fd116 into main Jul 31, 2024
6 checks passed
@saulshanabrook saulshanabrook deleted the yihozhang-fix-repl branch August 1, 2024 01:07
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