Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
WIP: dump asts #1041
base: master
Are you sure you want to change the base?
WIP: dump asts #1041
Changes from 23 commits
88819e3
c88a9c9
4d596d8
312eee0
6f3e7fd
765a49f
46ab52f
b6ae20c
30f7454
d7af028
2c487c5
f6fd9a7
e1227bc
2c2e5b7
eff807f
3adb001
47c4f79
1e14581
3018283
900278e
abc13c9
a37f17f
09088d6
339eb3a
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to make sure I understand the justification of introducing another representation - the intention here is to have a generic pretty printer that we can use for debugging, correct? Where
tast
is the first thing we've made a debug printer for, but we can extend it as needed.Provided the answer to the above is "yes", here's another important question:
Even if we don't use it right now, I'd like to see a PoC that it's doable before we commit to a specific pretty printing DSL.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I wanted to pattern match in
tools.ml
but wasn't sure what shape I was aiming for. So, I created a new representation and wrote a printer for it. In the future, this could be reused for the untyped tree.I believe the
loc
aspect can be captured as you described. It would be helpful to have a concrete example to ensure I fully understand what you would like to see.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure! Have a look through this file: https://github.com/rescript-lang/rescript-vscode/blob/master/analysis/src/DumpAst.ml
That prints (parts of) the parsetree, and marks structures with whether they hold the cursor or not (or if the loc is broken).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, in the tree traversal you would like to pass the cursor position and have that print something special if a node contains the cursor?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exactly, or if the loc is broken. Reason is that both of those are very important when working with things like hovers, autocomplete, etc. I don't need to see the actual locs I think, just if the cursor is in there and/or if the loc is broken. For actual locs, it's easy enough to print via
bsc
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple of questions there:
I'm not sure if I understand what a broken loc is. What does that mean?
I'm a little surprised by this. Can you elaborate on this? Or is it more a practical thing?
A while ago you told me that
bsc -dtypedtree
dumps the typed tree, however, inside a real project you need to pass in the dependencies and other flags. Is there an easy way find out what other arguments would be required? Like what isbunx rescript
eventually gonna pass down?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
%rescript.exprHole
with a "broken" loc at a place where it couldn't figure out more about what type of expression or pattern you're trying to write. These are important cues that help when doing autocomplete.bsc
would run when compiling. That's when those flags are needed. If you want to see precisely what the editor sees via the parser, this command is good enough (and it requires no knowledge of libs, PPXes etc):bsc whatever.res -dparsetree -ignore-parse-errors -only-parse -bs-no-builtin-ppx -bs-loc
. This will give you just the parsetree back, just as the parser sees it (which is what the editor operates on). No PPXes (including disabling the builtin PPXes) and-bs-loc
will give you the actual locs.