Skip to content

Commit

Permalink
GARDENSNAKE: Fix ast - string & decimal constants
Browse files Browse the repository at this point in the history
  • Loading branch information
lolbot-iichan committed Jul 12, 2020
1 parent 8c01ee4 commit f892c32
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions example/GardenSnake/GardenSnake.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@
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


Expand Down Expand Up @@ -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"""
Expand Down Expand Up @@ -763,6 +769,7 @@ def x(a):
print(x(8),'3')
print('this is decimal', 1/5)
print('BIG DECIMAL', 1.234567891234567e12345)
print('LITTE DECIMAL', 1.234567891234567e-12345)
"""

Expand Down

0 comments on commit f892c32

Please sign in to comment.