mirror of
https://github.com/michaelcmartin/Ophis.git
synced 2024-12-30 10:30:47 +00:00
Fix both incomplete and overaggressive use of the charmap
This commit is contained in:
parent
6a4b2ae73b
commit
c0307c7ea4
@ -122,7 +122,7 @@ def pragmaCharmap(ppt, line, result):
|
||||
if str(line.lookahead(0)) == "EOL":
|
||||
currentcharmap = basecharmap
|
||||
else:
|
||||
bytes = readData(line)
|
||||
bytes = readRawData(line)
|
||||
try:
|
||||
base = bytes[0].data
|
||||
newsubstr = "".join([chr(x.data) for x in bytes[1:]])
|
||||
@ -254,8 +254,26 @@ def pragmaCbmfloat(ppt, line, result):
|
||||
result.append(IR.Node(ppt, "Byte", *bytes))
|
||||
|
||||
|
||||
def readData(line):
|
||||
def readRawData(line):
|
||||
"Read raw data from a comma-separated list"
|
||||
if line.lookahead(0).type == "STRING":
|
||||
data = [IR.ConstantExpr(ord(x))
|
||||
for x in line.expect("STRING").value]
|
||||
else:
|
||||
data = [FE.parse_expr(line)]
|
||||
next = line.expect(',', 'EOL').type
|
||||
while next == ',':
|
||||
if line.lookahead(0).type == "STRING":
|
||||
data.extend([IR.ConstantExpr(ord(x))
|
||||
for x in line.expect("STRING").value])
|
||||
else:
|
||||
data.append(FE.parse_expr(line))
|
||||
next = line.expect(',', 'EOL').type
|
||||
return data
|
||||
|
||||
|
||||
def readData(line):
|
||||
"Read charmap-translated data from a comma-separated list"
|
||||
if line.lookahead(0).type == "STRING":
|
||||
data = [IR.ConstantExpr(ord(x))
|
||||
for x in line.expect("STRING").value.translate(currentcharmap)]
|
||||
@ -265,7 +283,7 @@ def readData(line):
|
||||
while next == ',':
|
||||
if line.lookahead(0).type == "STRING":
|
||||
data.extend([IR.ConstantExpr(ord(x))
|
||||
for x in line.expect("STRING").value])
|
||||
for x in line.expect("STRING").value.translate(currentcharmap)])
|
||||
else:
|
||||
data.append(FE.parse_expr(line))
|
||||
next = line.expect(',', 'EOL').type
|
||||
@ -332,5 +350,5 @@ def pragmaInvoke(ppt, line, result):
|
||||
if line.lookahead(0).type == "EOL":
|
||||
args = []
|
||||
else:
|
||||
args = readData(line)
|
||||
args = readRawData(line)
|
||||
result.append(IR.Node(ppt, "MacroInvoke", macro, *args))
|
||||
|
@ -401,6 +401,10 @@ def test_subfiles():
|
||||
'.charmap\n'
|
||||
'.byte "hELLO, wORLD!",10\n',
|
||||
b"Hello, World!\nhELLO, wORLD!\n")
|
||||
test_string(".charmap (multi-arg)",
|
||||
'.charmap \'A, "abcdefghijklmnopqrstuvwxyz"\n'
|
||||
'.charmap \'a, "ABCDEFGHIJKLMNOPQRSTUVWXYZ"\n'
|
||||
'.byte "hELLO, ", "wORLD!",10\n', b"Hello, World!\n")
|
||||
test_string(".charmap (out of range)",
|
||||
'.charmap 250, "ABCDEFGHIJKLM"\n.byte 250,251',
|
||||
b'')
|
||||
|
Loading…
Reference in New Issue
Block a user