Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: SyntaxError #48

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ jobs:
TOX_TESTENV_PASSENV: "PYTHONUTF8"
run: python -m tox -v --durations -e ${{ matrix.tox_env }}

- name: Test compile
run: python -m compileall pyrepl pythoni pythoni1

- name: Report coverage
if: always() && (steps.setup-tox.outcome == 'success' && contains(matrix.tox_env, '-coverage'))
uses: codecov/codecov-action@v1
Expand Down
175 changes: 85 additions & 90 deletions pyrepl/keymaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,68 +18,68 @@
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

reader_emacs_keymap = tuple(
[(r'\C-a', 'beginning-of-line'),
(r'\C-b', 'left'),
(r'\C-c', 'interrupt'),
(r'\C-d', 'delete'),
(r'\C-e', 'end-of-line'),
(r'\C-f', 'right'),
(r'\C-g', 'cancel'),
(r'\C-h', 'backspace'),
(r'\C-j', 'self-insert'),
(r'\<return>', 'accept'),
(r'\C-k', 'kill-line'),
(r'\C-l', 'clear-screen'),
# (r'\C-m', 'accept'),
(r'\C-q', 'quoted-insert'),
(r'\C-t', 'transpose-characters'),
(r'\C-u', 'unix-line-discard'),
(r'\C-v', 'quoted-insert'),
(r'\C-w', 'unix-word-rubout'),
(r'\C-x\C-u', 'upcase-region'),
(r'\C-y', 'yank'),
(r'\C-z', 'suspend'),

(r'\M-b', 'backward-word'),
(r'\M-c', 'capitalize-word'),
(r'\M-d', 'kill-word'),
(r'\M-f', 'forward-word'),
(r'\M-l', 'downcase-word'),
(r'\M-t', 'transpose-words'),
(r'\M-u', 'upcase-word'),
(r'\M-y', 'yank-pop'),
(r'\M--', 'digit-arg'),
(r'\M-0', 'digit-arg'),
(r'\M-1', 'digit-arg'),
(r'\M-2', 'digit-arg'),
(r'\M-3', 'digit-arg'),
(r'\M-4', 'digit-arg'),
(r'\M-5', 'digit-arg'),
(r'\M-6', 'digit-arg'),
(r'\M-7', 'digit-arg'),
(r'\M-8', 'digit-arg'),
(r'\M-9', 'digit-arg'),
(r'\M-\n', 'self-insert'),
(r'\<backslash>', 'self-insert')] + \
[(c, 'self-insert')
for c in map(chr, range(32, 127)) if c <> '\\'] + \
[(c, 'self-insert')
for c in map(chr, range(128, 256)) if c.isalpha()] + \
[(r'\<up>', 'up'),
(r'\<down>', 'down'),
(r'\<left>', 'left'),
(r'\<right>', 'right'),
(r'\<insert>', 'quoted-insert'),
(r'\<delete>', 'delete'),
(r'\<backspace>', 'backspace'),
(r'\M-\<backspace>', 'backward-kill-word'),
(r'\<end>', 'end'),
(r'\<home>', 'home'),
(r'\<f1>', 'help'),
(r'\EOF', 'end'), # the entries in the terminfo database for xterms
(r'\EOH', 'home'), # seem to be wrong. this is a less than ideal
# workaround
])
[
(r"\C-a", "beginning-of-line"),
(r"\C-b", "left"),
(r"\C-c", "interrupt"),
(r"\C-d", "delete"),
(r"\C-e", "end-of-line"),
(r"\C-f", "right"),
(r"\C-g", "cancel"),
(r"\C-h", "backspace"),
(r"\C-j", "self-insert"),
(r"\<return>", "accept"),
(r"\C-k", "kill-line"),
(r"\C-l", "clear-screen"),
# (r'\C-m', 'accept'),
(r"\C-q", "quoted-insert"),
(r"\C-t", "transpose-characters"),
(r"\C-u", "unix-line-discard"),
(r"\C-v", "quoted-insert"),
(r"\C-w", "unix-word-rubout"),
(r"\C-x\C-u", "upcase-region"),
(r"\C-y", "yank"),
(r"\C-z", "suspend"),
(r"\M-b", "backward-word"),
(r"\M-c", "capitalize-word"),
(r"\M-d", "kill-word"),
(r"\M-f", "forward-word"),
(r"\M-l", "downcase-word"),
(r"\M-t", "transpose-words"),
(r"\M-u", "upcase-word"),
(r"\M-y", "yank-pop"),
(r"\M--", "digit-arg"),
(r"\M-0", "digit-arg"),
(r"\M-1", "digit-arg"),
(r"\M-2", "digit-arg"),
(r"\M-3", "digit-arg"),
(r"\M-4", "digit-arg"),
(r"\M-5", "digit-arg"),
(r"\M-6", "digit-arg"),
(r"\M-7", "digit-arg"),
(r"\M-8", "digit-arg"),
(r"\M-9", "digit-arg"),
(r"\M-\n", "self-insert"),
(r"\<backslash>", "self-insert"),
]
+ [(c, "self-insert") for c in map(chr, range(32, 127)) if c != "\\"]
+ [(c, "self-insert") for c in map(chr, range(128, 256)) if c.isalpha()]
+ [
(r"\<up>", "up"),
(r"\<down>", "down"),
(r"\<left>", "left"),
(r"\<right>", "right"),
(r"\<insert>", "quoted-insert"),
(r"\<delete>", "delete"),
(r"\<backspace>", "backspace"),
(r"\M-\<backspace>", "backward-kill-word"),
(r"\<end>", "end"),
(r"\<home>", "home"),
(r"\<f1>", "help"),
(r"\EOF", "end"), # the entries in the terminfo database for xterms
(r"\EOH", "home"), # seem to be wrong. this is a less than ideal workaround
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now it appears with "home" only, but likely is also meant for "end". (just from what I think/see, no idea really).
I wanted to ensure that the comment's meaning/location/reference is kept (which was given before due to whitespace alignment), but now it is even less clear.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ya I agree. It looks like the comment spans multiple lines and starts with "the entries in the terminfo database.." IMO it should be on a separate line, before the end & home lines.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0262f36 fix that

should there be new line between help and comment? if yes, i will create another commit for that

]
)

