Skip to content

Commit

Permalink
don't call parse_tail (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
kavigupta authored Sep 10, 2024
1 parent a0b1383 commit 2048102
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions s_expression_parser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,17 @@ def parse_tail(close_paren):
if first is None:
return nil
if first == "." and config.dots_are_cons:
rest = parse_tail(close_paren)
if not isinstance(rest, Pair) or rest.cdr != nil:
rest = parse_atom(close_paren)
if not token_stream or token_stream[-1] != close_paren:
raise ValueError(
(
"If dots are used to represent cons, then a dot"
f" must be followed by a single atom, but instead was followed by {rest}"
" must be followed by a single atom, but instead was followed by "
+ (token_stream[-1] if token_stream else "EOF")
)
)
return rest.car
assert token_stream.pop() == close_paren
return rest
rest = parse_tail(close_paren)
return Pair(first, rest)

Expand Down

0 comments on commit 2048102

Please sign in to comment.