-
Notifications
You must be signed in to change notification settings - Fork 391
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 Match #93
Comments
Could I get assigned to this issue? I would love to contribute to this repo! |
@erica-w-fu Hi, feel free to work on this! |
Could I get some clarification on what is expected? Are we trying to convert match statements to latex? What does support mean exactly? |
Basically implementing some codegen rules in As for "small development", you can start to implement only a specific portion in the whole syntax (e.g., I think supporting only MatchValue is the easiest one). class FunctionCodegen(NodeVisitor):
...
def visit_Match(self, node: ast.Match) -> str:
if isinstance(node.pattern, ast.MatchValue):
return ...something...
raise exceptions.LatexifyNotSupportedError("Unsupported match syntax.") |
I think the whole match case can't be supported in
|
The resulting LaTeX could be expressed semilarly to that of the if clause: match x:
case 0:
return 1
case _:
return math.sin(x)/x |
That makes a lot of sense! Thanks for the clarification |
How can we build the project for development? Are there any detailed docs that explain how to build and test latexify/our implementation? |
@erica-w-fu I will add some documentation. For now you can install the development version as follows:
jupyter notebook is also installed by the command above. |
Thanks! I was able to run all of the tests. Are there any build tools and commands that you use to test within jupyter notebook? |
Are there any other cases that would be relevant for latex? If you could provide examples that would be extremely helpful! |
This library doesn't run tests within jupyter. If you need to run tests on jupyter, you need either (1) run CI libraries programmatically, or (2) run shell command from the notebook. If you know some other tools to run tests on jupyter, it is still fine to use it on your local environment.
I'm not sure for now. If you have some ideas, please share on this thread. |
Here are two ideas for things to support: 1. MatchOrIn conditional equations, multiple conditions can lead to one of the cases, thus we should implement MatchOr to support this. Code example
2. MatchAs (nonempty/not the wildcard)In conditional equations, ranges are often used to define certain cases, thus we should implement when MatchAs is not empty so the guard attribute can be evaluated and comparisons through <, >, <=, >= can be made Code example
For this case, we might also want to implement a fixed range like this Code example
Would we want to combine these ranges (so instead of |
Thanks! if each case doesn't require additional identifiers (capture), it would be good to be implemented. I guess they could be proposed by separate pull requests (to keep minimality of the change).
It looks we need to use boolean operation:
The library has to keep the original expression unless users specified appropriate options. In this case, if the user wanted to get |
@odashi Hi, we cannot get the match statement in the jupyter notebook running. For now, we are getting this error: This is what we did:
Is there any step we missed? Thanks ahead! |
@Yuqi07 Not sure how you installed the library. Could you provide the complete step you tried? |
I think these were the only steps I ran. Did I miss anything? Thxx! |
pip install from PyPI doesn't work for development. You need to install the main branch directly: |
Thanks! Now it works! |
It would be great if we support the
match
statement added in Python 3.10, but the entire syntax is somewhat complex.https://docs.python.org/3/library/ast.html#pattern-matching
The text was updated successfully, but these errors were encountered: