Make the AST round-trippable
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 20/100
Research direction
No files, tests, or code entry points are named. Start by reviewing the current LFortran AST and ASR design, then compare the proposed optional nodes and formatting-preservation requirements with the Roslyn references. Done is not defined: the issue leaves the node representation, generation policy, and whether AST or ASR must reproduce source open.
Written by the indexing model from the issue text.
Description
Original issue: https://gitlab.com/lfortran/lfortran/-/issues/42
The general idea is to follow the Roslyn design:
https://github.com/dotnet/roslyn/wiki/Roslyn%20Overview
One can play with the Roslyn AST viewer here:
The problem is that it seems the Roslyn AST is not as simple as our LFortran AST. For example Roslyn has all the tokens like } and ; in the AST tree. But those are not needed for the rest of the compiler, because they do not convey any semantic information.
So we decided to first design LFortran's AST and ASR to be as simple and abstract as possible. We are pretty close with the design. It is important that the design is not influenced by this round-trip requirement, but rather by the requirement that AST and ASR is simple, because that will simplify the rest of LFortran as well as all the other tools that people will write on top.
Next step is to figure out how to add all the optional nodes like white space, ;, end if and other tokens, so that the original source code can be exactly reproduced from AST, and perhaps even from ASR (that's even more complicated than from AST, because ASR does not have any declaration nodes).
Another open question is whether these optional white space nodes should always be generated, or only when the given (refactoring) tool requires it.
One should note that we can use the current AST to do formatting, and if the source code is always formatted the way LFortran does it, then we can use LFortran to do refactorings. It's just that it would be very nice to have a tool that can refactor a code base that is not already formatted using LFortran, exactly preserving the original formatting.
- Dominant language
- C++
- Stars
- 1.2k
- Forks
- 271
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 173
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from lfortran/lfortran
-
tests
Difficulty 1/5 Under an hour Newbie friendliness 90/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
Cleanup: resolve_proc_pointer_placeholders re-resolves placeholders already in placeholder_to_real Openderived types
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
derived types
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
openmp
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
All issues in lfortran/lfortran
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
-
Sensor initialization takes very long when `--initial-sim-time` is set to current UNIX timestamp Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
gazebosim/gz-sensors#662 · 1 comment ·
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
comp-datalake
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
ClickHouse/ClickHouse#121222 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
LadybirdBrowser/ladybird#12123 ·