diff options
author | David Beazley <dave@dabeaz.com> | 2008-02-16 17:22:29 +0000 |
---|---|---|
committer | David Beazley <dave@dabeaz.com> | 2008-02-16 17:22:29 +0000 |
commit | 29c3673964f97bb8cc9446a44b93ff6087e0f6eb (patch) | |
tree | 573b65a848c51e801b2a3a53b1aab8dfe5235670 | |
parent | 5e4f1cca846a93e58dcef67786114c4e2ca4569d (diff) | |
download | ply-29c3673964f97bb8cc9446a44b93ff6087e0f6eb.tar.gz |
Modified input() to accept objects that appear to be strings (by returning characters as the result of a slice) as input. This allows mmap objects and other objects to be passed as input.
-rw-r--r-- | ply/lex.py | 4 |
1 files changed, 3 insertions, 1 deletions
@@ -200,7 +200,9 @@ class Lexer(object): # input() - Push a new string into the lexer # ------------------------------------------------------------ def input(self,s): - if not (isinstance(s,types.StringType) or isinstance(s,types.UnicodeType)): + # Pull off the first character to see if s looks like a string + c = s[:1] + if not (isinstance(c,types.StringType) or isinstance(c,types.UnicodeType)): raise ValueError, "Expected a string" self.lexdata = s self.lexpos = 0 |