| OLD | NEW |
| 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 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 | 337 |
| 338 ################################################################################ | 338 ################################################################################ |
| 339 # IDL parsing | 339 # IDL parsing |
| 340 # | 340 # |
| 341 # TODO(bashi): We use regular expressions for parsing; this is incorrect | 341 # TODO(bashi): We use regular expressions for parsing; this is incorrect |
| 342 # (Web IDL is not a regular language) and broken. Remove these functions and | 342 # (Web IDL is not a regular language) and broken. Remove these functions and |
| 343 # always use the parser and ASTs. | 343 # always use the parser and ASTs. |
| 344 # Leading and trailing context (e.g. following '{') used to avoid false matches. | 344 # Leading and trailing context (e.g. following '{') used to avoid false matches. |
| 345 ################################################################################ | 345 ################################################################################ |
| 346 | 346 |
| 347 def is_callback_interface_from_idl(file_contents): | 347 def is_non_legacy_callback_interface_from_idl(file_contents): |
| 348 """Returns True if the specified IDL is a non-legacy callback interface.""" |
| 348 match = re.search(r'callback\s+interface\s+\w+\s*{', file_contents) | 349 match = re.search(r'callback\s+interface\s+\w+\s*{', file_contents) |
| 349 return bool(match) | 350 # Having constants means it's a legacy callback interface. |
| 351 # https://heycam.github.io/webidl/#legacy-callback-interface-object |
| 352 return bool(match) and not re.search(r'\s+const\b', file_contents) |
| 350 | 353 |
| 351 | 354 |
| 352 def should_generate_impl_file_from_idl(file_contents): | 355 def should_generate_impl_file_from_idl(file_contents): |
| 353 """True when a given IDL file contents could generate .h/.cpp files.""" | 356 """True when a given IDL file contents could generate .h/.cpp files.""" |
| 354 # FIXME: This would be error-prone and we should use AST rather than | 357 # FIXME: This would be error-prone and we should use AST rather than |
| 355 # improving the regexp pattern. | 358 # improving the regexp pattern. |
| 356 match = re.search(r'(interface|dictionary|exception)\s+\w+', file_contents) | 359 match = re.search(r'(interface|dictionary|exception)\s+\w+', file_contents) |
| 357 return bool(match) | 360 return bool(match) |
| 358 | 361 |
| 359 | 362 |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 519 | 522 |
| 520 # Remember an open brace. | 523 # Remember an open brace. |
| 521 match = re_last_brace.search(line) | 524 match = re_last_brace.search(line) |
| 522 was_open_brace = (match and match.group('last') == '{' and 'namespace' n
ot in line) | 525 was_open_brace = (match and match.group('last') == '{' and 'namespace' n
ot in line) |
| 523 | 526 |
| 524 # Let |'\n'.join| emit the last newline. | 527 # Let |'\n'.join| emit the last newline. |
| 525 if output: | 528 if output: |
| 526 output.append('') | 529 output.append('') |
| 527 | 530 |
| 528 return '\n'.join(output) | 531 return '\n'.join(output) |
| OLD | NEW |