-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.hs
62 lines (57 loc) · 3.12 KB
/
Main.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecursiveDo #-}
{-# LANGUAGE TemplateHaskell #-}
import Reflex.Dom
import qualified Data.Text as T
import Data.FileEmbed
import Data.Text.Encoding
import Data.Monoid ((<>))
import Control.Applicative
import InputStuff
--sample file
examples = decodeUtf8 $(embedFile "docs/exampleTerms")
--css file
css = $(embedFile "docs/css.css")
main :: IO()
main = mainWidgetWithCss css $ do
el "title" $ text "System T"
elClass "h1" "mainTitle" $ text "System T Interpreter"
el "div" $ do
rec stuff <- foldDyn (\t _ -> fullUpdate t) (reservedTerms , []) update
let myLib = fmap fst stuff
let myMsgs = fmap (T.unlines . snd) stuff
update <- el "div" $ do
u2 <- el "left" $ do
code <- textArea $ def & textAreaConfig_initialValue .~ examples
& attributes .~ constDyn ( "rows" =: "45" <> "style" =: "resize:none;width:80%")
el "br" $ return ()
load <- button "Load"
el "br" $ return ()
msgs <- textArea $ def & attributes .~ constDyn ( "readonly" =: "readonly" <> "rows" =: "10" <> "style" =: "resize:none;width:80%" )
& setValue .~ (updated myMsgs)
return (fmap getLines $ tag (current (value code)) load)
return u2
el "right" $ do
rec el "p" $ do
text "For an overview of the syntax look "
elAttr "a" ("target" =: "_blank" <> "href" =: "https://github.com/emarzion/SystemT/blob/master/README.md") $ text "here."
el "br" $ return ()
el "ul" $ do
el "li" $ text "To evaluate an expression, just type in that expression."
el "li" $ text "To get the type of an expression, type 'type' before the expression."
el "li" $ text "To print an expression (without definitions and without evaluating), type 'print' before the expression."
text "Keep in mind that neither System T nor this interpreter was written with efficient arithmetical computation in mind, so don't be surprised if it hangs up on even medium-sized numbers."
return ()
el "br" $ return ()
text "Input:"
el "br" $ return ()
textIn <- textInput $ def & attributes .~ constDyn ( "style" =: "width:80%" )
el "br" $ return ()
command <- button "Evaluate command"
el "p" $ return ()
text "Output:"
el "br" $ return ()
textOut <- textArea $ def & attributes .~ constDyn ( "rows" =: "5" <> "style" =: "resize:none;width:80%" <> "readonly" =: "readonly" )
& setValue .~ attachPromptlyDynWith evalCommand myLib (tag (current (fmap T.strip (value textIn))) command)
return ()
return ()