Permalink
Browse files

To save call stack, no decorator for parse_sexp

  • Loading branch information...
1 parent a75054f commit fa0db75554213b646dd97e71f53bcadec2a00bd0 @tkf committed Nov 2, 2012
Showing with 8 additions and 7 deletions.
  1. +8 −7 sexpdata.py
View
@@ -584,19 +584,20 @@ def atom(self, token):
except ValueError:
return Symbol(token)
- @return_as(list)
def parse_sexp(self, laiter):
+ sexp = []
+ append = sexp.append
while laiter.has_next():
c = laiter.lookahead()
if c == '"':
- yield self.string_to(self.parse_str(laiter))
+ append(self.string_to(self.parse_str(laiter)))
elif c in whitespace:
laiter.next()
continue
elif c in BRACKETS:
close = BRACKETS[c]
laiter.next()
- yield bracket(self.parse_sexp(laiter), c)
+ append(bracket(self.parse_sexp(laiter), c))
if laiter.lookahead_safe() != close:
raise ExpectClosingBracket(laiter.lookahead_safe(), close)
laiter.next()
@@ -605,13 +606,13 @@ def parse_sexp(self, laiter):
elif c == "'":
laiter.next()
subsexp = self.parse_sexp(laiter)
- yield Quoted(subsexp[0])
- for sexp in subsexp[1:]:
- yield sexp
+ append(Quoted(subsexp[0]))
+ sexp.extend(subsexp[1:])
elif c == self.line_comment:
laiter.consume_until('\n')
else:
- yield self.parse_atom(laiter)
+ append(self.parse_atom(laiter))
+ return sexp
def parse(iterable, **kwds):

0 comments on commit fa0db75

Please sign in to comment.