Minor cleanup.
This commit is contained in:
parent
7dbb3c69ed
commit
4827aa467e
|
|
@ -61,7 +61,7 @@ HELP_TEMPLATE = '''\
|
|||
|
||||
%s
|
||||
|
||||
---- end (%s)
|
||||
---- end ( %s )
|
||||
'''
|
||||
|
||||
|
||||
|
|
@ -331,12 +331,12 @@ def choice(stack):
|
|||
Use a Boolean value to select one of two items.
|
||||
::
|
||||
|
||||
A B False choice
|
||||
A B false choice
|
||||
----------------------
|
||||
A
|
||||
|
||||
|
||||
A B True choice
|
||||
A B true choice
|
||||
---------------------
|
||||
B
|
||||
|
||||
|
|
@ -354,12 +354,12 @@ def select(stack):
|
|||
Use a Boolean value to select one of two items from a sequence.
|
||||
::
|
||||
|
||||
[A B] False select
|
||||
[A B] false select
|
||||
------------------------
|
||||
A
|
||||
|
||||
|
||||
[A B] True select
|
||||
[A B] true select
|
||||
-----------------------
|
||||
B
|
||||
|
||||
|
|
|
|||
|
|
@ -111,20 +111,14 @@ def _parse(tokens):
|
|||
v = frame
|
||||
try: frame = stack.pop()
|
||||
except IndexError:
|
||||
raise ParseError('Extra closing bracket.')
|
||||
raise ParseError('Extra closing bracket.') from None
|
||||
frame.append(list_to_stack(v))
|
||||
elif tok == 'true':
|
||||
frame.append(True)
|
||||
elif tok == 'false':
|
||||
frame.append(False)
|
||||
elif isinstance(tok, Snippet):
|
||||
frame.append(tok)
|
||||
elif tok == 'true': frame.append(True)
|
||||
elif tok == 'false': frame.append(False)
|
||||
elif isinstance(tok, Snippet): frame.append(tok)
|
||||
else:
|
||||
try:
|
||||
thing = int(tok)
|
||||
except ValueError:
|
||||
thing = Symbol(tok)
|
||||
try: thing = int(tok)
|
||||
except ValueError: thing = Symbol(tok)
|
||||
frame.append(thing)
|
||||
if stack:
|
||||
raise ParseError('Unclosed bracket.')
|
||||
if stack: raise ParseError('Unclosed bracket.')
|
||||
return list_to_stack(frame)
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
from collections import namedtuple
|
||||
from re import compile as RE
|
||||
|
||||
|
||||
Snippet = namedtuple('Snippet', 'sha offset length')
|
||||
_fmt = '{%s %i %i}'
|
||||
|
||||
|
||||
pat = (
|
||||
'{'
|
||||
'\s*'
|
||||
|
|
@ -14,14 +16,18 @@ pat = (
|
|||
'\s*'
|
||||
'}'
|
||||
)
|
||||
|
||||
|
||||
_PAT = RE(pat)
|
||||
|
||||
|
||||
def to_string(snip):
|
||||
return _fmt % _ts(*snip)
|
||||
return _ts(*snip)
|
||||
|
||||
|
||||
def _ts(sha, offset, length):
|
||||
return sha.decode('ascii'), offset, length
|
||||
return f'{{{sha.decode("ascii")} {offset} {length}}}'
|
||||
|
||||
|
||||
def from_string(text):
|
||||
m = _PAT.match(text)
|
||||
|
|
@ -29,5 +35,6 @@ def from_string(text):
|
|||
raise ValueError
|
||||
return _fs(**m.groupdict())
|
||||
|
||||
|
||||
def _fs(sha, offset, length):
|
||||
return Snippet(sha.encode('ascii'), int(offset), int(length))
|
||||
|
|
|
|||
Loading…
Reference in New Issue