Skip to content
This repository was archived by the owner on May 7, 2021. It is now read-only.

Commit 36fc0ac

Browse files
authored
Merge pull request #1 from Anandsure/master
Swift
2 parents 18f2041 + 2543ca4 commit 36fc0ac

File tree

5 files changed

+453
-23
lines changed

5 files changed

+453
-23
lines changed

run.py

+157-5
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@
2121

2222
@app.route('/')
2323
def home():
24+
global intent
25+
intent=[]
2426
return render_template('compiler.html')
27+
2528

2629

2730
@app.route('/print/name', methods=['POST', 'GET'])
@@ -64,6 +67,7 @@ def get_names():
6467
intent.append(b[0]['intent'])
6568
else:
6669
intent.append(b[0]['intent'])
70+
print('user said:', command)
6771
print(intent)
6872

6973
while intent[0]=='python':
@@ -129,7 +133,7 @@ def get_names():
129133
print(ans)"""
130134

131135
elif intent[-1]=='arith_multiplication':
132-
to_send="""def mult(a,b):
136+
to_send="""def multi(a,b):
133137
return a*b
134138
x=int(input())
135139
y=int(input())
@@ -268,7 +272,7 @@ def get_names():
268272
int main() {
269273
int x,y;
270274
cin>>x>>y;
271-
cout<<"Product is: "<< x*y <<endl;
275+
cout<<"Product is: "<< x*y << endl;
272276
return 0;
273277
}"""
274278

