Elm reformatting and demo HTML page.
This commit is contained in:
parent
16cc0e5769
commit
20b5f05d29
|
|
@ -0,0 +1,4 @@
|
||||||
|
|
||||||
|
./demo/Joy.js: src/*.elm
|
||||||
|
elm make --output=./demo/Joy.js src/Main.elm
|
||||||
|
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,17 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||||
|
<head>
|
||||||
|
<title>Thun Demo</title>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<script src="Joy.js"></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Thun Demo</h1>
|
||||||
|
<div id="joy_interpreter_hull">
|
||||||
|
<h3>Thun Interpreter</h3>
|
||||||
|
<p>This is an interpreter for the <a href="https://git.sr.ht/~sforman/Thun/tree/trunk/item/docs/source/Thun.md">Thun</a> dialect of the <a href="https://en.wikipedia.org/wiki/Joy_%28programming_language%29">Joy</a> language. Enter a Thun expression in the text input below and the result of evaluation will be displayed beneath it.</p>
|
||||||
|
<div id="joy_interpreter"></div>
|
||||||
|
</div>
|
||||||
|
<script>var joy_interpreter = Elm.Main.init({node: document.getElementById('joy_interpreter')});</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
@ -1,19 +1,19 @@
|
||||||
module Main exposing (..)
|
module Main exposing (..)
|
||||||
|
|
||||||
import Dict
|
|
||||||
|
|
||||||
import Browser
|
import Browser
|
||||||
import Html exposing (Html, Attribute, div, input, text)
|
import Dict
|
||||||
|
import Html exposing (Attribute, Html, div, input, text)
|
||||||
import Html.Attributes exposing (..)
|
import Html.Attributes exposing (..)
|
||||||
import Html.Events exposing (onInput)
|
import Html.Events exposing (onInput)
|
||||||
|
import Joy exposing (JoyDict, doit, initialize)
|
||||||
|
|
||||||
|
|
||||||
import Joy exposing (doit, JoyDict, initialize)
|
|
||||||
|
|
||||||
-- MAIN
|
-- MAIN
|
||||||
|
|
||||||
|
|
||||||
main =
|
main =
|
||||||
Browser.sandbox { init = init, update = update, view = view }
|
Browser.sandbox { init = init, update = update, view = view }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -21,15 +21,18 @@ main =
|
||||||
|
|
||||||
|
|
||||||
type alias Model =
|
type alias Model =
|
||||||
{ content : String
|
{ content : String
|
||||||
, evaluated : String
|
, evaluated : String
|
||||||
, dictionary : JoyDict
|
, dictionary : JoyDict
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
init : Model
|
init : Model
|
||||||
init =
|
init =
|
||||||
{ content = "", evaluated = "", dictionary = initialize Dict.empty }
|
{ content = ""
|
||||||
|
, evaluated = ""
|
||||||
|
, dictionary = initialize Dict.empty
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -37,18 +40,22 @@ init =
|
||||||
|
|
||||||
|
|
||||||
type Msg
|
type Msg
|
||||||
= Change String
|
= Change String
|
||||||
|
|
||||||
|
|
||||||
update : Msg -> Model -> Model
|
update : Msg -> Model -> Model
|
||||||
update msg model =
|
update msg model =
|
||||||
case msg of
|
case msg of
|
||||||
Change newContent ->
|
Change newContent ->
|
||||||
case doit newContent model.dictionary of
|
case doit newContent model.dictionary of
|
||||||
Err err ->
|
Err err ->
|
||||||
{ model | content = newContent, evaluated = err}
|
{ model | content = newContent, evaluated = err }
|
||||||
Ok (output, dict) ->
|
|
||||||
{ content = newContent, evaluated = output, dictionary = dict }
|
Ok ( output, dict ) ->
|
||||||
|
{ content = newContent
|
||||||
|
, evaluated = output
|
||||||
|
, dictionary = dict
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -57,8 +64,12 @@ update msg model =
|
||||||
|
|
||||||
view : Model -> Html Msg
|
view : Model -> Html Msg
|
||||||
view model =
|
view model =
|
||||||
div []
|
div [ attribute "id" "joy_interpreter" ]
|
||||||
[ input [ placeholder "Text to reverse", value model.content, onInput Change ] []
|
[ input
|
||||||
|
[ placeholder "Thun expression to evaluate"
|
||||||
|
, value model.content
|
||||||
|
, onInput Change
|
||||||
|
]
|
||||||
|
[]
|
||||||
, div [] [ text model.evaluated ]
|
, div [] [ text model.evaluated ]
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue