Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TODOs in the cases generator lexer: dedent > 0 case in the to_text function + escape sequence handling
13 changes: 11 additions & 2 deletions Tools/cases_generator/lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def choice(*opts: str) -> str:
string_char = r"""([^"\\\n]|""" + escape_sequence + ")"
str_re = '"' + string_char + '*"'
STRING = "STRING"
char = r"\'.\'" # TODO: escape sequence
char = r"\'([^'\\]|\\[0-7]{1,3}|\\x[0-9a-fA-F]+|\\.|\\\\)\'"
CHARACTER = "CHARACTER"

comment_re = r"(//.*)|/\*([^*]|\*[^/])*\*/"
Expand Down Expand Up @@ -344,7 +344,16 @@ def to_text(tkns: list[Token], dedent: int = 0) -> str:
if dedent != 0 and tkn.kind == "COMMENT" and "\n" in text:
if dedent < 0:
text = text.replace("\n", "\n" + " " * -dedent)
# TODO: dedent > 0
elif dedent > 0:
temp: list[str] = []
for line in text.split("\n"):
leading_space = len(line) - len(line.lstrip())
if leading_space > dedent:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the regex necessary? Would line = line[min(leading_space, dedent):] work?

line = re.sub(r'(?m)^[ \t]{' + str(dedent) + r'}', '', line)
else:
line = re.sub(r'(?m)^[ \t]{' + str(leading_space) + r'}', '', line)
temp.append(line)
text = "\n".join(temp)
res.append(text)
line, col = tkn.end
return "".join(res)
Expand Down