Skip to content

Commit

Permalink
Added new flag parse_float to class Parser.
Browse files Browse the repository at this point in the history
  • Loading branch information
kazssym committed Jul 6, 2013
1 parent edbe8dd commit 3e57dcd
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions sexpdata.py
Expand Up @@ -538,13 +538,14 @@ class Parser(object):
quote_or_escape_re = re.compile(r'"|\\')

def __init__(self, string, string_to=None, nil='nil', true='t', false=None,
line_comment=';'):
line_comment=';', parse_float=True):
self.string = string
self.nil = nil
self.true = true
self.false = false
self.string_to = (lambda x: x) if string_to is None else string_to
self.line_comment = line_comment
self.parse_float = parse_float

def parse_str(self, i):
string = self.string
Expand Down Expand Up @@ -606,9 +607,12 @@ def atom(self, token):
try:
return int(token)
except ValueError:
try:
return float(token)
except ValueError:
if self.parse_float:
try:
return float(token)
except ValueError:
return Symbol(token)
else:
return Symbol(token)

def parse_sexp(self, i):
Expand Down

0 comments on commit 3e57dcd

Please sign in to comment.