mirror of
https://github.com/mnaberez/py65.git
synced 2025-01-04 16:30:42 +00:00
Command shortcuts now work when the command has no args.
This commit is contained in:
parent
ab7c84659a
commit
87de997a78
@ -68,28 +68,30 @@ class Monitor(cmd.Cmd):
|
|||||||
'z': 'step'}
|
'z': 'step'}
|
||||||
|
|
||||||
def _preprocess_line(self, line):
|
def _preprocess_line(self, line):
|
||||||
# ignore leading dots
|
# line comments
|
||||||
line = line.lstrip('.')
|
quoted = False
|
||||||
|
for pos, char in enumerate(line):
|
||||||
|
if char in ('"', "'"):
|
||||||
|
quoted = not quoted
|
||||||
|
if (not quoted) and (char == ';'):
|
||||||
|
line = line[:pos]
|
||||||
|
break
|
||||||
|
|
||||||
|
# whitepsace & leading dots
|
||||||
|
line = line.strip(' \t').lstrip('.')
|
||||||
|
|
||||||
# command shortcuts
|
# command shortcuts
|
||||||
for shortcut, command in self._shortcuts.iteritems():
|
for shortcut, command in self._shortcuts.iteritems():
|
||||||
|
if line == shortcut:
|
||||||
|
line = command
|
||||||
|
break
|
||||||
|
|
||||||
pattern = '^%s\s+' % re.escape(shortcut)
|
pattern = '^%s\s+' % re.escape(shortcut)
|
||||||
matches = re.match(pattern, line)
|
matches = re.match(pattern, line)
|
||||||
if matches:
|
if matches:
|
||||||
start, end = matches.span()
|
start, end = matches.span()
|
||||||
line = "%s %s" % (command, line[end:])
|
line = "%s %s" % (command, line[end:])
|
||||||
|
|
||||||
# line comments
|
|
||||||
quoted = False
|
|
||||||
for pos in range(0, len(line)):
|
|
||||||
if line[pos] in ('"', "'"):
|
|
||||||
quoted = not quoted
|
|
||||||
if (not quoted) and (line[pos] == ';'):
|
|
||||||
line = line[:pos]
|
|
||||||
break
|
break
|
||||||
|
|
||||||
if line == 'a':
|
|
||||||
line = 'assemble'
|
|
||||||
|
|
||||||
return line
|
return line
|
||||||
|
|
||||||
|
@ -9,13 +9,35 @@ class MonitorTests(unittest.TestCase):
|
|||||||
|
|
||||||
# line processing
|
# line processing
|
||||||
|
|
||||||
def test_preprocess_line_removes_leading_dots(self):
|
def test__preprocess_line_removes_leading_dots_after_whitespace(self):
|
||||||
stdout = StringIO()
|
mon = Monitor()
|
||||||
mon = Monitor(stdout=stdout)
|
self.assertEqual('help', mon._preprocess_line(' ...help'))
|
||||||
mon.onecmd('...help')
|
|
||||||
|
def test__preprocess_line_removes_leading_and_trailing_whitespace(self):
|
||||||
out = stdout.getvalue()
|
mon = Monitor()
|
||||||
self.assert_('Documented commands' in out)
|
self.assertEqual('help', mon._preprocess_line(' \t help \t '))
|
||||||
|
|
||||||
|
def test__preprocess_line_rewrites_shortcut_when_alone_on_line(self):
|
||||||
|
mon = Monitor()
|
||||||
|
self.assertEqual('assemble', mon._preprocess_line(' a'))
|
||||||
|
|
||||||
|
def test__preprocess_line_rewrites_shortcut_with_arguments_on_line(self):
|
||||||
|
mon = Monitor()
|
||||||
|
self.assertEqual('assemble c000', mon._preprocess_line('a c000'))
|
||||||
|
|
||||||
|
def test__preprocess_line_removes_semicolon_comments(self):
|
||||||
|
mon = Monitor()
|
||||||
|
self.assertEqual('assemble', mon._preprocess_line('a ;comment'))
|
||||||
|
|
||||||
|
def test__preprocess_line_does_not_remove_semicolons_in_quotes(self):
|
||||||
|
mon = Monitor()
|
||||||
|
self.assertEqual('assemble lda #$";"',
|
||||||
|
mon._preprocess_line('a lda #$";" ;comment'))
|
||||||
|
|
||||||
|
def test__preprocess_line_does_not_remove_semicolons_in_apostrophes(self):
|
||||||
|
mon = Monitor()
|
||||||
|
self.assertEqual("assemble lda #$';'",
|
||||||
|
mon._preprocess_line("assemble lda #$';' ;comment"))
|
||||||
|
|
||||||
# assemble
|
# assemble
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user