1
0
mirror of https://github.com/mnaberez/py65.git synced 2025-01-16 18:33:00 +00:00

Handle all syntax errors in immediate values

This commit is contained in:
Mike Naberezny 2014-12-14 18:55:32 -08:00
parent 23bd9b9a39
commit 2dde6bdafe
2 changed files with 9 additions and 7 deletions

View File

@ -101,15 +101,15 @@ class Assembler:
# target is an immediate value
if target.startswith('#'):
if target[1] in ("'", '"'): # quoted ascii character
try:
try:
if target[1] in ("'", '"'): # quoted ascii character
number = ord(target[2])
except IndexError:
raise SyntaxError(statement)
else:
number = self._address_parser.number(target[1:])
else:
number = self._address_parser.number(target[1:])
except IndexError:
raise SyntaxError(statement)
if (number < 0x00) or (number > self._mpu.byteMask):
if (number < 0) or (number > self._mpu.byteMask):
raise OverflowError
statement = before + '#$' + self._mpu.BYTE_FORMAT % number

View File

@ -22,6 +22,8 @@ class AssemblerTests(unittest.TestCase):
def test_assemble_bad_syntax_raises_syntaxerror(self):
self.assertRaises(SyntaxError,
self.assemble, 'foo')
self.assertRaises(SyntaxError,
self.assemble, 'lda #')
self.assertRaises(SyntaxError,
self.assemble, 'lda #"')