Implement #"raw strings" (#1122)

Fixes #1121
This commit is contained in:
Rangi
2023-11-07 17:48:23 -05:00
committed by GitHub
parent 9fc088dcb0
commit 8eeb40cca8
5 changed files with 120 additions and 6 deletions

76
test/asm/raw-strings.asm Normal file
View File

@@ -0,0 +1,76 @@
DEF q EQUS "\""
assert !strcmp( \
#"\t\1{s}\", \
"\\t\\1\{s}\\" )
assert !strcmp( \
#"\a,\b,\1,\2", \
"\\a,\\b,\\1,\\2" )
assert !strcmp( \
#"""new
line""", \
"new\nline" )
assert !strcmp( \
#"""new\nline""", \
"""new\\nline""" )
assert !strcmp( \
#"/\w+(\+\w+)?@[a-z]+\.[a-z]{2,3}/i", \
"/\\w+(\\+\\w+)?@[a-z]+\\.[a-z]\{2,3}/i" )
assert !strcmp( \
#{q}{q}{q}rs", \
{q}\{q}\{q}rs" )
assert !strcmp( \
#"", \
"" )
assert !strcmp( \
#"""""", \
"""""" )
MACRO test
REDEF raw EQUS \1
REDEF plain EQUS \2
assert !strcmp("{raw}", "{plain}")
ENDM
; test lexing string literals within macro args
test \
#"\t\1{s}\", \
"\\t\\1\{s}\\"
test \
#"\a,\b,\1,\2", \
"\\a,\\b,\\1,\\2"
test \
#"""new,
line""", \
"new,\nline"
test \
#"""new,\nline""", \
"""new,\\nline"""
test \
#"/\w+(\+\w+)?@[a-z]+\.[a-z]{2,3}/i", \
"/\\w+(\\+\\w+)?@[a-z]+\\.[a-z]\{2,3}/i"
test \
#{q}{q}{q}rs", \
{q}\{q}\{q}rs"
test \
#"", \
""
test \
#"""""", \
""""""
MACRO echo
println "\#"
ENDM
DEF s EQUS "foo"
echo \
# "{s}", \
#"{s}", \ ; raw!
#raw"{s}", \
#/*comment*/"{s}"
echo \
# """{s}""", \
#"""{s}""", \ ; raw!
#raw"""{s}""", \
#/*comment*/"""{s}"""