hist_emacs_keymap = reader_emacs_keymap + (
(r'\C-n', 'next-history'),
Expand All @@ -98,37 +98,33 @@
python_emacs_keymap = comp_emacs_keymap + (
(r'\n', 'maybe-accept'),
(r'\M-\n', 'self-insert'))

reader_vi_insert_keymap = tuple(
[(c, 'self-insert')
for c in map(chr, range(32, 127)) if c <> '\\'] + \
[(c, 'self-insert')
for c in map(chr, range(128, 256)) if c.isalpha()] + \
[(r'\C-d', 'delete'),
(r'\<backspace>', 'backspace'),
('')])
[(c, "self-insert") for c in map(chr, range(32, 127)) if c != "\\"]
+ [(c, "self-insert") for c in map(chr, range(128, 256)) if c.isalpha()]
+ [(r"\C-d", "delete"), (r"\<backspace>", "backspace"), ("")]
)

reader_vi_command_keymap = tuple(
[
('E', 'enter-emacs-mode'),
('R', 'enter-replace-mode'),
('dw', 'delete-word'),
('dd', 'delete-line'),

('h', 'left'),
('i', 'enter-insert-mode'),
('j', 'down'),
('k', 'up'),
('l', 'right'),
('r', 'replace-char'),
('w', 'forward-word'),
('x', 'delete'),
('.', 'repeat-edit'), # argh!
(r'\<insert>', 'enter-insert-mode'),
] +
[(c, 'digit-arg') for c in '01234567689'] +
[])

("E", "enter-emacs-mode"),
("R", "enter-replace-mode"),
("dw", "delete-word"),
("dd", "delete-line"),
("h", "left"),
("i", "enter-insert-mode"),
("j", "down"),
("k", "up"),
("l", "right"),
("r", "replace-char"),
("w", "forward-word"),
("x", "delete"),
(".", "repeat-edit"), # argh!
(r"\<insert>", "enter-insert-mode"),
]
+ [(c, "digit-arg") for c in "01234567689"]
)


reader_keymaps = {
'emacs' : reader_emacs_keymap,
Expand All @@ -137,4 +133,3 @@
}

del c # from the listcomps

13 changes: 7 additions & 6 deletions pyrepl/pygame_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class PyGameConsole(Console):
height,
width,
"""

def __init__(self):
self.pygame_screen = pygame.display.set_mode((800, 600))
pygame.font.init()
Expand All @@ -105,7 +105,7 @@ def __init__(self):
pygame.display.update()
pygame.event.set_allowed(None)
pygame.event.set_allowed(KEYDOWN)

def install_keymap(self, keymap):
"""Install a given keymap.

Expand All @@ -130,7 +130,8 @@ def paint_margin(self):
s.fill(c, [0, 600 - bmargin, 800, bmargin])
s.fill(c, [800 - rmargin, 0, lmargin, 600])

