summaryrefslogtreecommitdiff
path: root/ply
diff options
context:
space:
mode:
authorDavid Beazley <dave@dabeaz.com>2008-02-16 17:22:29 +0000
committerDavid Beazley <dave@dabeaz.com>2008-02-16 17:22:29 +0000
commit29c3673964f97bb8cc9446a44b93ff6087e0f6eb (patch)
tree573b65a848c51e801b2a3a53b1aab8dfe5235670 /ply
parent5e4f1cca846a93e58dcef67786114c4e2ca4569d (diff)
downloadply-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.
Diffstat (limited to 'ply')
-rw-r--r--ply/lex.py4
1 files changed, 3 insertions, 1 deletions
diff --git a/ply/lex.py b/ply/lex.py
index 24908b4..dd85bac 100644
--- a/ply/lex.py
+++ b/ply/lex.py
@@ -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