Skip to content

Commit 57f77cd

Browse files
committed
python fixes
1 parent bc38604 commit 57f77cd

File tree

5 files changed

+24
-22
lines changed

5 files changed

+24
-22
lines changed

modiscript/MODI

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,20 @@ def execute(filename):
3232
def main():
3333
if len(sys.argv) < 2 or '-h' in sys.argv or '--help' in sys.argv:
3434
usage()
35-
35+
3636
filename = sys.argv[-1]
37-
#filename = "modi.chai"
37+
# filename = "modi.chai"
3838
if '-d' in sys.argv or '--debug' in sys.argv:
3939
global DEBUG
4040
DEBUG = True
41-
41+
4242
# check existence
4343
if not os.path.isfile(filename):
4444
raise ErrorHandler(FNF, filename)
4545
# execute
4646
execute(filename)
4747

48+
4849
if __name__ == '__main__':
4950
try:
5051
main()
1.43 KB
Binary file not shown.

modiscript/lexer.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from utils import *
1+
from utils import LEX, ErrorHandler, ERROR, CONGRESS_RULE, STARTING_TROUBLE, MISQUOTE, WORDS
22
import re
33
import sys
44

@@ -23,18 +23,8 @@ def lexeme(lex, value=None, line=0, offset=0):
2323

2424
@staticmethod
2525
def normalize(word):
26-
if word == 'nahin':
27-
word = 'nahi'
28-
elif word == 'tho':
29-
word = 'toh'
30-
elif word == 'bhayyo':
31-
word = 'bhaiyo'
32-
elif word == 'beheno':
33-
word = 'behno'
34-
elif word == 'thak':
35-
word = 'tak'
36-
elif word == 'jyada':
37-
word = 'zyada'
26+
if word in WORDS:
27+
word = WORDS[word]
3828
elif mitrooon.search(word):
3929
word = 'mitrooon'
4030
elif acche.search(word):
@@ -193,6 +183,6 @@ def _analyze_lexemes(self):
193183
yield Lexer.lexeme(*lex)
194184
self.stack = []
195185
self.clear = False
196-
if sys.version_info >= (3,7):
197-
return
186+
if sys.version_info >= (3, 7):
187+
return
198188
raise StopIteration()

modiscript/parser.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from ast import *
2-
from utils import *
2+
from utils import LEX, ErrorHandler, ERROR, CONGRESS_RULE
33

44

55
class Parser:
@@ -122,7 +122,7 @@ def _analyze_print(self, num):
122122
new_num, node = self._analyze_expr(num + 1)
123123
if node is not None:
124124
return new_num, Expr(value=Call(func=Name(id='print', ctx=Load()),
125-
args=[node], keywords=[]), **self._debug_details(num))
125+
args=[node], keywords=[]), **self._debug_details(num))
126126
return num + 1, None
127127

128128
def _analyze_until(self, num):
@@ -267,7 +267,8 @@ def _analyze_b(self, num):
267267
elif lexeme['lex'] == LEX['<']:
268268
op = Gt(**self._debug_details(num))
269269
op = Compare(left=prev, ops=[op], comparators=[node], **self._debug_details(num))
270-
if new_num + 1 < self.length and self.lex[new_num + 1]['lex'] == LEX['var'] and self.lex[new_num + 1]['value'] == 'nahi':
270+
if new_num + 1 < self.length and self.lex[new_num + 1]['lex'] == LEX['var'] and self.lex[new_num + 1][
271+
'value'] == 'nahi':
271272
new_num += 1
272273
op = UnaryOp(op=Not(), operand=op, **self._debug_details(new_num))
273274
if new_num < self.length and self.lex[new_num]['lex'] == LEX['hai']:
@@ -293,7 +294,8 @@ def _analyze_b(self, num):
293294
elif lexeme['lex'] == LEX['!=']:
294295
op = NotEq(**self._debug_details(new_num))
295296
op = Compare(left=prev, ops=[op], comparators=[node], **self._debug_details(num))
296-
if new_num + 1 < self.length and self.lex[new_num + 1]['lex'] == LEX['var'] and self.lex[new_num + 1]['value'] == 'nahi':
297+
if new_num + 1 < self.length and self.lex[new_num + 1]['lex'] == LEX['var'] and self.lex[new_num + 1][
298+
'value'] == 'nahi':
297299
new_num += 1
298300
op = UnaryOp(op=Not(), operand=op, **self._debug_details(new_num))
299301
if new_num + 1 < self.length and self.lex[new_num + 1]['lex'] == LEX['hai']:

modiscript/utils.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@
4040
'false': 105
4141
}
4242

43+
WORDS = {
44+
"nahin": "nahi",
45+
"tho": "toh",
46+
"bhayyo": "bhaiyo",
47+
"beheno": "behno",
48+
"thak": "tak",
49+
"jyada": "zyada"
50+
}
51+
4352

4453
def usage():
4554
print("Usage:", PROGRAM, "[options]", "filename")

0 commit comments

Comments
 (0)