summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlb_ii <lolbot_iichan@mail.ru>2020-07-12 18:07:16 +0300
committerlb_ii <lolbot_iichan@mail.ru>2020-07-12 18:16:12 +0300
commitf892c324f90b805f62e056eb536d354519c7e51d (patch)
tree84497298b583ba523ecef2159037932696f1e181
parent8c01ee4fe3e3f705933bda4101176780771f1252 (diff)
downloadply-f892c324f90b805f62e056eb536d354519c7e51d.tar.gz
GARDENSNAKE: Fix ast - string & decimal constants
-rw-r--r--example/GardenSnake/GardenSnake.py13
1 files changed, 10 insertions, 3 deletions
diff --git a/example/GardenSnake/GardenSnake.py b/example/GardenSnake/GardenSnake.py
index 64b4b27..a89252c 100644
--- a/example/GardenSnake/GardenSnake.py
+++ b/example/GardenSnake/GardenSnake.py
@@ -78,6 +78,10 @@ tokens = (
def t_NUMBER(t):
r"""(\d+(\.\d*)?|\.\d+)([eE][-+]? \d+)?"""
t.value = decimal.Decimal(t.value)
+ if t.value == int(t.value):
+ t.value = int(t.value)
+ else:
+ t.value = float(t.value)
return t
@@ -613,10 +617,12 @@ def p_atom_name(p):
def p_atom_number(p):
- """atom : NUMBER
- | STRING"""
- p[0] = ast.Const(p[1])
+ """atom : NUMBER"""
+ p[0] = ast.Num(p[1])
+def p_atom_string(p):
+ """atom : STRING"""
+ p[0] = ast.Str(p[1])
def p_atom_tuple(p):
"""atom : LPAR testlist RPAR"""
@@ -763,6 +769,7 @@ print(x(2))
print(x(8),'3')
print('this is decimal', 1/5)
print('BIG DECIMAL', 1.234567891234567e12345)
+print('LITTE DECIMAL', 1.234567891234567e-12345)
"""