-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvertElif.py
executable file
·37 lines (33 loc) · 1.63 KB
/
convertElif.py
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
import re
import tokenize
from convertSuite import convertSuite
import convertToken
__author__ = 'Alexis Shaw'
def convertElif(token,line,t,v,i,understood,variables, oldIdent):
"""
"""
condition = ''
i += 1
while len(token)-i > 0 :
(t, v, _, _,_) = token[i]
if t == tokenize.NAME:
condition,i,understood,variables = convertToken.convertToken(token, condition,t,v,i,understood,variables,'')
elif t == tokenize.OP and re.match(r'^[<>()[\]&^|~=+*%[,-]$|^\*\*$|<<|>>|>=|<=|!=|==',v):
condition,i,understood,variables = convertToken.convertToken(token, condition,t,v,i,understood,variables,'')
elif t == tokenize.NL or t == tokenize.NUMBER:
condition,i,understood,variables = convertToken.convertToken(token,condition,t,v,i,understood,variables,'')
elif t == tokenize.STRING:
condition,i,understood,variables = convertToken.convertToken(token,condition,t,v,i,understood,variables,'')
elif t == tokenize.COMMENT and token[i+1][0] == tokenize.NL:
condition,i,understood,variables = convertToken.convertToken(token,condition,t,v,i,understood,variables,'')
elif t == tokenize.OP and v == ":":
break
i += 1
i += 1
(t, v, _, _,_) = token[i]
body, i,understood,variables, singleLine, noSimpleStatements, comment = convertSuite(token,t,v,i,understood,variables, oldIdent)
if singleLine:
line += 'elsif (' + condition + ') {' + body + '}' + comment + '\n'
else:
line += 'elsif (' + condition + ') {\n' + body + '\n'+ oldIdent+'}\n' + oldIdent
return line, i, understood, variables