def refresh(self, screen, (cx, cy)):
def refresh(self, screen, c):
c = cx, cy
self.screen = screen
self.pygame_screen.fill(colors.bg,
[0, tmargin + self.cur_top + self.scroll,
Expand Down Expand Up @@ -282,9 +283,9 @@ def flushoutput(self):

def forgetinput(self):
"""Forget all pending, but not yet processed input."""
while pygame.event.poll().type <> NOEVENT:
while pygame.event.poll().type != NOEVENT:
pass

def getpending(self):
"""Return the characters that have been typed but not yet
processed."""
Expand All @@ -299,7 +300,7 @@ def getpending(self):

def wait(self):
"""Wait for an event."""
raise Exception, "erp!"
raise Exception("erp!")

def repaint(self):
# perhaps we should consolidate grobs?
Expand Down
60 changes: 33 additions & 27 deletions pyrepl/pygame_keymap.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,23 +89,27 @@ def _parse_key1(key, s):
ret = _escapes[c]
s += 2
elif c == "c":
if key[s + 2] != '-':
raise KeySpecError, \
"\\C must be followed by `-' (char %d of %s)"%(
s + 2, repr(key))
if key[s + 2] != "-":
raise KeySpecError(
"\\C must be followed by `-' (char %d of %s)"
% (s + 2, repr(key))
)
if ctrl:
raise KeySpecError, "doubled \\C- (char %d of %s)"%(
s + 1, repr(key))
raise KeySpecError(
"doubled \\C- (char %d of %s)" % (s + 1, repr(key))
)
ctrl = 1
s += 3
elif c == "m":
if key[s + 2] != '-':
raise KeySpecError, \
"\\M must be followed by `-' (char %d of %s)"%(
s + 2, repr(key))
if key[s + 2] != "-":
raise KeySpecError(
"\\M must be followed by `-' (char %d of %s)"
% (s + 2, repr(key))
)
if meta:
raise KeySpecError, "doubled \\M- (char %d of %s)"%(
s + 1, repr(key))
raise KeySpecError(
"doubled \\M- (char %d of %s)" % (s + 1, repr(key))
)
meta = 1
s += 3
elif c.isdigit():
Expand All @@ -119,22 +123,25 @@ def _parse_key1(key, s):
elif c == '<':
t = key.find('>', s)
if t == -1:
raise KeySpecError, \
"unterminated \\< starting at char %d of %s"%(
s + 1, repr(key))
raise KeySpecError(
"unterminated \\< starting at char %d of %s"
% (s + 1, repr(key))
)
try:
ret = _keynames[key[s+2:t].lower()]
s = t + 1
except KeyError:
raise KeySpecError, \
"unrecognised keyname `%s' at char %d of %s"%(
key[s+2:t], s + 2, repr(key))
raise KeySpecError(
"unrecognised keyname `%s' at char %d of %s"
% (key[s + 2 : t], s + 2, repr(key))
)
if ret is None:
return None, s
else:
raise KeySpecError, \
"unknown backslash escape %s at char %d of %s"%(
`c`, s + 2, repr(key))
raise KeySpecError(
"unknown backslash escape %s at char %d of %s"
% (repr(c), s + 2, repr(key))
)
else:
if ctrl:
ret = chr(ord(key[s]) & 0x1f) # curses.ascii.ctrl()
Expand All @@ -160,9 +167,8 @@ def _compile_keymap(keymap):
r.setdefault(key[0], {})[key[1:]] = value
for key, value in r.items():
if value.has_key(()):
if len(value) <> 1:
raise KeySpecError, \
"key definitions for %s clash"%(value.values(),)
if len(value) != 1:
raise KeySpecError("key definitions for %s clash" % (value.values(),))
else:
r[key] = value[()]
else:
Expand Down Expand Up @@ -202,8 +208,8 @@ def unparse_key(keyseq):
return ''
name, s = keyname(keyseq)
if name:
if name <> 'escape' or s == len(keyseq):
return '\\<' + name + '>' + unparse_key(keyseq[s:])
if name != "escape" or s == len(keyseq):
return "\\<" + name + ">" + unparse_key(keyseq[s:])
else:
return '\\M-' + unparse_key(keyseq[1:])
else:
Expand All @@ -226,7 +232,7 @@ def _unparse_keyf(keyseq):
return []
name, s = keyname(keyseq)
if name:
if name <> 'escape' or s == len(keyseq):
if name != "escape" or s == len(keyseq):
return [name] + _unparse_keyf(keyseq[s:])
else:
rest = _unparse_keyf(keyseq[1:])
Expand Down