Skip to content

Commit 1f4853d

Browse files
committed
Use pygments instead of pyparsing for argspec
This will remove the dependency on pyparsing.
1 parent 5bece9d commit 1f4853d

File tree

2 files changed

+16
-48
lines changed

2 files changed

+16
-48
lines changed

README

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ bpython - A fancy curses interface to the Python interactive interpreter
44
Dependencies
55
============
66
Pygments
7-
pyparsing
8-
(apt-get install python-pyparsing python-pygments)
7+
(apt-get install python-pygments)
98

109
Introduction
1110
============

bpython/cli.py

Lines changed: 15 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,6 @@
6262
# This for import completion
6363
from bpython import importcompletion
6464

65-
# And these are used for argspec.
66-
from pyparsing import Forward, Suppress, QuotedString, dblQuotedString, \
67-
Group, OneOrMore, ZeroOrMore, Literal, Optional, Word, \
68-
alphas, alphanums, printables, ParseException
69-
7065
from bpython import __version__
7166

7267
def log(x):
@@ -331,17 +326,6 @@ def __init__(self, scr, interp, statusbar=None, idle=None):
331326
'ignore') as hfile:
332327
self.rl_hist = hfile.readlines()
333328

334-
pexp = Forward()
335-
chars = printables.replace('(', '')
336-
chars = chars.replace(')', '')
337-
pexpnest = (
338-
Optional(Word(chars)) +
339-
Literal("(") +
340-
Optional(Group(pexp)) +
341-
Optional(Literal(")")))
342-
pexp << (OneOrMore(Word(chars) | pexpnest))
343-
self.pparser = pexp
344-
345329
def attr_matches(self, text):
346330
"""Taken from rlcompleter.py and bent to my will."""
347331

@@ -489,39 +473,24 @@ def getargspec(func):
489473
# This happens if no __init__ is found
490474
return None
491475

492-
def parse_parens(s):
493-
"""Run a string through the pyparsing pattern for paren
494-
counting."""
495-
496-
try:
497-
parsed = self.pparser.parseString(s).asList()
498-
except ParseException:
499-
return False
500-
501-
return parsed
502-
503-
def walk(seq):
504-
"""Walk a nested list and return the last list found that
505-
doesn't have a close paren in it (i.e. the active function)"""
506-
r = None
507-
if isinstance(seq, list):
508-
if ")" not in seq and "(" in seq:
509-
r = seq[seq.index('(') - 1]
510-
for i in seq:
511-
t = walk(i)
512-
if t:
513-
r = t
514-
return r
515-
516476
if not OPTS.arg_spec:
517477
return False
518478

519-
t = parse_parens(self.s)
520-
if not t:
521-
return False
522-
523-
func = walk(t)
524-
if not func:
479+
stack = ['']
480+
try:
481+
for (token, value) in PythonLexer().get_tokens(self.s):
482+
if token is Token.Punctuation:
483+
if value == '(':
484+
stack.append('')
485+
elif value == ')':
486+
stack.pop()
487+
elif (token is Token.Name or token in Token.Name.subtypes or
488+
token is Token.Operatir and value == '.'):
489+
stack[-1] += value
490+
else:
491+
stack[-1] = ''
492+
func = stack.pop() or stack.pop()
493+
except IndexError:
525494
return False
526495

527496
return getargspec(func)

0 commit comments

Comments
 (0)