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

Parse and format incomplete code #822

Open
lydell opened this issue Sep 7, 2023 · 0 comments
Open

Parse and format incomplete code #822

lydell opened this issue Sep 7, 2023 · 0 comments

Comments

@lydell
Copy link
Contributor

lydell commented Sep 7, 2023

Originally from a Discord thread. @avh4’s response there:

Yeah, I'm open to PRs for that! See lenient parser for some of the other ideas that have been documented.

The main concern is to make sure that it doesn't make the parser start doing a lot of backtracking, and to make sure that the grammar remains unambiguous and that it doesn't change the parsing of any valid Elm files

I’m creating an issue for tracking.

Here’s the idea:

What if elm-format could parse and format incomplete Elm code?

  • case thing of with 0 branches
  • let in with 0 declarations
  • case branches with nothing after the ->
  • let bindings or top-level declarations with nothing after =
  • if with nothing between then and else, or nothing after else
  • and whatever else we can think of where the grammar says “there should be a <thing> after the <symbol>” but the <thing> is missing so far, or “there should be one or more <thing> in <construct>” but there are zero so far.

The idea here is that while writing out new pieces of code (where parts are left to fill in yet), you don’t lose formatting.

I have learned to put placeholders like x, ä or TODO all over the place while writing code so that “I don’t lose elm-format”. But sometimes I forget and then it feels like elm-format (on save) stopped working until I realize “oh, I must have left a syntax error behind somewhere”.

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

1 participant