-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
207 lines (162 loc) · 5.74 KB
/
index.html
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
<meta charset="utf-8">
<title>தென்றல் - Thendral transpiler</title>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.0/beautify.js"></script>
<script src="scripts/require.js"></script>
</head>
<style>
body {
margin: 0;
padding: 0;
}
a {
color: white;
}
.program-bar {
position: fixed;
width: 100%;
bottom: 0;
}
.navigation-bar {
display: flex;
flex-direction: row;
justify-content: space-around;
background-color: #005cf8;
padding: 5px;
position: sticky;
color: #fff;
}
body {
background-color: rgba(0, 0, 0, 0.8);
color: white;
}
.container {
display: flex;
flex-direction: row;
column-gap: 10px;
height: 70%;
align-content: center;
justify-content: center;
}
.description-container {
display: flex;
flex-direction: row;
column-gap: 10px;
align-content: center;
justify-content: center;
}
.textarea {
height: 100%;
flex-grow: 0.4;
background-color: rgba(0, 0, 0, 0.7);
color: white;
font-size: 20px;
}
.description {
flex-grow: 0.4;
}
.program-bar {
padding: 20px;
background-color: #005cf8;
display: flex;
flex-direction: row;
column-gap: 10px;
row-gap: 10px;
justify-content: center;
align-items: center;
flex-wrap: wrap;
}
.program {
border: 1px solid white;
border-radius: 10px;
cursor: pointer;
padding: 10px;
}
.second-column {
font-size: 20px;
}
</style>
<body>
<div class="navigation-bar">
<h1>தென்றல் - javascript transpiler</h1>
<div class="second-column">
<p>version: 0.0.1</p>
<p>நிரலர்: <a href="https://github.com/naveen17797" target="_blank">நவீன்</a></p>
<p><a href="https://github.com/agaram-programming-language/thendral" target="_blank">Get source code</a></p>
<p>Email: kmnaveen101@gmail.com</p>
</div>
</div>
<div class="description-container">
<p class="description">Thendral</p>
<p class="description">Translated JS Code</p>
<p class="description">Output</p>
</div>
<div class="container">
<textarea class="textarea" id="thendral-code"></textarea>
<textarea class="textarea" id="translated-code" readonly></textarea>
<textarea class="textarea" id="output" readonly></textarea>
</div>
<div class="program-bar">
<div class="program" data-program-id="hello-world">Hello World</div>
<div class="program" data-program-id="variable-declaration">Variable declaration</div>
<div class="program" data-program-id="if-loop">If loop</div>
<div class="program" data-program-id="while-loop">While loop</div>
<div class="program" data-program-id="function-declaration">Function Declaration</div>
<div class="program" data-program-id="sum-of-two-numbers">Sum of two numbers</div>
<div class="program" data-program-id="print-even-numbers">Print even numbers</div>
</div>
</body>
<script>
var outputBuffer = ""
function translate() {
outputBuffer = ""
const thendralCode = document.getElementById("thendral-code").value
const jsCode = js_beautify(window.thendral(thendralCode).code);
document.getElementById("translated-code")
.value = jsCode
try {
const output = eval(jsCode);
document.getElementById("output")
.value = output
}
catch (e) {
document.getElementById("output")
.value = e.message
}
}
function thendralPrint(value) {
outputBuffer = outputBuffer + "\n" + value
return outputBuffer
}
window.addEventListener("load", () => {
require(["Transpiler"], (Transpiler) => {
window.thendral = Transpiler.thendral
})
document.getElementById("thendral-code")
.addEventListener("keydown", (event) => {
translate();
})
document.getElementById("thendral-code")
.addEventListener("keypress", (event) => {
translate();
})
document.getElementById("thendral-code")
.addEventListener("keyup", (event) => {
translate();
})
const divs = document.querySelectorAll('.program');
const programMap = {
"hello-world": `எழுது 'வணக்கம் உலகம்'`,
"variable-declaration": `நிலையற்ற a = 2`,
"if-loop": `நிலையற்ற a = 2\nஒருவேளை( a > 1 ) {\nஎழுது 'a is greater than 1'\n }\nஇல்லையென்றால்(சரி) { }\nஎதுவும்இல்லையென்றால் {}`,
"while-loop": `நிலையற்ற a = 2\nஇருப்பின்வளையம்(a < 10) {\n a = a + 2 \n}\nஎழுது a`,
"function-declaration": `செயல்பாடு கூட்டல்(அ,ஆ) {\n திருப்பு அ + ஆ \n}\n எழுது கூட்டல்(1,2)`,
"sum-of-two-numbers": `எழுது 1 + 4`,
"print-even-numbers": `நிலையற்ற a = 2\nஇருப்பின்வளையம்(a < 10) {\n a = a + 2 \n எழுது a \n}`
}
divs.forEach(el => el.addEventListener('click', event => {
document.getElementById("thendral-code").value = programMap[event.target.getAttribute("data-program-id")];
translate()
}));
})
</script>