Skip to content

Commit 92ecf9c

Browse files
committed
dedent > 0 + escape sequence
1 parent f108468 commit 92ecf9c

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

Tools/cases_generator/lexer.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def choice(*opts: str) -> str:
109109
string_char = r"""([^"\\\n]|""" + escape_sequence + ")"
110110
str_re = '"' + string_char + '*"'
111111
STRING = "STRING"
112-
char = r"\'.\'" # TODO: escape sequence
112+
char = r"\'([^'\\]|\\[0-7]{1,3}|\\x[0-9a-fA-F]+|\\.|\\\\)\'"
113113
CHARACTER = "CHARACTER"
114114

115115
comment_re = r"(//.*)|/\*([^*]|\*[^/])*\*/"
@@ -344,7 +344,16 @@ def to_text(tkns: list[Token], dedent: int = 0) -> str:
344344
if dedent != 0 and tkn.kind == "COMMENT" and "\n" in text:
345345
if dedent < 0:
346346
text = text.replace("\n", "\n" + " " * -dedent)
347-
# TODO: dedent > 0
347+
elif dedent > 0:
348+
ret = []
349+
for line in text.split("\n"):
350+
leading_space = len(line) - len(line.lstrip())
351+
if leading_space > dedent:
352+
line = re.sub(r'(?m)^[ \t]{' + str(dedent) + r'}', '', line)
353+
else:
354+
line = re.sub(r'(?m)^[ \t]{' + str(leading_space) + r'}', '', line)
355+
ret.append(line)
356+
text = "\n".join(ret)
348357
res.append(text)
349358
line, col = tkn.end
350359
return "".join(res)

0 commit comments

Comments
 (0)