mirror of
https://github.com/jfmengels/elm-review.git
synced 2024-11-26 07:44:22 +03:00
Init project and copy example from bogdanp/elm-ast
This commit is contained in:
commit
81feaf4ef3
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
elm-stuff
|
||||
example/elm.js
|
16
elm-package.json
Normal file
16
elm-package.json
Normal file
@ -0,0 +1,16 @@
|
||||
{
|
||||
"version": "1.0.0",
|
||||
"summary": "helpful summary of your project, less than 80 characters",
|
||||
"repository": "https://github.com/user/project.git",
|
||||
"license": "BSD3",
|
||||
"source-directories": [
|
||||
"."
|
||||
],
|
||||
"exposed-modules": [],
|
||||
"dependencies": {
|
||||
"elm-lang/core": "5.0.0 <= v < 6.0.0",
|
||||
"elm-lang/html": "2.0.0 <= v < 3.0.0",
|
||||
"jfmengels/elm-ast": "1.0.1 <= v < 2.0.0"
|
||||
},
|
||||
"elm-version": "0.18.0 <= v < 0.19.0"
|
||||
}
|
95
example/Main.elm
Normal file
95
example/Main.elm
Normal file
@ -0,0 +1,95 @@
|
||||
module Main exposing (main)
|
||||
|
||||
import Ast
|
||||
import Ast.Expression exposing (..)
|
||||
import Ast.Statement exposing (..)
|
||||
import Html exposing (..)
|
||||
import Html
|
||||
import Html.Events exposing (..)
|
||||
import Json.Decode as JD
|
||||
|
||||
|
||||
type Msg
|
||||
= Replace String
|
||||
|
||||
|
||||
init : String
|
||||
init =
|
||||
"""module Main exposing (..)
|
||||
|
||||
f : Int -> Int
|
||||
f x = x + 1
|
||||
|
||||
g : Int -> Int
|
||||
g x = x * 2
|
||||
|
||||
h = f << g
|
||||
"""
|
||||
|
||||
|
||||
update : Msg -> String -> String
|
||||
update action model =
|
||||
case action of
|
||||
Replace m ->
|
||||
m
|
||||
|
||||
|
||||
withChild : a -> List (Html Msg) -> Html Msg
|
||||
withChild title children =
|
||||
li []
|
||||
[ pre [] [ text <| toString title ]
|
||||
, ul [] children
|
||||
]
|
||||
|
||||
|
||||
expression : Expression -> Html Msg
|
||||
expression e =
|
||||
case e of
|
||||
List es ->
|
||||
withChild e (List.map expression es)
|
||||
|
||||
Application e1 e2 ->
|
||||
withChild e
|
||||
[ expression e1
|
||||
, expression e2
|
||||
]
|
||||
|
||||
e ->
|
||||
li [] [ pre [] [ text <| toString e ] ]
|
||||
|
||||
|
||||
statement : Statement -> Html Msg
|
||||
statement s =
|
||||
case s of
|
||||
FunctionDeclaration _ _ e ->
|
||||
withChild s [ expression e ]
|
||||
|
||||
s ->
|
||||
li [] [ pre [] [ text <| toString s ] ]
|
||||
|
||||
|
||||
tree : String -> Html Msg
|
||||
tree m =
|
||||
case Ast.parse m of
|
||||
Ok ( _, _, statements ) ->
|
||||
ul [] (List.map statement statements)
|
||||
|
||||
err ->
|
||||
div [] [ text <| toString err ]
|
||||
|
||||
|
||||
view : String -> Html Msg
|
||||
view model =
|
||||
div []
|
||||
[ textarea [ on "input" (JD.map Replace targetValue) ] [ text model ]
|
||||
, tree model
|
||||
]
|
||||
|
||||
|
||||
main : Program Never String Msg
|
||||
main =
|
||||
Html.beginnerProgram
|
||||
{ model = init
|
||||
, update = update
|
||||
, view = view
|
||||
}
|
16
example/elm-package.json
Normal file
16
example/elm-package.json
Normal file
@ -0,0 +1,16 @@
|
||||
{
|
||||
"version": "1.0.0",
|
||||
"summary": "helpful summary of your project, less than 80 characters",
|
||||
"repository": "https://github.com/user/project.git",
|
||||
"license": "BSD3",
|
||||
"source-directories": [
|
||||
"."
|
||||
],
|
||||
"exposed-modules": [],
|
||||
"dependencies": {
|
||||
"elm-lang/core": "5.0.0 <= v < 6.0.0",
|
||||
"elm-lang/html": "2.0.0 <= v < 3.0.0",
|
||||
"jfmengels/elm-ast": "1.0.0 <= v < 2.0.0"
|
||||
},
|
||||
"elm-version": "0.18.0 <= v < 0.19.0"
|
||||
}
|
21
example/index.html
Normal file
21
example/index.html
Normal file
@ -0,0 +1,21 @@
|
||||
<html>
|
||||
<head>
|
||||
<style>
|
||||
textarea {
|
||||
font-family: monospace;
|
||||
width: 100%;
|
||||
height: 400px;
|
||||
}
|
||||
|
||||
pre {
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<script src="elm.js"></script>
|
||||
<script>
|
||||
Elm.Main.fullscreen();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user