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

How to I go from an AST tree to a file? #33

Open
machard opened this issue Aug 18, 2022 · 4 comments
Open

How to I go from an AST tree to a file? #33

machard opened this issue Aug 18, 2022 · 4 comments

Comments

@machard
Copy link

machard commented Aug 18, 2022

Hi,
Let's say I use https://github.com/crytic/amarna/blob/main/amarna/grammars/cairo.lark and https://github.com/lark-parser/Lark.js to get the AST tree of a cairo file. What do I use after to generate a cairo file from the AST ?
Thank you

@machard
Copy link
Author

machard commented Aug 18, 2022

Unless I did not understand properly, I want to do the other side : write the cairo file after I played with the AST

@erezsh
Copy link
Member

erezsh commented Aug 18, 2022

(Yes, sorry, I misunderstood your question at first)

There is no direct way to do that. You'll have to write a transformer that generates a cairo file from an AST.

You can use the line/column information to restore the same whitespace, and it's also possible to collect the ignore tokens into an array, using lexer_callbacks.

@machard
Copy link
Author

machard commented Aug 18, 2022

thank you.
I am a bit new to this, it's called a generator or serializer ?
I think https://babeljs.io/docs/en/babel-generator is turning js ast to js code, do you have maybe other example of such tool ?

@erezsh
Copy link
Member

erezsh commented Aug 18, 2022

You can call it a code generator. I don't think serializer is the same thing.

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

No branches or pull requests

2 participants