Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/dabeaz/ply
Browse files Browse the repository at this point in the history
  • Loading branch information
dabeaz committed Feb 15, 2018
2 parents 5d54440 + 807d381 commit e8c6af0
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ply/lex.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def writetab(self, lextab, outputdir=''):
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))

Expand Down
26 changes: 26 additions & 0 deletions test/lex_optimize4.py
Original file line number Diff line number Diff line change
@@ -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")
20 changes: 20 additions & 0 deletions test/testlex.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,26 @@ def test_lex_optimize3(self):
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")
Expand Down

0 comments on commit e8c6af0

Please sign in to comment.