From f561a849c228a8f81e4aee54718bf5d93fcaf04e Mon Sep 17 00:00:00 2001 From: SpookyDervish <78246495+SpookyDervish@users.noreply.github.com> Date: Sat, 13 Sep 2025 19:29:22 +1000 Subject: [PATCH] fix of escape sequences --- generators/x86_64.py | 7 ++++++- out | Bin 4656 -> 9072 bytes test.grnd | 6 ++++++ tokenizer.py | 10 ++++++---- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/generators/x86_64.py b/generators/x86_64.py index b8c2291..c4f3039 100644 --- a/generators/x86_64.py +++ b/generators/x86_64.py @@ -704,7 +704,12 @@ class X86_64Generator(Generator): value_type = type(value) if value_type == str: if not const["no_string"]: - final = f'db "' + value.replace("\\n", "\", 10, \"") + "\", 0" + value = value.replace("\"", "\", 34, \"") + value = value.replace("\r", "\", 13, \"") + value = value.replace("\n", "\", 10, \"") + value = value.replace("\a", "\", 7, \"") + + final = f'db "' + value + "\", 0" final = final.replace(", \"\", ", ", ") f.write(final) else: diff --git a/out b/out index f148d252397266742cfbef50a9ca155dcd09fa29..d1f28decacbc4e063d9de7376d3bc4d11d270e46 100644 GIT binary patch literal 9072 zcmeI2J4*vW5P&C_2a$Mq7J?$er4X?&KBHnG5m8da+VZ%NKni0dw@L)T-d`jZvGTtN zHs%+^ncbZ;xda=*#u?b1o!9Q&$2Pm{<5}(8Nu_|rfn(5?SJ5uh1AG=a1E2zjkj6d- zS)H5t4&jI^jDEK<*5DZjt&ydnwZX2(`p%>QYtEy(9L0R{U*9{4OS^FKBP5keP^%oNUs`YybKXh(YDU8}sJKe&zjco_pF19^v zWo-M{4j_nB*j1&gPUi-KpdLlW0YS47su0z61E3V$w^dk2t-40Hc%+&=1tpz}pYm&2 z#u<=`d4oZ-F(3PmBYv+zF%*8@VJv_m4yZof7tF;s8S%RfW8$707pir}UE1<|<7`m^ t3f0kEc`{HIjRM-Q@!Hl$sz)D&a$!{5+v#GP_V2X%H(S3JXPQB>{tLCMQ}h4; delta 279 zcmez1wn1frrkDT&95^soFfcJVFt9SPOte?z+yIr>Fma*q#2Oh+F(_Yb<4tw`NsJa^ zS&SatEGiz&9~c8Xx@}Z;*Z>vqvrhadHF<*)%VZq|kqkbdhyVj4kZ^!%hESX^aRpRy zQ5@njIK&z9OH1?;i*qNhQM8))$!)TMk^-aHS S=L)Ed;$%T(bIy}UJb3`#=_ix` diff --git a/test.grnd b/test.grnd index e69de29..c961dad 100644 --- a/test.grnd +++ b/test.grnd @@ -0,0 +1,6 @@ +@loop +stdout "/\r" +stdout "-\r" +stdout "\\r" +stdout "|\r" +jump %loop \ No newline at end of file diff --git a/tokenizer.py b/tokenizer.py index 173f21e..9adc167 100644 --- a/tokenizer.py +++ b/tokenizer.py @@ -379,7 +379,8 @@ def tokenize(input_string: str): current_char = input_string[pos] while current_char != '"': - current_token += current_char + if current_char != "\\": + current_token += current_char pos += 1 column += 1 if pos > len(input_string)-1: @@ -393,12 +394,11 @@ def tokenize(input_string: str): column += 1 while pos <= len(input_string)-1: escape += input_string[pos] - print(escape) - valid_escapes = ['"', 'n', 't', 'a', 'r'] + valid_escapes = ['"', 'n', 't', 'a', 'r', '\\'] if escape == '"': - current_token += 'aaaaaaa' + current_token += '"' elif escape == "n": current_token += '\n' elif escape == "t": @@ -407,6 +407,8 @@ def tokenize(input_string: str): current_token += "\a" elif escape == "r": current_token += "\r" + elif escape == "\\": + current_token += "\\" if escape in valid_escapes: break