Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(810)

Side by Side Diff: bindings/scripts/blink_idl_lexer.py

Issue 581453002: Dartium Roll 38 roll (Closed) Base URL: https://dart.googlecode.com/svn/third_party/WebCore
Patch Set: Sync'd w/ r 182210 Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « bindings/scripts/aggregate_generated_bindings.py ('k') | bindings/scripts/blink_idl_parser.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 third_party = os.path.join(module_path, os.pardir, os.pardir, os.pardir, os.pard ir) 62 third_party = os.path.join(module_path, os.pardir, os.pardir, os.pardir, os.pard ir)
63 # Insert at front to override system libraries, and after path[0] == script dir 63 # Insert at front to override system libraries, and after path[0] == script dir
64 sys.path.insert(1, third_party) 64 sys.path.insert(1, third_party)
65 from ply import lex 65 from ply import lex
66 66
67 # Base lexer is in Chromium src/tools/idl_parser 67 # Base lexer is in Chromium src/tools/idl_parser
68 tools_dir = os.path.join(third_party, os.pardir, 'tools') 68 tools_dir = os.path.join(third_party, os.pardir, 'tools')
69 sys.path.append(tools_dir) 69 sys.path.append(tools_dir)
70 from idl_parser.idl_lexer import IDLLexer 70 from idl_parser.idl_lexer import IDLLexer
71 71
72 LEXTAB = 'lextab'
72 REMOVE_TOKENS = ['COMMENT'] 73 REMOVE_TOKENS = ['COMMENT']
73 74
74 75
75 class BlinkIDLLexer(IDLLexer): 76 class BlinkIDLLexer(IDLLexer):
76 # ignore comments 77 # ignore comments
77 def t_COMMENT(self, t): 78 def t_COMMENT(self, t):
78 r'(/\*(.|\n)*?\*/)|(//.*(\n[ \t]*//.*)*)' 79 r'(/\*(.|\n)*?\*/)|(//.*(\n[ \t]*//.*)*)'
79 self.AddLines(t.value.count('\n')) 80 self.AddLines(t.value.count('\n'))
80 81
81 # Analogs to _AddToken/_AddTokens in base lexer 82 # Analogs to _AddToken/_AddTokens in base lexer
82 # Needed to remove COMMENT token, since comments ignored 83 # Needed to remove COMMENT token, since comments ignored
83 def _RemoveToken(self, token): 84 def _RemoveToken(self, token):
84 if token in self.tokens: 85 if token in self.tokens:
85 self.tokens.remove(token) 86 self.tokens.remove(token)
86 87
87 def _RemoveTokens(self, tokens): 88 def _RemoveTokens(self, tokens):
88 for token in tokens: 89 for token in tokens:
89 self._RemoveToken(token) 90 self._RemoveToken(token)
90 91
91 def __init__(self, debug=False, optimize=True, outputdir=None): 92 def __init__(self, debug=False, optimize=True, outputdir=None,
93 rewrite_tables=False):
92 if debug: 94 if debug:
93 # Turn off optimization and caching to help debugging 95 # Turn off optimization and caching to help debugging
94 optimize = False 96 optimize = False
95 outputdir = None 97 outputdir = None
96 if outputdir: 98 if outputdir:
97 # Need outputdir in path because lex imports the cached lex table 99 # Need outputdir in path because lex imports the cached lex table
98 # as a Python module 100 # as a Python module
99 sys.path.append(outputdir) 101 sys.path.append(outputdir)
100 102
103 if rewrite_tables:
104 tablefile_root = os.path.join(outputdir, LEXTAB)
105 # Also remove the .pyc/.pyo files, or they'll be used even if
106 # the .py file doesn't exist.
107 for ext in ('.py', '.pyc', '.pyo'):
108 try:
109 os.unlink(tablefile_root + ext)
110 except OSError:
111 pass
112
101 IDLLexer.__init__(self) 113 IDLLexer.__init__(self)
102 # Overrides to parent class 114 # Overrides to parent class
103 self._RemoveTokens(REMOVE_TOKENS) 115 self._RemoveTokens(REMOVE_TOKENS)
104 # Optimized mode substantially decreases startup time (by disabling 116 # Optimized mode substantially decreases startup time (by disabling
105 # error checking), and also allows use of Python's optimized mode. 117 # error checking), and also allows use of Python's optimized mode.
106 # See: Optimized Mode 118 # See: Optimized Mode
107 # http://www.dabeaz.com/ply/ply.html#ply_nn15 119 # http://www.dabeaz.com/ply/ply.html#ply_nn15
108 self._lexobj = lex.lex(object=self, 120 self._lexobj = lex.lex(object=self,
109 debug=debug, 121 debug=debug,
110 optimize=optimize, 122 optimize=optimize,
123 lextab=LEXTAB,
111 outputdir=outputdir) 124 outputdir=outputdir)
112 125
113 126
114 ################################################################################ 127 ################################################################################
115 128
116 def main(argv): 129 def main(argv):
117 # If file itself executed, build and cache lex table 130 # If file itself executed, build and cache lex table
118 try: 131 try:
119 outputdir = argv[1] 132 outputdir = argv[1]
120 except IndexError as err: 133 except IndexError as err:
121 print 'Usage: %s OUTPUT_DIR' % argv[0] 134 print 'Usage: %s OUTPUT_DIR' % argv[0]
122 return 1 135 return 1
123 lexer = BlinkIDLLexer(outputdir=outputdir) 136 # 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
138 # the parse table.
139 lexer = BlinkIDLLexer(outputdir=outputdir, rewrite_tables=True)
124 140
125 141
126 if __name__ == '__main__': 142 if __name__ == '__main__':
127 sys.exit(main(sys.argv)) 143 sys.exit(main(sys.argv))
OLDNEW
« no previous file with comments | « bindings/scripts/aggregate_generated_bindings.py ('k') | bindings/scripts/blink_idl_parser.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698