import Util
+# FIXME: It would be nice to at least match a few other things like `...`, $(
+# ... ), $VAR, etc., if only so we can nicely say "we don't support this".
+
class ShLexer:
def __init__(self, data):
self.data = data
self.data)
return str
c = self.eat()
- if c != delim:
+ if c == '"': #
+ str += '"'
+ elif c == '\\':
str += '\\'
- str += c
+ else:
+ str += '\\' + c
else:
str += c
Util.warning("missing quote character in %r" % self.data)
return ('<&',)
if self.maybe_eat('>'):
return ('<<',)
+ return (c,)
return self.lex_arg(c)
return list(ShLexer(str).lex())
def test_basic(self):
- self.assertEqual(self.lex('a|b>c&d'),
- ['a', ('|',), 'b', ('>',), 'c', ('&',), 'd'])
+ self.assertEqual(self.lex('a|b>c&d<e'),
+ ['a', ('|',), 'b', ('>',), 'c', ('&',), 'd',
+ ('<',), 'e'])
def test_redirection_tokens(self):
self.assertEqual(self.lex('a2>c'),
['hello"world'])
self.assertEqual(self.lex(""" "hello\\'world" """),
["hello\\'world"])
+ self.assertEqual(self.lex(""" "hello\\\\world" """),
+ ["hello\\world"])
self.assertEqual(self.lex(""" he"llo wo"rld """),
["hello world"])