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

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

Issue 261243002: Add support for [Global] / [PrimaryGlobal] IDL extended attributes (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fix nit 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 | Annotate | Revision Log
« no previous file with comments | « Source/bindings/scripts/generate_global_constructors.py ('k') | Source/core/frame/Window.idl » ('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 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 def get_parent_interface(file_contents): 86 def get_parent_interface(file_contents):
87 match = re.search(r'interface\s+' 87 match = re.search(r'interface\s+'
88 r'\w+\s*' 88 r'\w+\s*'
89 r':\s*(\w+)\s*' 89 r':\s*(\w+)\s*'
90 r'{', 90 r'{',
91 file_contents) 91 file_contents)
92 return match and match.group(1) 92 return match and match.group(1)
93 93
94 94
95 def get_interface_extended_attributes_from_idl(file_contents): 95 def get_interface_extended_attributes_from_idl(file_contents):
96 # Strip comments
97 # re.compile needed b/c Python 2.6 doesn't support flags in re.sub
98 single_line_comment_re = re.compile(r'//.*$', flags=re.MULTILINE)
99 block_comment_re = re.compile(r'/\*.*?\*/', flags=re.MULTILINE | re.DOTALL)
100 file_contents = re.sub(single_line_comment_re, '', file_contents)
101 file_contents = re.sub(block_comment_re, '', file_contents)
102
96 match = re.search(r'\[(.*)\]\s*' 103 match = re.search(r'\[(.*)\]\s*'
97 r'((callback|partial)\s+)?' 104 r'((callback|partial)\s+)?'
98 r'(interface|exception)\s+' 105 r'(interface|exception)\s+'
99 r'\w+\s*' 106 r'\w+\s*'
100 r'(:\s*\w+\s*)?' 107 r'(:\s*\w+\s*)?'
101 r'{', 108 r'{',
102 file_contents, flags=re.DOTALL) 109 file_contents, flags=re.DOTALL)
103 if not match: 110 if not match:
104 return {} 111 return {}
105 # Strip comments 112
106 # re.compile needed b/c Python 2.6 doesn't support flags in re.sub 113 extended_attributes_string = match.group(1)
107 single_line_comment_re = re.compile(r'//.*$', flags=re.MULTILINE)
108 block_comment_re = re.compile(r'/\*.*?\*/', flags=re.MULTILINE | re.DOTALL)
109 extended_attributes_string = re.sub(single_line_comment_re, '', match.group( 1))
110 extended_attributes_string = re.sub(block_comment_re, '', extended_attribute s_string)
111 extended_attributes = {} 114 extended_attributes = {}
112 # FIXME: this splitting is WRONG: it fails on ExtendedAttributeArgList like 115 # FIXME: this splitting is WRONG: it fails on ExtendedAttributeArgList like
113 # 'NamedConstructor=Foo(a, b)' 116 # 'NamedConstructor=Foo(a, b)'
114 parts = [extended_attribute.strip() 117 parts = [extended_attribute.strip()
115 for extended_attribute in extended_attributes_string.split(',') 118 for extended_attribute in extended_attributes_string.split(',')
116 # Discard empty parts, which may exist due to trailing comma 119 # Discard empty parts, which may exist due to trailing comma
117 if extended_attribute.strip()] 120 if extended_attribute.strip()]
118 for part in parts: 121 for part in parts:
119 name, _, value = map(string.strip, part.partition('=')) 122 name, _, value = map(string.strip, part.partition('='))
120 extended_attributes[name] = value 123 extended_attributes[name] = value
121 return extended_attributes 124 return extended_attributes
122 125
123 126
124 def get_put_forward_interfaces_from_idl(file_contents): 127 def get_put_forward_interfaces_from_idl(file_contents):
125 put_forwards_pattern = (r'\[[^\]]*PutForwards=[^\]]*\]\s+' 128 put_forwards_pattern = (r'\[[^\]]*PutForwards=[^\]]*\]\s+'
126 r'readonly\s+' 129 r'readonly\s+'
127 r'attribute\s+' 130 r'attribute\s+'
128 r'(\w+)') 131 r'(\w+)')
129 return sorted(set(match.group(1) 132 return sorted(set(match.group(1)
130 for match in re.finditer(put_forwards_pattern, 133 for match in re.finditer(put_forwards_pattern,
131 file_contents, 134 file_contents,
132 flags=re.DOTALL))) 135 flags=re.DOTALL)))
OLDNEW
« no previous file with comments | « Source/bindings/scripts/generate_global_constructors.py ('k') | Source/core/frame/Window.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698