Skip to content

Parse and format incomplete code #822

@lydell

Description

@lydell

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”.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions