Skip to content

Commit

Permalink
ast: Parse triple-quoted literals
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Povišer <povik@cutebit.org>
  • Loading branch information
povik committed Feb 28, 2024
1 parent a7b0d08 commit 511bc1d
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions fold/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,18 @@ def string_literal():
opening_marker = inp.marker()
opening_quote = next(inp)
assert opening_quote in "'\""
if opening_quote == "'" and inp.peek() is not None and inp.peek() == "'":
next(inp)
if inp.peek() is None or inp.peek() != "'":
return "''"
next(inp)
buffer = ""
while len(buffer) < 3 or buffer[-3:] != "'''":
if inp.peek() is None:
raise BadInput("missing termination of a triple-quoted literal",
markers=(opening_marker, inp.marker()))
buffer += next(inp)
return "'" + buffer[:-3] + "'"
ret = []
while inp.peek() is not None \
and inp.peek() != opening_quote:
Expand Down

0 comments on commit 511bc1d

Please sign in to comment.