git @ Cat's Eye Technologies Wagon / 1.0-2019.0924
Merge pull request #1 from catseye/develop-2019-2 Develop 2019 2 Chris Pressey authored 2 years ago GitHub committed 2 years ago
7 changed file(s) with 85 addition(s) and 27 deletion(s). Raw diff Collapse all Expand all
+0
-17
demo/index.html less more
0 <!DOCTYPE html>
1 <head>
2 <meta charset="utf-8">
3 <title>Wagon interpreter</title>
4 </head>
5 <body>
6
7 <h1>Wagon interpreter</h1>
8
9 <div id="installation">
10 <textarea id="prog" rows="10" cols="80"></textarea>
11 <div><button id="run-button">Run</button></div>
12 <pre id="result"></pre>
13 </div>
14
15 <script src="wagon.js"></script>
16 </body>
0 function launch(config) {
1 config.container.innerHTML = `
2 <textarea id="prog" rows="10" cols="80"></textarea>
3 <div id="control-panel"></div>
4 <div><button id="run-button">Run</button></div>
5 <pre id="result"></pre>
6 `;
7
8 function makeSelect(container, labelText, optionsArray, fun) {
9 var label = document.createElement('label');
10 label.innerHTML = labelText;
11 container.appendChild(label);
12 var select = document.createElement("select");
13 for (var i = 0; i < optionsArray.length; i++) {
14 var op = document.createElement("option");
15 op.text = optionsArray[i].filename;
16 op.value = optionsArray[i].contents;
17 select.options.add(op);
18 }
19 select.onchange = function(e) {
20 fun(optionsArray[select.selectedIndex]);
21 };
22 select.selectedIndex = 0;
23 label.appendChild(select);
24 return select;
25 };
26
27 function selectOptionByText(selectElem, text) {
28 var optElem;
29 for (var i = 0; optElem = selectElem.options[i]; i++) {
30 if (optElem.text === text) {
31 selectElem.selectedIndex = i;
32 selectElem.dispatchEvent(new Event('change'));
33 return;
34 }
35 }
36 }
37
38 var controlPanel = document.getElementById('control-panel');
39 var select = makeSelect(controlPanel, "example program:", examplePrograms, function(option) {
40 document.getElementById('prog').value = option.contents;
41 });
42 selectOptionByText(select, "reverse0.pail");
43 }
44
45 launch({ container: document.getElementById('installation') });
0 <!DOCTYPE html>
1 <head>
2 <meta charset="utf-8">
3 <title>Wagon interpreter</title>
4 </head>
5 <body>
6
7 <h1>Wagon interpreter</h1>
8
9 <p>(Language.Wagon compiled to .js by <code>hastec</code>, running in HTML5 document)</p>
10
11 <div id="installation"></div>
12
13 <script src="../eg/examplePrograms.jsonp.js"></script>
14 <script src="wagon-hastec-launcher.js"></script>
15 <script src="wagon.js"></script>
16 </body>
0 examplePrograms = [
1 {
2 "contents": "iis i iiisiss iis r\n",
3 "filename": "reverse0.wagon"
4 },
5 {
6 "contents": "iis i iiisiss i r\n",
7 "filename": "reverse1.wagon"
8 },
9 {
10 "contents": "p@ I I I SII SII\n",
11 "filename": "while.wagon"
12 }
13 ];
0 iis i iiisiss iis r
0 iis i iiisiss i r
00 module Main where
11
2 import Haste
3 import Haste.DOM
4 import Haste.Events
2 import Haste.DOM (withElems, getValue, setProp)
3 import Haste.Events (onEvent, MouseEvent(Click))
54
65 import qualified Language.Wagon.ConcatEval as ConcatEval
76
8
97 main = withElems ["prog", "result", "run-button"] driver
108
11 driver [progElem, resultElem, runButtonElem] = do
12 onEvent runButtonElem Click $ \_ -> execute
13 where
14 execute = do
15 Just prog <- getValue progElem
16 setProp resultElem "textContent" $ show $ ConcatEval.run prog
9 driver [progElem, resultElem, runButtonElem] =
10 onEvent runButtonElem Click $ \_ -> do
11 Just prog <- getValue progElem
12 setProp resultElem "textContent" $ show $ ConcatEval.run prog