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

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

Issue 270573005: Move modules-dependent IDL statements out of core by supporting 'implements' in RHS interface (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Refine utility function. Created 6 years, 7 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 # We use regular expressions for parsing; this is incorrect (Web IDL is not a 51 # We use regular expressions for parsing; this is incorrect (Web IDL is not a
52 # regular language), but simple and sufficient in practice. 52 # regular language), but simple and sufficient in practice.
53 # Leading and trailing context (e.g. following '{') used to avoid false matches. 53 # Leading and trailing context (e.g. following '{') used to avoid false matches.
54 ################################################################################ 54 ################################################################################
55 55
56 def get_partial_interface_name_from_idl(file_contents): 56 def get_partial_interface_name_from_idl(file_contents):
57 match = re.search(r'partial\s+interface\s+(\w+)\s*{', file_contents) 57 match = re.search(r'partial\s+interface\s+(\w+)\s*{', file_contents)
58 return match and match.group(1) 58 return match and match.group(1)
59 59
60 60
61 def get_implemented_interfaces_from_idl(file_contents, interface_name): 61 def get_implements_from_idl(file_contents, interface_name):
62 # Rule is: identifier-A implements identifier-B; 62 # Rule is: identifier-A implements identifier-B;
63 # http://www.w3.org/TR/WebIDL/#idl-implements-statements 63 # http://www.w3.org/TR/WebIDL/#idl-implements-statements
64 def get_implemented(left_identifier, right_identifier): 64 # Returns two lists of interfaces that contain identifier-As and identifier- Bs.
65 # identifier-A must be the current interface 65 # The 'implements' statements are supported in both identifier-A IDL and ide ntifier-B IDL
66 if left_identifier != interface_name: 66 # to avoid potential layering violation.
67 raise IdlBadFilenameError("Identifier on the left of the 'implements ' statement should be %s in %s.idl, but found %s" % (interface_name, interface_n ame, left_identifier))
68 return right_identifier
69
70 implements_re = (r'^\s*' 67 implements_re = (r'^\s*'
71 r'(\w+)\s+' 68 r'(\w+)\s+'
72 r'implements\s+' 69 r'implements\s+'
73 r'(\w+)\s*' 70 r'(\w+)\s*'
74 r';') 71 r';')
75 implements_matches = re.finditer(implements_re, file_contents, re.MULTILINE) 72 implements_matches = re.finditer(implements_re, file_contents, re.MULTILINE)
76 implements_pairs = [(match.group(1), match.group(2)) 73 implements_pairs = [(match.group(1), match.group(2))
77 for match in implements_matches] 74 for match in implements_matches]
78 return [get_implemented(left, right) for left, right in implements_pairs] 75 A_interfaces = []
76 B_interfaces = []
77 for left, right in implements_pairs:
78 if left == interface_name:
79 B_interfaces.append(right)
80 elif right == interface_name:
81 A_interfaces.append(left)
82 return [A_interfaces, B_interfaces]
Inactive 2014/05/07 21:45:05 You should return a tuple here: return (A_interfac
c.shu 2014/05/07 21:52:40 Done.
79 83
80 84
81 def is_callback_interface_from_idl(file_contents): 85 def is_callback_interface_from_idl(file_contents):
82 match = re.search(r'callback\s+interface\s+\w+\s*{', file_contents) 86 match = re.search(r'callback\s+interface\s+\w+\s*{', file_contents)
83 return bool(match) 87 return bool(match)
84 88
85 89
86 def get_parent_interface(file_contents): 90 def get_parent_interface(file_contents):
87 match = re.search(r'interface\s+' 91 match = re.search(r'interface\s+'
88 r'\w+\s*' 92 r'\w+\s*'
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 127
124 def get_put_forward_interfaces_from_idl(file_contents): 128 def get_put_forward_interfaces_from_idl(file_contents):
125 put_forwards_pattern = (r'\[[^\]]*PutForwards=[^\]]*\]\s+' 129 put_forwards_pattern = (r'\[[^\]]*PutForwards=[^\]]*\]\s+'
126 r'readonly\s+' 130 r'readonly\s+'
127 r'attribute\s+' 131 r'attribute\s+'
128 r'(\w+)') 132 r'(\w+)')
129 return sorted(set(match.group(1) 133 return sorted(set(match.group(1)
130 for match in re.finditer(put_forwards_pattern, 134 for match in re.finditer(put_forwards_pattern,
131 file_contents, 135 file_contents,
132 flags=re.DOTALL))) 136 flags=re.DOTALL)))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698