summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Beazley <dave@dabeaz.com>2018-02-15 12:27:19 -0600
committerGitHub <noreply@github.com>2018-02-15 12:27:19 -0600
commit807d3816a2639b41ae48ab062d8885e1f006d920 (patch)
tree0db7290eecff535d51565679059a222efeac63f0
parent6860652be4069eaac8be88af1400f69a5197284f (diff)
parente678d756427c72edd1b0107c55fd10640d8ffe2b (diff)
downloadply-807d3816a2639b41ae48ab062d8885e1f006d920.tar.gz
Merge pull request #153 from astrofrog/fix-reflags-python3
Fix Python 3.6 bug with re module flags
-rw-r--r--ply/lex.py2
-rw-r--r--test/lex_optimize4.py26
-rwxr-xr-xtest/testlex.py20
3 files changed, 47 insertions, 1 deletions
diff --git a/ply/lex.py b/ply/lex.py
index 65deefe..39f6d0d 100644
--- a/ply/lex.py
+++ b/ply/lex.py
@@ -180,7 +180,7 @@ class Lexer:
tf.write('# %s.py. This file automatically created by PLY (version %s). Don\'t edit!\n' % (basetabmodule, __version__))
tf.write('_tabversion = %s\n' % repr(__tabversion__))
tf.write('_lextokens = set(%s)\n' % repr(tuple(self.lextokens)))
- tf.write('_lexreflags = %s\n' % repr(self.lexreflags))
+ tf.write('_lexreflags = %s\n' % repr(int(self.lexreflags)))
tf.write('_lexliterals = %s\n' % repr(self.lexliterals))
tf.write('_lexstateinfo = %s\n' % repr(self.lexstateinfo))
diff --git a/test/lex_optimize4.py b/test/lex_optimize4.py
new file mode 100644
index 0000000..cc6e2a9
--- /dev/null
+++ b/test/lex_optimize4.py
@@ -0,0 +1,26 @@
+# -----------------------------------------------------------------------------
+# lex_optimize4.py
+# -----------------------------------------------------------------------------
+import re
+import sys
+
+if ".." not in sys.path: sys.path.insert(0,"..")
+import ply.lex as lex
+
+tokens = [
+ "PLUS",
+ "MINUS",
+ "NUMBER",
+ ]
+
+t_PLUS = r'\+?'
+t_MINUS = r'-'
+t_NUMBER = r'(\d+)'
+
+def t_error(t):
+ pass
+
+
+# Build the lexer
+lex.lex(optimize=True, lextab="opt4tab", reflags=re.UNICODE)
+lex.runmain(data="3+4")
diff --git a/test/testlex.py b/test/testlex.py
index 3880f6f..83070a7 100755
--- a/test/testlex.py
+++ b/test/testlex.py
@@ -514,6 +514,26 @@ class LexBuildOptionTests(unittest.TestCase):
except OSError:
pass
+ def test_lex_optimize4(self):
+
+ # Regression test to make sure that reflags works correctly
+ # on Python 3.
+
+ for extension in ['py', 'pyc']:
+ try:
+ os.remove("opt4tab.{0}".format(extension))
+ except OSError:
+ pass
+
+ run_import("lex_optimize4")
+ run_import("lex_optimize4")
+
+ for extension in ['py', 'pyc']:
+ try:
+ os.remove("opt4tab.{0}".format(extension))
+ except OSError:
+ pass
+
def test_lex_opt_alias(self):
try:
os.remove("aliastab.py")