forked from typedefs/try-typedefs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
87 lines (73 loc) · 2.92 KB
/
main.js
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
var exampleTerms =
[ "(name MyVoid 0)"
, "(name MyUnit 1)"
, "(name MyVar (var 0))"
, "name MySum (+ 1 0))"
, "name MyProduct (* 1 1))"
, "(mu Nat (Zero 1) (Succ (var 0)))" // TODO errr is nat ok like this?
, "(mu List (Nil 1) (Cons (* (var 1) (var 0))))"
, "(mu ListNat (NilN 1) (ConsN (* (mu Nat (Z 1) (S (var 0))) (var 0))))" // now if you wanted to generate `data ListNat = NilN | ConsN Nat Nat ListNat` you'll have to copypaste the `nat` mu part
, "(name Maybe (+ 1 (var 0)))"
, "(mu Maybe (Nil 1) (Just (var 1)))"
];
// not used atm
function getSourceTextFromUrlBar () {
var text1 = location.search;
console.log('getIt: text1 =', text1)
// console.log('getIt: text1 =', R.dropWhile(x => x != '=', text1))
// console.log('getIt: text1 =', R.split('=', text1))
var text2 = R.split('=', text1)[1] // TODO [1] is a brittle way of extracting the value for the key 'input-tdef'
console.log('getIt: text2 =', text2)
var text3 = decodeURI(text2)
console.log('getIt: text3 =', text3)
// console.log('getIt: unescape(text2) =', unescape(text2))
// console.log('getIt: decodeURIComponent(text2) =', decodeURIComponent(text2))
var text4 = text2.replace(/[+]/g, ' ')
console.log('getIt: text4 =', text4)
var text5 = decodeURI(text4)
console.log('getIt: text5 =', text5)
var text6 = unescape(text5)
console.log('getIt: text6 =', text6)
return text6
}
function getSourceTextFromInput () {
var inputElem = document.getElementById('input-tdef2')
var text = inputElem.innerHTML
return text
}
// currently, this is invoked BY the main function in the Idris JS code!
function getSource () {
var text = getSourceTextFromInput()
console.log('getSource: text =', text)
return text
}
function setSource (text) {
document.getElementById("input-tdef").innerHTML = text;
document.getElementById("input-tdef2").innerHTML = text;
}
// currently, this is invoked BY the main function in the Idris JS code!
function setResult (text, text2) {
console.log('setResult: text =', text)
document.getElementById("output-haskell").innerHTML = text;
}
function copyExample (exampleSourceCode) {
console.log('copyExample: exampleSourceCode =', exampleSourceCode)
setSource(exampleSourceCode);
}
function main () {
var text = getSourceTextFromInput()
console.log('main: text =', text)
setSource(text);
var mkEx = ex => '<a class="navbar-item" href="#"><code onclick="copyExample(this.innerHTML)">' + ex + '</code></a>'
var exampleMenuItems = R.compose(R.join('\n'), R.map(mkEx))(exampleTerms)
document.getElementById('js-navbar-examples-dropdown').innerHTML = exampleMenuItems
var inputElem = document.getElementById('input-tdef2')
inputElem.focus()
var butCompile = document.getElementById('compile2')
function onClickButCompile (e) {
var text = getSourceTextFromInput()
console.log('butCompile clicked: text:', text)
window.idris_main()
}
butCompile.addEventListener('click', onClickButCompile)
}