-
Notifications
You must be signed in to change notification settings - Fork 825
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
appropriate to build an ast using nom? #255
Comments
I'm going to make another attempt to write this in the next few days. I think I know what mistakes I made in the first attempt. |
Hi! Any reason you closed this issue? Did you find a way to generate an AST? I'm sorry I can't answer fast, I'm currently traveling. |
Thanks! I closed the ticket because I wasn't sure if reporting my question as an issue was the appropriate forum. In any event I've made some progress in a branch: https://github.com/mspiegel/nom/blob/arithmetic_ast/tests/arithmetic_ast.rs. The downside is that in a few instances I have to clone the entire AST which I suspect is not the right way to do it. See for example, https://github.com/mspiegel/nom/blob/arithmetic_ast/tests/arithmetic_ast.rs#L75. Whenever you have the chance any help would be 1000% appreciated. Once I get this AST calculator working I was planning on applying the same strategy to submit a pull request for ehuss/license-exprs#3 |
Yup I'm very stuck about how to rewrite my initial version without relying on clone. I think there are two problems but my knowledge of rust is very poor so there may be N problems for any value of N. One problem is that I can't assign "expr" to a new Expr value that is constructed out of the old "expr" reference. The other problem is that the Expr gets moved into the closure because it's not copyable so then I can't return "acc" on line https://github.com/mspiegel/nom/blob/arithmetic_ast/tests/arithmetic_ast.rs#L79. I've tried playing around with Expr, Box, RefCell, unsafe, I couldn't get a working solution. |
Aha wait I had an insight. Instead of trying to modifying the Expr while parsing, I should be appending some things onto a vector while consuming the input and then in the return closure I can build the final Expr using the vector. I will try that tomorrow morning. Sorry for the comment spam. |
Success!!!!!!! I'll submit a pull request. |
I was trying to adapt the arithmetic.rs example and have the parser generate an AST rather than compute the result. I am very new to rust and was getting tripped up. When I am creating new values of the AST enum I think I needed to use the try! macro but I wasn't sure how to combine that with the nom macros. Is nom a good use case for generating the ASTs?
The text was updated successfully, but these errors were encountered: