Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lue-bird/elm-syntax-format
pretty print elm-syntax like elm-format
https://github.com/lue-bird/elm-syntax-format
ast elm elm-format elm-syntax pretty-print
Last synced: about 1 month ago
JSON representation
pretty print elm-syntax like elm-format
- Host: GitHub
- URL: https://github.com/lue-bird/elm-syntax-format
- Owner: lue-bird
- License: mit
- Created: 2024-09-11T21:52:45.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2024-11-19T23:55:23.000Z (about 1 month ago)
- Last Synced: 2024-11-20T00:29:15.375Z (about 1 month ago)
- Topics: ast, elm, elm-format, elm-syntax, pretty-print
- Language: Elm
- Homepage: https://dark.elm.dmy.fr/packages/lue-bird/elm-syntax-format/latest/
- Size: 1.94 MB
- Stars: 6
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: changes.md
- License: LICENSE
Awesome Lists containing this project
README
Pretty print an [`elm-syntax`](https://dark.elm.dmy.fr/packages/stil4m/elm-syntax/latest/) tree as [`elm-format`](https://github.com/avh4/elm-format) would
(breaking lines and inserting comments in the right places).```elm
import ElmSyntaxPrint
import ElmSyntaxParserLenient"""
module Sample exposing(...)
plus2 (n)= {- this adds 2-} n
+
2
"""
|> ElmSyntaxParserLenient.run ElmSyntaxParserLenient.module_
|> Maybe.map
(\syntaxModule ->
syntaxModule
|> ElmSyntaxPrint.module_
|> ElmSyntaxPrint.toString
)
-->
Just """module Sample exposing (..)plus2 n =
{- this adds 2 -}
n
+ 2
"""
```To try it out, you can
run [this node script](https://github.com/lue-bird/elm-syntax-format/tree/main/node-elm-syntax-format).If you want to _generate_ code, better bets are [`mdgriffith/elm-codegen`](https://dark.elm.dmy.fr/packages/mdgriffith/elm-codegen/latest/) or [`the-sett/elm-syntax-dsl`](https://dark.elm.dmy.fr/packages/the-sett/elm-syntax-dsl/latest/).
## known deviations in printing
- ranges of `of`, `exposing` and `as` are needed to determine whether they should be on the next line or at the end of last line
- ranges of `=`, `:`, `,`, `|`, `->`, pattern `::`, the operators and the keywords are needed to determine whether comments are before or after
- function types outputting a parenthesized function do not preserve the parens because type parens are not stored in the syntax tree
- comments before/after parenthesized types will get eaten because type parens are not stored in the syntax tree
- some floats in exponent representation are formatted to without it and the other way around
- handling int (and float?) overflow (elm-format itself seems to have issues here, too https://github.com/avh4/elm-format/issues/635)
- formatting documentation markdownPlease [report](https://github.com/lue-bird/elm-syntax-format/issues/new) others you notice <3
## performance problems?
Please [open an issue](https://github.com/lue-bird/elm-syntax-format/issues/new).