File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -109,7 +109,7 @@ def choice(*opts: str) -> str:
109109string_char = r"""([^"\\\n]|""" + escape_sequence + ")"
110110str_re = '"' + string_char + '*"'
111111STRING = "STRING"
112- char = r"\'.\'" # TODO: escape sequence
112+ char = r"\'([^'\\]|\\[0-7]{1,3}|\\x[0-9a-fA-F]+|\\.|\\\\)\'"
113113CHARACTER = "CHARACTER"
114114
115115comment_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 )
You can’t perform that action at this time.
0 commit comments