OLD | NEW |
1 # Copyright (C) 2013 Google Inc. All rights reserved. | 1 # Copyright (C) 2013 Google Inc. All rights reserved. |
2 # | 2 # |
3 # Redistribution and use in source and binary forms, with or without | 3 # Redistribution and use in source and binary forms, with or without |
4 # modification, are permitted provided that the following conditions are | 4 # modification, are permitted provided that the following conditions are |
5 # met: | 5 # met: |
6 # | 6 # |
7 # * Redistributions of source code must retain the above copyright | 7 # * Redistributions of source code must retain the above copyright |
8 # notice, this list of conditions and the following disclaimer. | 8 # notice, this list of conditions and the following disclaimer. |
9 # * Redistributions in binary form must reproduce the above | 9 # * Redistributions in binary form must reproduce the above |
10 # copyright notice, this list of conditions and the following disclaimer | 10 # copyright notice, this list of conditions and the following disclaimer |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 if rewrite_tables: | 103 if rewrite_tables: |
104 tablefile_root = os.path.join(outputdir, LEXTAB) | 104 tablefile_root = os.path.join(outputdir, LEXTAB) |
105 # Also remove the .pyc/.pyo files, or they'll be used even if | 105 # Also remove the .pyc/.pyo files, or they'll be used even if |
106 # the .py file doesn't exist. | 106 # the .py file doesn't exist. |
107 for ext in ('.py', '.pyc', '.pyo'): | 107 for ext in ('.py', '.pyc', '.pyo'): |
108 try: | 108 try: |
109 os.unlink(tablefile_root + ext) | 109 os.unlink(tablefile_root + ext) |
110 except OSError: | 110 except OSError: |
111 pass | 111 pass |
112 | 112 |
| 113 lextab = LEXTAB |
| 114 else: |
| 115 lextab = None |
| 116 |
113 IDLLexer.__init__(self) | 117 IDLLexer.__init__(self) |
114 # Overrides to parent class | 118 # Overrides to parent class |
115 self._RemoveTokens(REMOVE_TOKENS) | 119 self._RemoveTokens(REMOVE_TOKENS) |
116 # Optimized mode substantially decreases startup time (by disabling | 120 # Optimized mode substantially decreases startup time (by disabling |
117 # error checking), and also allows use of Python's optimized mode. | 121 # error checking), and also allows use of Python's optimized mode. |
118 # See: Optimized Mode | 122 # See: Optimized Mode |
119 # http://www.dabeaz.com/ply/ply.html#ply_nn15 | 123 # http://www.dabeaz.com/ply/ply.html#ply_nn15 |
120 self._lexobj = lex.lex(object=self, | 124 self._lexobj = lex.lex(object=self, |
121 debug=debug, | 125 debug=debug, |
122 optimize=optimize, | 126 optimize=optimize, |
123 lextab=LEXTAB, | 127 lextab=lextab, |
124 outputdir=outputdir) | 128 outputdir=outputdir) |
125 | 129 |
126 | 130 |
127 ################################################################################ | 131 ################################################################################ |
128 | 132 |
129 def main(argv): | 133 def main(argv): |
130 # If file itself executed, build and cache lex table | 134 # If file itself executed, build and cache lex table |
131 try: | 135 try: |
132 outputdir = argv[1] | 136 outputdir = argv[1] |
133 except IndexError as err: | 137 except IndexError as err: |
134 print 'Usage: %s OUTPUT_DIR' % argv[0] | 138 print 'Usage: %s OUTPUT_DIR' % argv[0] |
135 return 1 | 139 return 1 |
136 # Important: rewrite_tables=True causes the cache file to be deleted if it | 140 # Important: rewrite_tables=True causes the cache file to be deleted if it |
137 # exists, thus making sure that PLY doesn't load it instead of regenerating | 141 # exists, thus making sure that PLY doesn't load it instead of regenerating |
138 # the parse table. | 142 # the parse table. |
139 lexer = BlinkIDLLexer(outputdir=outputdir, rewrite_tables=True) | 143 lexer = BlinkIDLLexer(outputdir=outputdir, rewrite_tables=True) |
140 | 144 |
141 | 145 |
142 if __name__ == '__main__': | 146 if __name__ == '__main__': |
143 sys.exit(main(sys.argv)) | 147 sys.exit(main(sys.argv)) |
OLD | NEW |