Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/stil4m/elm-syntax
Elm syntax in Elm
https://github.com/stil4m/elm-syntax
Last synced: about 2 months ago
JSON representation
Elm syntax in Elm
- Host: GitHub
- URL: https://github.com/stil4m/elm-syntax
- Owner: stil4m
- License: mit
- Created: 2017-05-08T19:47:19.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2024-08-04T09:48:29.000Z (2 months ago)
- Last Synced: 2024-08-04T19:13:26.380Z (about 2 months ago)
- Language: Elm
- Size: 2.64 MB
- Stars: 92
- Watchers: 8
- Forks: 28
- Open Issues: 57
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# elm-syntax
Elm Syntax in Elm: for parsing and writing Elm in Elm.
## How does this work?
When Elm code is parsed, it's converted into an Abstract Syntax Tree (AST).
The AST lets us represent the code in a way that's much easier to work with when programming.Here's an example of that:
Code: `3 + 4 * 2`
AST:
```elm
OperatorApplication
(Integer 3)
"+"
(OperatorApplication
(Integer 4)
"*"
(Integer 2)
)
```Notice how it forms a tree structure where we first multiply together 4 and 2, and then add the result with 3.
That's where the "tree" part of AST comes from.## Getting Started
```elm
import Elm.Parser
import Html exposing (Html)src : String
src =
"""module Foo exposing (foo)foo = 1
"""parse : String -> String
parse input =
case Elm.Parser.parseToFile input of
Err e ->
"Failed: " ++ Debug.toString eOk v ->
"Success: " ++ Debug.toString vmain : Html msg
main =
Html.text (parse src)
```Used in:
* [`elm-review`](https://elm-review.com/)
* [`elm-codegen`](https://package.elm-lang.org/packages/mdgriffith/elm-codegen/latest/)
* [`elm-analyse`](https://github.com/stil4m/elm-analyse)
* [`elm-xref`](https://github.com/zwilias/elm-xref)
* [`elm-lens`](https://github.com/mbuscemi/elm-lens)