Skip to content

Commit 33ca100

Browse files
committed
chore: make numbers work in lexer
1 parent ffbc3f3 commit 33ca100

4 files changed

Lines changed: 21 additions & 15 deletions

File tree

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
setup(
1717
name='universalpython',
18-
version='0.0.6',
18+
version='0.1.0',
1919
author='Saad Bazaz',
2020
author_email='saadbazaz@hotmail.com',
2121
url='https://github.com/UniversalPython/UniversalPython',

test.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

universalpython/languages/de/de_native.lang.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
letters:
22
start : "a"
33
end : "z"
4+
extra : "äöüßÄÖÜ"
45

56
numbers:
67
start : "0"

universalpython/modes/lex.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# ------------------------------------------------------------
2-
# ply_test.py
2+
# lex.py
33
#
4-
# tokenizer to test UrduPython grammer
4+
# tokenizer to test UniversalPython grammer
55
# ------------------------------------------------------------
66

77

@@ -264,9 +264,13 @@ def t_ID(t):
264264

265265
if args["reverse"]:
266266
t_ID.__doc__ = r'[a-zA-Z_][a-zA-Z_0-9]*'
267-
else:
268-
t_ID.__doc__ = r'['+language_dict["letters"]["start"]+'-'+language_dict["letters"]["end"]+'_]['+language_dict["numbers"]["start"]+'-'+language_dict["numbers"]["end"]+'_'+language_dict["letters"]["start"]+'-'+language_dict["letters"]["end"]+']*'
269-
267+
else:
268+
# Get base letters and any extra characters
269+
letter_range = language_dict["letters"]["start"] + "-" + language_dict["letters"]["end"]
270+
if "extra" in language_dict["letters"]:
271+
letter_range += language_dict["letters"]["extra"]
272+
273+
t_ID.__doc__ = r'[' + letter_range + '_][' + letter_range + language_dict["numbers"]["start"] + '-' + language_dict["numbers"]["end"] + '_]*'
270274

271275
# A string containing ignored characters (spaces and tabs)
272276
# t_ignore = ' \t'
@@ -374,9 +378,9 @@ def t_COMMENT(t):
374378
break # No more input
375379

376380
# ------------- Debugging ---------------
377-
#print(tok)
378-
#print ("Tok's value is:", tok.value)
379-
#print ("Tok's type is:", tok.type)
381+
# print(tok)
382+
# print ("Tok's value is:", tok.value)
383+
# print ("Tok's type is:", tok.type)
380384
# ------------- Debugging ---------------
381385

382386

@@ -386,12 +390,14 @@ def t_COMMENT(t):
386390
# ------------- Debugging ---------------
387391
# if tok.type == '۔':
388392
# print ("Found an Urdu dot!")
393+
# print ("Found a reserved word:", tok.value, "as", tok.type)
394+
# print ("tok.type == 'NUMBER'", tok.type == 'NUMBER')
389395
# ------------- Debugging ---------------
390-
391-
# if args["reverse"] and tok.type == 'NUMBER':
392-
# compiled_code += tok.value
393-
# else:
394-
compiled_code += tok.type
396+
397+
if tok.type == 'NUMBER':
398+
compiled_code += tok.value
399+
else:
400+
compiled_code += tok.type
395401
else:
396402
compiled_code += tok.value
397403

0 commit comments

Comments
 (0)