Index: bindings/scripts/blink_idl_lexer.py |
diff --git a/bindings/scripts/blink_idl_lexer.py b/bindings/scripts/blink_idl_lexer.py |
index bbde34268b44c0b97fd797d19523eef48f586005..ba68c6c7dce1f27fee35f768d536401abfe5520b 100644 |
--- a/bindings/scripts/blink_idl_lexer.py |
+++ b/bindings/scripts/blink_idl_lexer.py |
@@ -69,6 +69,7 @@ tools_dir = os.path.join(third_party, os.pardir, 'tools') |
sys.path.append(tools_dir) |
from idl_parser.idl_lexer import IDLLexer |
+LEXTAB = 'lextab' |
REMOVE_TOKENS = ['COMMENT'] |
@@ -88,7 +89,8 @@ class BlinkIDLLexer(IDLLexer): |
for token in tokens: |
self._RemoveToken(token) |
- def __init__(self, debug=False, optimize=True, outputdir=None): |
+ def __init__(self, debug=False, optimize=True, outputdir=None, |
+ rewrite_tables=False): |
if debug: |
# Turn off optimization and caching to help debugging |
optimize = False |
@@ -98,6 +100,16 @@ class BlinkIDLLexer(IDLLexer): |
# as a Python module |
sys.path.append(outputdir) |
+ if rewrite_tables: |
+ tablefile_root = os.path.join(outputdir, LEXTAB) |
+ # Also remove the .pyc/.pyo files, or they'll be used even if |
+ # the .py file doesn't exist. |
+ for ext in ('.py', '.pyc', '.pyo'): |
+ try: |
+ os.unlink(tablefile_root + ext) |
+ except OSError: |
+ pass |
+ |
IDLLexer.__init__(self) |
# Overrides to parent class |
self._RemoveTokens(REMOVE_TOKENS) |
@@ -108,6 +120,7 @@ class BlinkIDLLexer(IDLLexer): |
self._lexobj = lex.lex(object=self, |
debug=debug, |
optimize=optimize, |
+ lextab=LEXTAB, |
outputdir=outputdir) |
@@ -120,7 +133,10 @@ def main(argv): |
except IndexError as err: |
print 'Usage: %s OUTPUT_DIR' % argv[0] |
return 1 |
- lexer = BlinkIDLLexer(outputdir=outputdir) |
+ # Important: rewrite_tables=True causes the cache file to be deleted if it |
+ # exists, thus making sure that PLY doesn't load it instead of regenerating |
+ # the parse table. |
+ lexer = BlinkIDLLexer(outputdir=outputdir, rewrite_tables=True) |
if __name__ == '__main__': |