mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 16:34:47 +01:00
Require whitespace for and/or tokens in subproc mode
This commit is contained in:
parent
8920cc3d4e
commit
cefd8d395d
3 changed files with 98 additions and 3 deletions
16
news/ao.rst
Normal file
16
news/ao.rst
Normal file
|
@ -0,0 +1,16 @@
|
|||
**Added:** None
|
||||
|
||||
**Changed:**
|
||||
|
||||
* The literal tokens ``and`` and ``or`` must be surrounded by
|
||||
whitespace to delimit subprocess mode. If they do not have
|
||||
whitespace on both sides in subproc mode, they are condisered
|
||||
to be part of a command argument.
|
||||
|
||||
**Deprecated:** None
|
||||
|
||||
**Removed:** None
|
||||
|
||||
**Fixed:** None
|
||||
|
||||
**Security:** None
|
|
@ -169,6 +169,82 @@ def test_ampersand():
|
|||
assert check_token('&', ['AMPERSAND', '&', 0])
|
||||
|
||||
|
||||
def test_not_really_and_pre():
|
||||
inp = "![foo-and]"
|
||||
exp = [
|
||||
('BANG_LBRACKET', '![', 0),
|
||||
('NAME', 'foo', 2),
|
||||
('MINUS', '-', 5),
|
||||
('NAME', 'and', 6),
|
||||
('RBRACKET', ']', 9),
|
||||
]
|
||||
assert check_tokens(inp, exp)
|
||||
|
||||
|
||||
def test_not_really_and_post():
|
||||
inp = "![and-bar]"
|
||||
exp = [
|
||||
('BANG_LBRACKET', '![', 0),
|
||||
('NAME', 'and', 2),
|
||||
('MINUS', '-', 5),
|
||||
('NAME', 'bar', 6),
|
||||
('RBRACKET', ']', 9),
|
||||
]
|
||||
assert check_tokens(inp, exp)
|
||||
|
||||
|
||||
def test_not_really_and_pre_post():
|
||||
inp = "![foo-and-bar]"
|
||||
exp = [
|
||||
('BANG_LBRACKET', '![', 0),
|
||||
('NAME', 'foo', 2),
|
||||
('MINUS', '-', 5),
|
||||
('NAME', 'and', 6),
|
||||
('MINUS', '-', 9),
|
||||
('NAME', 'bar', 10),
|
||||
('RBRACKET', ']', 13),
|
||||
]
|
||||
assert check_tokens(inp, exp)
|
||||
|
||||
|
||||
def test_not_really_or_pre():
|
||||
inp = "![foo-or]"
|
||||
exp = [
|
||||
('BANG_LBRACKET', '![', 0),
|
||||
('NAME', 'foo', 2),
|
||||
('MINUS', '-', 5),
|
||||
('NAME', 'or', 6),
|
||||
('RBRACKET', ']', 8),
|
||||
]
|
||||
assert check_tokens(inp, exp)
|
||||
|
||||
|
||||
def test_not_really_or_post():
|
||||
inp = "![or-bar]"
|
||||
exp = [
|
||||
('BANG_LBRACKET', '![', 0),
|
||||
('NAME', 'or', 2),
|
||||
('MINUS', '-', 4),
|
||||
('NAME', 'bar', 5),
|
||||
('RBRACKET', ']', 8),
|
||||
]
|
||||
assert check_tokens(inp, exp)
|
||||
|
||||
|
||||
def test_not_really_or_pre_post():
|
||||
inp = "![foo-or-bar]"
|
||||
exp = [
|
||||
('BANG_LBRACKET', '![', 0),
|
||||
('NAME', 'foo', 2),
|
||||
('MINUS', '-', 5),
|
||||
('NAME', 'or', 6),
|
||||
('MINUS', '-', 8),
|
||||
('NAME', 'bar', 9),
|
||||
('RBRACKET', ']', 12),
|
||||
]
|
||||
assert check_tokens(inp, exp)
|
||||
|
||||
|
||||
def test_atdollar():
|
||||
assert check_token('@$', ['ATDOLLAR', '@$', 0])
|
||||
|
||||
|
|
|
@ -69,15 +69,18 @@ def token_map():
|
|||
def handle_name(state, token):
|
||||
"""Function for handling name tokens"""
|
||||
typ = 'NAME'
|
||||
state['last'] = token
|
||||
if state['pymode'][-1][0]:
|
||||
if token.string in kwmod.kwlist:
|
||||
typ = token.string.upper()
|
||||
state['last'] = token
|
||||
yield _new_token(typ, token.string, token.start)
|
||||
else:
|
||||
if token.string == 'and':
|
||||
prev = state['last']
|
||||
state['last'] = token
|
||||
has_whitespace = prev.end != token.start
|
||||
if token.string == 'and' and has_whitespace:
|
||||
yield _new_token('AND', token.string, token.start)
|
||||
elif token.string == 'or':
|
||||
elif token.string == 'or' and has_whitespace:
|
||||
yield _new_token('OR', token.string, token.start)
|
||||
else:
|
||||
yield _new_token('NAME', token.string, token.start)
|
||||
|
|
Loading…
Add table
Reference in a new issue