Skip to content

Commit

Permalink
Use pyparsing's locatedExpr instead of our custom helper
Browse files Browse the repository at this point in the history
Our locatedExpr helper was suggested by the author of pyparsing as a
way to get the location of a token. He added the feature to pyparsing
shortly after (version 2.0.2 more than 5 years ago), so there is no
reason to carry our own locatedExpr implementation.

For more context, see:

  http://stackoverflow.com/questions/18706631/pyparsing-get-token-location-in-results-name

Signed-off-by: Christophe Vu-Brugier <cvubrugier@fastmail.fm>
  • Loading branch information
cvubrugier committed Sep 7, 2019
1 parent 421ff99 commit 7b5ba2c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
21 changes: 8 additions & 13 deletions configshell/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
import os
import six
import sys
from pyparsing import (alphanums, Empty, Group, OneOrMore, Optional,
ParseResults, Regex, Suppress, Word)
from pyparsing import (alphanums, Empty, Group, locatedExpr,
OneOrMore, Optional, ParseResults, Regex,
Suppress, Word)

from . import console
from . import log
Expand Down Expand Up @@ -48,7 +49,7 @@ def handle_sigint(signum, frame):
tty=True
else:
tty=False

# remember the original setting
oldTerm = os.environ.get('TERM')
os.environ['TERM'] = ''
Expand All @@ -59,12 +60,6 @@ def handle_sigint(signum, frame):
if oldTerm != None:
os.environ['TERM'] = oldTerm
del oldTerm

# Pyparsing helper to group the location of a token and its value
# http://stackoverflow.com/questions/18706631/pyparsing-get-token-location-in-results-name
locator = Empty().setParseAction(lambda s, l, t: l)
def locatedExpr(expr):
return Group(locator('location') + expr('value'))

class ConfigShell(object):
'''
Expand Down Expand Up @@ -608,13 +603,13 @@ def _complete(self, text, state):
current_token = 'pparam'
elif 'x' in [x.value for x in parse_results.kparams]:
current_token = 'kparam'
elif path and beg == parse_results.path.location:
elif path and beg == parse_results.path.locn_start:
current_token = 'path'
elif command and beg == parse_results.command.location:
elif command and beg == parse_results.command.locn_start:
current_token = 'command'
elif pparams and beg in [p.location for p in parse_results.pparams]:
elif pparams and beg in [p.locn_start for p in parse_results.pparams]:
current_token = 'pparam'
elif kparams and beg in [k.location for k in parse_results.kparams]:
elif kparams and beg in [k.locn_start for k in parse_results.kparams]:
current_token = 'kparam'

self._current_completions = \
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
url = 'http://github.com/open-iscsi/configshell-fb',
packages = ['configshell', 'configshell_fb'],
install_requires = [
'pyparsing',
'pyparsing >= 2.0.2',
'six',
'urwid',
],
Expand Down

0 comments on commit 7b5ba2c

Please sign in to comment.