commit 81feaf4ef34af2bb014348d587bd1207e6eca3e9 Author: Jeroen Engels Date: Sat Jan 7 18:29:26 2017 +0100 Init project and copy example from bogdanp/elm-ast diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..78ddd29a --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +elm-stuff +example/elm.js diff --git a/elm-package.json b/elm-package.json new file mode 100644 index 00000000..4a59eb3d --- /dev/null +++ b/elm-package.json @@ -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" +} diff --git a/example/Main.elm b/example/Main.elm new file mode 100644 index 00000000..c98accd3 --- /dev/null +++ b/example/Main.elm @@ -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 + } diff --git a/example/elm-package.json b/example/elm-package.json new file mode 100644 index 00000000..1d34b5a1 --- /dev/null +++ b/example/elm-package.json @@ -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" +} diff --git a/example/index.html b/example/index.html new file mode 100644 index 00000000..5cea5ff8 --- /dev/null +++ b/example/index.html @@ -0,0 +1,21 @@ + + + + + + + + +