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 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 return ls[1].value | 373 return ls[1].value |
374 | 374 |
375 if len(p) > 3: | 375 if len(p) > 3: |
376 p[0] = unwrap_string(p[1]) + p[2] + p[3] | 376 p[0] = unwrap_string(p[1]) + p[2] + p[3] |
377 else: | 377 else: |
378 p[0] = unwrap_string(p[1]) | 378 p[0] = unwrap_string(p[1]) |
379 | 379 |
380 def __init__(self, | 380 def __init__(self, |
381 # common parameters | 381 # common parameters |
382 debug=False, | 382 debug=False, |
| 383 # local parameters |
| 384 rewrite_tables=False, |
383 # idl_parser parameters | 385 # idl_parser parameters |
384 lexer=None, verbose=False, mute_error=False, | 386 lexer=None, verbose=False, mute_error=False, |
385 # yacc parameters | 387 # yacc parameters |
386 outputdir='', optimize=True, write_tables=False, | 388 outputdir='', optimize=True, write_tables=False, |
387 picklefile=None): | 389 picklefile=None): |
388 if debug: | 390 if debug: |
389 # Turn off optimization and caching, and write out tables, | 391 # Turn off optimization and caching, and write out tables, |
390 # to help debugging | 392 # to help debugging |
391 optimize = False | 393 optimize = False |
392 outputdir = None | 394 outputdir = None |
393 picklefile = None | 395 picklefile = None |
394 write_tables = True | 396 write_tables = True |
395 if outputdir: | 397 if outputdir: |
396 picklefile = picklefile or os.path.join(outputdir, 'parsetab.pickle'
) | 398 picklefile = picklefile or os.path.join(outputdir, 'parsetab.pickle'
) |
| 399 if rewrite_tables: |
| 400 try: |
| 401 os.unlink(picklefile) |
| 402 except OSError: |
| 403 pass |
397 | 404 |
398 lexer = lexer or BlinkIDLLexer(debug=debug, | 405 lexer = lexer or BlinkIDLLexer(debug=debug, |
399 outputdir=outputdir, | 406 outputdir=outputdir, |
400 optimize=optimize) | 407 optimize=optimize) |
401 self.lexer = lexer | 408 self.lexer = lexer |
402 self.tokens = lexer.KnownTokens() | 409 self.tokens = lexer.KnownTokens() |
403 # Using SLR (instead of LALR) generates the table faster, | 410 # Using SLR (instead of LALR) generates the table faster, |
404 # but produces the same output. This is ok b/c Web IDL (and Blink IDL) | 411 # but produces the same output. This is ok b/c Web IDL (and Blink IDL) |
405 # is an SLR grammar (as is often the case for simple LL(1) grammars). | 412 # is an SLR grammar (as is often the case for simple LL(1) grammars). |
406 # | 413 # |
(...skipping 25 matching lines...) Expand all Loading... |
432 | 439 |
433 ################################################################################ | 440 ################################################################################ |
434 | 441 |
435 def main(argv): | 442 def main(argv): |
436 # If file itself executed, cache parse table | 443 # If file itself executed, cache parse table |
437 try: | 444 try: |
438 outputdir = argv[1] | 445 outputdir = argv[1] |
439 except IndexError as err: | 446 except IndexError as err: |
440 print 'Usage: %s OUTPUT_DIR' % argv[0] | 447 print 'Usage: %s OUTPUT_DIR' % argv[0] |
441 return 1 | 448 return 1 |
442 parser = BlinkIDLParser(outputdir=outputdir) | 449 # Important: rewrite_tables=True causes the cache file to be deleted if it |
| 450 # exists, thus making sure that PLY doesn't load it instead of regenerating |
| 451 # the parse table. |
| 452 parser = BlinkIDLParser(outputdir=outputdir, rewrite_tables=True) |
443 | 453 |
444 | 454 |
445 if __name__ == '__main__': | 455 if __name__ == '__main__': |
446 sys.exit(main(sys.argv)) | 456 sys.exit(main(sys.argv)) |
OLD | NEW |