@@ -277,7 +281,7 @@ def get_names():
277281
using namespace std;
278282
int main() {
279283
int x,y;
280-
cout<<"Quotient is: "<< x/y <<endl;
284+
cout<<"Quotient is: "<< x/y << endl;
281285
return 0;
282286
}"""
283287

@@ -370,7 +374,7 @@ def get_names():
370374

371375
########################################################PHP#########################################################################################################################
372376
while intent[0]=='php':
373-
if intent=='for_loop':
377+
if intent[-1]=='for_loop':
374378
to_send = """for ($x = a; $x <= b; $x++) {
375379
//enter your code
376380
} """
@@ -529,7 +533,155 @@ def get_names():
529533
c+=1
530534
return json.dumps({"response": to_send}), 200
531535

536+
######################################################## SWIFT #########################################################################################################################
537+
538+
while intent[0]=='swift':
539+
if intent[-1]=='for_loop':
540+
to_send = """for i in a...b {
541+
//enter your code here
542+
} """
543+
544+
elif intent[-1]=='print':
545+
to_send = """ print(//enter your code) """
546+
547+
elif intent[-1]=='nested_for':
548+
to_send = """for i in a...b {
549+
for j in a...b{
550+
//enter your code here
551+
}
552+
}"""
553+
554+
elif intent[-1]=='if_condition':
555+
to_send = """let a = 10
556+
if a &lt; b {
557+
//enter your code
558+
}
559+
//print("This statement is always executed.")"""
560+
561+
elif intent[-1]=='nested_if':
562+
to_send = """let a = 10
563+
if a &gt; b {
564+
if a &gt; b {
565+
//enter your code
566+
}
567+
}
568+
//print("This statement is always executed.")
569+
"""
570+
571+
elif intent[-1]=='else_if':
572+
to_send = """let a = 10
573+
if a &gt; b {
574+
//enter your code
575+
} else if a &gt; b {
576+
//enter your code
577+
}
578+
//print("This statement is always executed.")
579+
"""
580+
581+
elif intent[-1]=='else_condition':
582+
to_send = """let a = 10
583+
if a &gt; b {
584+
//enter your code
585+
}
586+
else {
587+
//enter your code
588+
}"""
589+
590+
elif intent[-1]=='while_loop':
591+
to_send = """while a <= b {
592+
//enter your code
593+
}"""
532594

595+
elif intent[-1]=='exit_loop':
596+
to_send = """if a &gt; b {
597+
break
598+
}"""
599+
600+
elif intent[-1]=='do_while_loop':
601+
to_send = """repeat {
602+
var i = 1
603+
//enter your code here.
604+
i = i + 1
605+
} while a &lt; b"""
606+
607+
elif intent[-1]=='init_string':
608+
to_send = """var your_string = 'change it here' """
609+
610+
elif intent[-1]=='init_int':
611+
to_send = """var your_integer = 0 """
612+
613+
elif intent[-1]=='init_char':
614+
to_send = """var your_char = 'C' """
615+
616+
elif intent[-1]=='init_float':
617+
to_send = """var your_float = 0.00 """
618+
619+
elif intent[-1]=='arith_addition':
620+
to_send = """func add(a: Int , b: Int) -> Int {
621+
let sum = a + b
622+
return sum
623+
}
624+
print("sum is" , add(a: 2, b: 4), separator: " ")"""
625+
626+
elif intent[-1]=='arith_subtraction':
627+
to_send = """func sub(a: Int , b: Int) -> Int {
628+
let diff = a - b
629+
return diff
630+
}
631+
print("diff is" , sub(a: 10, b: 4), separator: " ")"""
632+
633+
elif intent[-1]=='arith_multiplication':
634+
to_send = """func multi(a: Int , b: Int) -> Int {
635+
let prod = a * b
636+
return prod
637+
}
638+
print("product is" , multi(a: 2, b: 4), separator: " ")"""
639+
640+
elif intent[-1]=='arith_division':
641+
to_send = """func divi(a: Int , b: Int) -> Int {
642+
let diff = a / b
643+
return diff
644+
}
645+
print("quotient is" , divi(a: 19, b: 4), separator: " ")"""
646+
647+
elif intent[-1]=='arith_remainder':
648+
to_send = """func modu(a: Int , b: Int) -> Int {
649+
let mod = a % b
650+
return mod
651+
}
652+
print("reminder is" , modu(a: 18, b: 4), separator: " ")"""
653+
654+
elif intent[-1]=='def_function':
655+
to_send = """func your_func_name(a: Int , b: Int) -> String {
656+
//enter your code
657+
if a &gt; b{
658+
The_final_output = "Edit this function"
659+
}
660+
return The_final_output
661+
}
662+
print("output:" , your_func_name(a: 18, b: 4), separator: " ")"""
663+
664+
665+
elif intent[-1]=='create_array':
666+
to_send = """var your_array = [1,2,3,4,5,6]
667+
print(your_array)"""
668+
669+
elif intent[-1]=='switch_condition':
670+
to_send = """let someCharacter: Character = "z" // or someinteger: Int = 2
671+
switch someCharacter {
672+
case "a": // case 1:
673+
// enter your code
674+
case "z": // case 2:
675+
// enter your code
676+
default:
677+
// default reply
678+
}"""
679+
680+
else:
681+
to_send= """running swift"""
682+
683+
c+=1
684+
return json.dumps({"response": to_send}), 200
533685

534686
c+=1
535687
return json.dumps({"response": ' '}), 200
@@ -538,7 +690,7 @@ def get_names():
538690
if __name__=='__main__':
539691
c=1
540692
intent=[]
541-
webbrowser.open('http://127.0.0.1:5000/')
693+
webbrowser.open('http://127.0.0.1:5000')
542694
app.run(debug=False)
543695

544696

static/css/style.css

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
ul.chat-messages li {
2+
list-style-type:none;
3+
}
4+
5+
ul.chat-messages li:nth-child(odd) {
6+
text-align: left;
7+
}
8+
9+
ul.chat-messages li:nth-child(even) {
10+
text-align: right;
11+
}
12+
13+
.mic {
14+
height: 70px;
15+
cursor: pointer;
16+
align-items: center;
17+
}
18+
19+
.chat-bot-modal {
20+
position: fixed;
21+
top: 0;
22+
left: 0;
23+
z-index: 999;
24+
display: none;
25+
height: 100vh;
26+
width: 100vw;
27+
background-color: rgba(0,0,0,.6);
28+
color: white;
29+
}
30+
31+
.chat-bot-modal.open {
32+
display: block;
33+
}
34+
35+
.chat-bot-wrapper {
36+
display: grid;
37+
grid-template-columns: .75fr 1.5fr .75fr;
38+
grid-gap: 10px;
39+
}
40+
41+
.chat-bot-wrapper .col {
42+
justify-content: center;
43+
align-items: center;
44+
}
45+
46+
.chat-window {
47+
text-align: center;
48+
}
49+
.chat-window input {
50+
width: 100%;
51+
line-height: 2.25rem;
52+
height: 2.25rem;
53+
}
54+
55+
.chat-window button.chat-window-button {
56+
margin-top: .5rem;
57+
font-weight: 400;
58+
text-align: center;
59+
vertical-align: middle;
60+
height: 40px;
61+
padding: 0.375rem 0.75rem;
62+
line-height: 1.5;
63+
border-radius: 0.25rem;
64+
color: #fff;
65+
background-color: #00b3be;
66+
}
67+
68+
.chat-bot-button {
69+
position: fixed;
70+
bottom: 10px;
71+
right: 10px;
72+
z-index: 1000;
73+
height: 60px;
74+
width: 60px;
75+
cursor: pointer;
76+
background-color: #00b3be;
77+
border-radius: 50%;
78+
padding: 7.5px;
79+
box-shadow: 2px 3px 3px #888888;
80+
}
81+
.chat-bot-button > div svg path {
82+
fill: white;
83+
}
84+
85+
.chat-bot-modal.open .chat-bot-button .question svg {
86+
display: none;
87+
}
88+
p.rambot svg {
89+
height: 50px;
90+
}

static/js/index.js

+26-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ function postChatMessage (response) {
3737
$.ajax({
3838
type: "POST",
3939
contentType: "application/json;charset=utf-8",
40-
url: "http://localhost:5000/print/name",
40+
//url: "http://127.0.0.1:5000/print/name", //localhostURL
41+
url: "https://228125ae.ngrok.io/print/name", //ngrokURL, keeps changing xD
4142
traditional: "true",
4243
data: JSON.stringify(respon_json),
4344
dataType: "json",
@@ -46,6 +47,7 @@ function postChatMessage (response) {
4647
var p=response.response.toString().localeCompare("python running!")
4748
var c=response.response.toString().localeCompare("running c++")
4849
var ph=response.response.toString().localeCompare("running php")
50+
var sw=response.response.toString().localeCompare("running swift")
4951
if(p==0){
5052
flag=1
5153
console.log(flag)
@@ -70,6 +72,14 @@ function postChatMessage (response) {
7072
flag=flag
7173
console.log(flag)
7274
}
75+
if(sw==0){
76+
flag=3
77+
console.log(flag)
78+
}
79+
else if(sw==-1 || sw==1){
80+
flag=flag
81+
console.log(flag)
82+
}
7383
if(flag==1){
7484
displayResponse(response.response);
7585
}
@@ -79,6 +89,9 @@ function postChatMessage (response) {
7989
else if(flag==2){
8090
displayResponsePhp(response.response);
8191
}
92+
else if(flag==3){
93+
displayResponseSwift(response.response);
94+
}
8295
}
8396
});
8497
}
@@ -119,6 +132,18 @@ function displayResponseC (response) {
119132
});
120133
}
121134

135+
function displayResponseSwift (response) {
136+
let newChat = document.createElement('p')
137+
newChat.innerHTML = `${response}`
138+
chatMessages = document.getElementById("chat-input");
139+
chatMessages.append(newChat)
140+
EnlighterJS.Util.Init('p', null, {
141+
indent: 4,
142+
language: 'swift',
143+
theme: 'MooTwo'
144+
});
145+
}
146+
122147
function speakResponse (response) {
123148
let utterance = new SpeechSynthesisUtterance(response);
124149
utterance.voice = samantha

0 commit comments

Comments
 (0)