From abd6a848f84eb68b326815c33f55cea38e66acd2 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Thu, 21 Dec 2023 16:57:46 -0800 Subject: [PATCH] Add support for editing the meta rules Signed-off-by: Danila Fedorin --- src/Main.elm | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Main.elm b/src/Main.elm index 764a369..f9342dd 100644 --- a/src/Main.elm +++ b/src/Main.elm @@ -18,12 +18,14 @@ import Tuple type Tab = Editor + | MetaEditor | Rendered tabEq : Tab -> Tab -> Bool tabEq t1 t2 = case (t1, t2) of (Editor, Editor) -> True + (MetaEditor, MetaEditor) -> True (Rendered, Rendered) -> True _ -> False @@ -48,6 +50,7 @@ type alias Model = type alias Flags = { renderRules: String, rules: String, query: String } type Msg = SetProgram String + | SetRenderProgram String | SetQuery String | SetTab Tab | SetEditMode EditMode @@ -59,10 +62,11 @@ viewSection : String -> Html Msg -> Html Msg viewSection name content = Html.div [ class "bergamot-section" ] [ Html.em [ class "bergamot-section-heading" ] [ Html.text name ], content ] -viewTab : Tab -> Html Msg -> Html Msg -> Html Msg -viewTab tab editor rendered = +viewTab : Tab -> Html Msg -> Html Msg -> Html Msg -> Html Msg +viewTab tab editor metaEditor rendered = case tab of Editor -> editor + MetaEditor -> metaEditor Rendered -> rendered viewSelector : (a -> a -> Bool) -> (a -> Msg) -> a -> List (a, String) -> Html Msg @@ -129,12 +133,13 @@ viewProofTree mode renderProgs progs querys = viewSection "Proof Tree" <| view : Model -> Html Msg view m = Html.div [ class "bergamot-root" ] - [ viewTabSelector m.tab [(Editor, "Rule Editor"), (Rendered, "Rendered Rules")] + [ viewTabSelector m.tab [(Editor, "Rule Editor"), (MetaEditor, "Meta Rule Editor"), (Rendered, "Rendered Rules")] , viewEditModeSelector m.editMode [(Query, "Query"), (Syntax, "Language Term")] , viewSection "Query" <| Html.input [ type_ "text", onInput SetQuery, value m.query ] [] , viewProofTree m.editMode m.renderProgram m.program m.query , viewTab m.tab (viewSection "Rules" <| Html.textarea [ onInput SetProgram ] [ Html.text m.program ]) + (viewSection "Meta Rules" <| Html.textarea [ onInput SetRenderProgram ] [ Html.text m.renderProgram ]) (Html.Lazy.lazy2 viewRules m.renderProgram m.program) ] @@ -142,6 +147,7 @@ update : Msg -> Model -> (Model, Cmd Msg) update msg m = case msg of SetProgram prog -> ({ m | program = prog }, Cmd.none) + SetRenderProgram prog -> ({ m | renderProgram = prog }, Cmd.none) SetQuery query -> ({ m | query = query }, Cmd.none) SetTab tab -> ({ m | tab = tab }, Cmd.none) SetEditMode mode -> ({ m | editMode = mode }, Cmd.none)