Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/elm-in-elm/compiler
Elm compiler written in Elm
https://github.com/elm-in-elm/compiler
compiler elm-lang language
Last synced: 7 days ago
JSON representation
Elm compiler written in Elm
- Host: GitHub
- URL: https://github.com/elm-in-elm/compiler
- Owner: elm-in-elm
- License: bsd-3-clause
- Created: 2019-01-09T18:15:46.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2024-01-31T17:26:29.000Z (9 months ago)
- Last Synced: 2024-05-18T20:47:26.740Z (6 months ago)
- Topics: compiler, elm-lang, language
- Language: Elm
- Homepage: https://elm-in-elm.github.io/compiler/
- Size: 17.4 MB
- Stars: 389
- Watchers: 19
- Forks: 27
- Open Issues: 19
-
Metadata Files:
- Readme: README-library.md
- License: LICENSE
Awesome Lists containing this project
- awesome-list - compiler - in-elm | 327 | (Elm)
README
# elm-in-elm
Elm compiler written in Elm!
_For more information on the `elm-in-elm` project in general read the [comprehensive documentation](http://github.com/elm-in-elm/compiler/tree/master/README.md)._
The entrypoint of this library is the [`Elm.Compiler`](/packages/elm-in-elm/compiler/latest/Elm-Compiler) module.
The typical flow of functions inside this library looks like this:
![Stages of the compiler](https://github.com/elm-in-elm/compiler/raw/master/assets/stages.png)
## Example usage - Elm to Elixir
An example of how the core of Elm to Elixir compiler might look; pay attention to the pipeline inside `elmToElixir`:
```elm
module ElmToElixir exposing (elmToElixir)import Elm.AST.Typed as Typed
import Elm.AST.Typed.Unwrapped as TypedU
import Elm.Compiler
import Elm.Compiler.Error exposing (Error)
import Elm.Data.FileContents exposing (FileContents)
import Elm.Data.FilePath exposing (FilePath)
import Elm.Data.Module as Module exposing (Module){-| Usage:
elmToElixir
{ filePath = "src/Foo.elm"
, sourceCode =
"""
module Foo exposing (foo)foo : Int -> String
foo x =
String.repeat x "FOO! "
"""
}
-}
elmToElixir : { filePath : FilePath, sourceCode : FileContents} -> Result Error String
elmToElixir file =
file
|> Elm.Compiler.parseModule
|> Result.andThen Elm.Compiler.desugarOnlyModule
|> Result.andThen Elm.Compiler.inferModule
|> Result.map Elm.Compiler.optimizeModule
|> Result.map (Module.map Typed.unwrap)
|> Result.map emitElixirModule{-| The important part: emit Elixir source code! -}
emitElixirModule : Module TypedU.Expr -> FileContents
emitElixirModule m =
[ emitHeader m.name m.exposing_
, emitImports m.imports
, emitDeclarations m.declarations
]
|> String.join "\n\n\n"emitHeader = Debug.todo "emitHeader"
emitImports = Debug.todo "emitImports"
emitDeclarations = Debug.todo "emitDeclarations"
```