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

Side by Side Diff: third_party/WebKit/Source/bindings/scripts/utilities.py

Issue 2397363002: Replace hand-written IDBObserverCallback with auto-generated code (Closed)
Patch Set: Created 4 years, 2 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
OLDNEW
1 # Copyright 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """Utility functions (file reading, simple IDL parsing by regexes) for IDL build . 5 """Utility functions (file reading, simple IDL parsing by regexes) for IDL build .
6 6
7 Design doc: http://www.chromium.org/developers/design-documents/idl-build 7 Design doc: http://www.chromium.org/developers/design-documents/idl-build
8 """ 8 """
9 9
10 import os 10 import os
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 except Exception: 327 except Exception:
328 # If trouble unpickling, overwrite 328 # If trouble unpickling, overwrite
329 pass 329 pass
330 with open(pickle_filename, 'w') as pickle_file: 330 with open(pickle_filename, 'w') as pickle_file:
331 pickle.dump(data, pickle_file) 331 pickle.dump(data, pickle_file)
332 332
333 333
334 ################################################################################ 334 ################################################################################
335 # IDL parsing 335 # IDL parsing
336 # 336 #
337 # We use regular expressions for parsing; this is incorrect (Web IDL is not a 337 # TODO(bashi) We use regular expressions for parsing; this is incorrect
338 # regular language), but simple and sufficient in practice. 338 # (Web IDL is not a regular language), and broken. Remove these functions and
339 # always use the parser and ASTs.
339 # Leading and trailing context (e.g. following '{') used to avoid false matches. 340 # Leading and trailing context (e.g. following '{') used to avoid false matches.
340 ################################################################################ 341 ################################################################################
341 342
342 def is_callback_interface_from_idl(file_contents): 343 def is_callback_interface_from_idl(file_contents):
343 match = re.search(r'callback\s+interface\s+\w+\s*{', file_contents) 344 match = re.search(r'callback\s+interface\s+\w+\s*{', file_contents)
344 return bool(match) 345 return bool(match)
345 346
346 347
347 def should_generate_impl_file_from_idl(file_contents): 348 def should_generate_impl_file_from_idl(file_contents):
348 """True when a given IDL file contents could generate .h/.cpp files.""" 349 """True when a given IDL file contents could generate .h/.cpp files."""
349 # FIXME: This would be error-prone and we should use AST rather than 350 # FIXME: This would be error-prone and we should use AST rather than
350 # improving the regexp pattern. 351 # improving the regexp pattern.
351 match = re.search(r'(interface|dictionary|exception)\s+\w+', file_contents) 352 match = re.search(r'(interface|dictionary|exception)\s+\w+', file_contents)
352 return bool(match) 353 return bool(match)
353 354
354 355
355 def match_interface_extended_attributes_from_idl(file_contents): 356 def match_interface_extended_attributes_from_idl(file_contents):
356 # Strip comments 357 # Strip comments
357 # re.compile needed b/c Python 2.6 doesn't support flags in re.sub 358 # re.compile needed b/c Python 2.6 doesn't support flags in re.sub
358 single_line_comment_re = re.compile(r'//.*$', flags=re.MULTILINE) 359 single_line_comment_re = re.compile(r'//.*$', flags=re.MULTILINE)
359 block_comment_re = re.compile(r'/\*.*?\*/', flags=re.MULTILINE | re.DOTALL) 360 block_comment_re = re.compile(r'/\*.*?\*/', flags=re.MULTILINE | re.DOTALL)
360 file_contents = re.sub(single_line_comment_re, '', file_contents) 361 file_contents = re.sub(single_line_comment_re, '', file_contents)
361 file_contents = re.sub(block_comment_re, '', file_contents) 362 file_contents = re.sub(block_comment_re, '', file_contents)
362 363
363 match = re.search(r'\[(.*)\]\s*' 364 match = re.search(
bashi 2016/10/07 07:07:26 This regexp is totally broken and doesn't work fol
364 r'((callback|partial)\s+)?' 365 r'\[([^[]*)\]\s*'
365 r'(interface|exception)\s+' 366 r'(interface|callback\s+interface|partial\s+interface|exception)\s+'
366 r'\w+\s*' 367 r'\w+\s*'
367 r'(:\s*\w+\s*)?' 368 r'(:\s*\w+\s*)?'
368 r'{', 369 r'{',
369 file_contents, flags=re.DOTALL) 370 file_contents, flags=re.DOTALL)
370 return match 371 return match
371 372
372
373 def get_interface_extended_attributes_from_idl(file_contents): 373 def get_interface_extended_attributes_from_idl(file_contents):
374 match = match_interface_extended_attributes_from_idl(file_contents) 374 match = match_interface_extended_attributes_from_idl(file_contents)
375 if not match: 375 if not match:
376 return {} 376 return {}
377 377
378 extended_attributes_string = match.group(1) 378 extended_attributes_string = match.group(1)
379 extended_attributes = {} 379 extended_attributes = {}
380 # FIXME: this splitting is WRONG: it fails on extended attributes where list s of 380 # FIXME: this splitting is WRONG: it fails on extended attributes where list s of
381 # multiple values are used, which are seperated by a comma and a space. 381 # multiple values are used, which are seperated by a comma and a space.
382 parts = [extended_attribute.strip() 382 parts = [extended_attribute.strip()
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 510
511 # Remember an open brace. 511 # Remember an open brace.
512 match = re_last_brace.search(line) 512 match = re_last_brace.search(line)
513 was_open_brace = (match and match.group('last') == '{' and 'namespace' n ot in line) 513 was_open_brace = (match and match.group('last') == '{' and 'namespace' n ot in line)
514 514
515 # Let |'\n'.join| emit the last newline. 515 # Let |'\n'.join| emit the last newline.
516 if output: 516 if output:
517 output.append('') 517 output.append('')
518 518
519 return '\n'.join(output) 519 return '\n'.join(output)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698