Add a (debug) interactive demo
This commit is contained in:
parent
800c96dc7b
commit
efe0efbee7
@ -26,7 +26,8 @@ variable = Parser.variable
|
||||
term : Parser (Term Metavariable)
|
||||
term = Parser.lazy (\() -> Parser.oneOf
|
||||
[ Parser.succeed IntLit |= intLit
|
||||
, Parser.succeed Call
|
||||
, Parser.backtrackable <|
|
||||
Parser.succeed Call
|
||||
|= name
|
||||
|= Parser.sequence
|
||||
{ start = "("
|
||||
@ -36,6 +37,8 @@ term = Parser.lazy (\() -> Parser.oneOf
|
||||
, item = term
|
||||
, trailing = Forbidden
|
||||
}
|
||||
, Parser.succeed (\n -> Call n [])
|
||||
|= name
|
||||
, Parser.succeed Var |= variable
|
||||
])
|
||||
|
||||
@ -70,3 +73,9 @@ program =
|
||||
, trailing = Mandatory
|
||||
}
|
||||
|. Parser.end
|
||||
|
||||
run : Parser a -> String -> Maybe a
|
||||
run prs s =
|
||||
case Parser.run prs s of
|
||||
Ok a -> Just a
|
||||
Err _ -> Nothing
|
||||
|
15
src/Main.elm
15
src/Main.elm
@ -2,6 +2,7 @@ module Main exposing (main)
|
||||
|
||||
import Browser
|
||||
import Html exposing (Html)
|
||||
import Html.Events exposing (onInput)
|
||||
import Bergamot.Syntax exposing (..)
|
||||
import Bergamot.Search exposing (..)
|
||||
import Bergamot.Rules exposing (..)
|
||||
@ -10,20 +11,24 @@ import Maybe
|
||||
import Tuple
|
||||
import Debug
|
||||
|
||||
type alias Model = {}
|
||||
type alias Model = { program : String }
|
||||
type alias Flags = ()
|
||||
type alias Msg = ()
|
||||
type Msg
|
||||
= SetProgram String
|
||||
|
||||
init : Flags -> (Model, Cmd Msg)
|
||||
init () = ({}, Cmd.none)
|
||||
init () = ({ program = "" }, Cmd.none)
|
||||
|
||||
view : Model -> Html Msg
|
||||
view _ = Html.div [] []
|
||||
view m = Html.div []
|
||||
[ Html.textarea [ onInput SetProgram ] []
|
||||
, Html.p [] [ Html.text (Debug.toString (run program m.program)) ]
|
||||
]
|
||||
|
||||
update : Msg -> Model -> (Model, Cmd Msg)
|
||||
update msg m =
|
||||
case msg of
|
||||
() -> (m, Cmd.none)
|
||||
SetProgram prog -> ({ m | program = prog }, Cmd.none)
|
||||
|
||||
subscriptions : Model -> Sub Msg
|
||||
subscriptions _ = Sub.none
|
||||
|
Loading…
Reference in New Issue
Block a user