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 match = re.search(r'callback\s+interface\s+\w+\s*{', file_contents) | 348 match = re.search(r'callback\s+interface\s+\w+\s*{', file_contents) |
bashi
2017/04/27 08:49:49
Could you add a comment why we search 'const' to d
Yuki
2017/04/27 12:18:29
|file_contents| doesn't include any comment, right
tkent
2017/04/28 06:13:36
Done. Added a comment.
| |
349 return bool(match) | 349 return bool(match) and not re.search(r'\bconst\b', file_contents) |
350 | 350 |
351 | 351 |
352 def should_generate_impl_file_from_idl(file_contents): | 352 def should_generate_impl_file_from_idl(file_contents): |
353 """True when a given IDL file contents could generate .h/.cpp files.""" | 353 """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 | 354 # FIXME: This would be error-prone and we should use AST rather than |
355 # improving the regexp pattern. | 355 # improving the regexp pattern. |
356 match = re.search(r'(interface|dictionary|exception)\s+\w+', file_contents) | 356 match = re.search(r'(interface|dictionary|exception)\s+\w+', file_contents) |
357 return bool(match) | 357 return bool(match) |
358 | 358 |
359 | 359 |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
519 | 519 |
520 # Remember an open brace. | 520 # Remember an open brace. |
521 match = re_last_brace.search(line) | 521 match = re_last_brace.search(line) |
522 was_open_brace = (match and match.group('last') == '{' and 'namespace' n ot in line) | 522 was_open_brace = (match and match.group('last') == '{' and 'namespace' n ot in line) |
523 | 523 |
524 # Let |'\n'.join| emit the last newline. | 524 # Let |'\n'.join| emit the last newline. |
525 if output: | 525 if output: |
526 output.append('') | 526 output.append('') |
527 | 527 |
528 return '\n'.join(output) | 528 return '\n'.join(output) |
OLD | NEW |