diff --git a/src/Bergamot/Parser.elm b/src/Bergamot/Parser.elm index 799304c..f653d14 100644 --- a/src/Bergamot/Parser.elm +++ b/src/Bergamot/Parser.elm @@ -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 diff --git a/src/Main.elm b/src/Main.elm index 45b7047..93bea8d 100644 --- a/src/Main.elm +++ b/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