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

Escape newlines in graphviz output #7

Merged
merged 4 commits into from
Nov 9, 2023

Conversation

saulshanabrook
Copy link
Member

@saulshanabrook saulshanabrook commented Sep 2, 2023

This PR adds support for rendering nodes in graphviz that contain newlines (\n).

Note that the default egglog parser is not able to create strings with newlines (i.e. the string "\n" ends up with the newline escaped during parsing), but the Python bindings are able to create them.

Previously, newlines were emitted as-is in the graphviz output, as newlines in the file, which meant they were not rendered.

I tested this PR with this code:

from egglog import *

egraph = EGraph()

@egraph.function
def f() -> String: ...

egraph.register(set_(f()).to(String("Hello\nWorld!")))
egraph.display()

Which now renders like this:

Screenshot 2023-09-02 at 9 43 26 AM

But previously was like this:

Screenshot 2023-09-02 at 9 43 59 AM

EDIT: I also added a BALIGN="left" so that the lines separated by <br /> are aligned left, instead of centered, and tested this.

@saulshanabrook
Copy link
Member Author

I realized you can actually reproduce this bug in egglog itself:

(function f () String)

(set (f) "Hello
World!")

@mwillsey mwillsey merged commit 6f16222 into egraphs-good:main Nov 9, 2023
2 checks passed
@saulshanabrook saulshanabrook deleted the escape-newlines branch November 10, 2023 17:48
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