OLD | NEW |
1 #! /usr/bin/env python | 1 #! /usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 import itertools | 6 import itertools |
7 import json | 7 import json |
8 import os.path | 8 import os.path |
9 import pprint | 9 import pprint |
10 import re | 10 import re |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 | 142 |
143 def process(self, callbacks): | 143 def process(self, callbacks): |
144 properties = OrderedDict() | 144 properties = OrderedDict() |
145 for node in self.node.GetChildren(): | 145 for node in self.node.GetChildren(): |
146 if node.cls == 'Member': | 146 if node.cls == 'Member': |
147 k, v = Member(node).process(callbacks) | 147 k, v = Member(node).process(callbacks) |
148 properties[k] = v | 148 properties[k] = v |
149 result = {'id': self.node.GetName(), | 149 result = {'id': self.node.GetName(), |
150 'properties': properties, | 150 'properties': properties, |
151 'type': 'object'} | 151 'type': 'object'} |
| 152 if self.node.GetProperty('nodefine'): |
| 153 result['nodefine'] = True |
152 if self.node.GetProperty('nodoc'): | 154 if self.node.GetProperty('nodoc'): |
153 result['nodoc'] = True | 155 result['nodoc'] = True |
154 elif self.node.GetProperty('inline_doc'): | 156 elif self.node.GetProperty('inline_doc'): |
155 result['inline_doc'] = True | 157 result['inline_doc'] = True |
156 elif self.node.GetProperty('noinline_doc'): | 158 elif self.node.GetProperty('noinline_doc'): |
157 result['noinline_doc'] = True | 159 result['noinline_doc'] = True |
158 return result | 160 return result |
159 | 161 |
160 | 162 |
161 | 163 |
162 class Member(object): | 164 class Member(object): |
163 ''' | 165 ''' |
164 Given an IDL dictionary or interface member, converts into a name/value pair | 166 Given an IDL dictionary or interface member, converts into a name/value pair |
165 where the value is a Python dictionary that the JSON schema compiler expects | 167 where the value is a Python dictionary that the JSON schema compiler expects |
166 to see. | 168 to see. |
167 ''' | 169 ''' |
168 def __init__(self, member_node): | 170 def __init__(self, member_node): |
169 self.node = member_node | 171 self.node = member_node |
170 | 172 |
171 def process(self, callbacks, functions_are_properties=False): | 173 def process(self, callbacks, functions_are_properties=False): |
172 properties = OrderedDict() | 174 properties = OrderedDict() |
173 name = self.node.GetName() | 175 name = self.node.GetName() |
174 if self.node.GetProperty('deprecated'): | 176 if self.node.GetProperty('deprecated'): |
175 properties['deprecated'] = self.node.GetProperty('deprecated') | 177 properties['deprecated'] = self.node.GetProperty('deprecated') |
176 if self.node.GetProperty('allowAmbiguousOptionalArguments'): | 178 if self.node.GetProperty('allowAmbiguousOptionalArguments'): |
177 properties['allowAmbiguousOptionalArguments'] = True | 179 properties['allowAmbiguousOptionalArguments'] = True |
178 for property_name in ('OPTIONAL', 'nodoc', 'nocompile', 'nodart'): | 180 for property_name in ('OPTIONAL', 'nodoc', 'nocompile', 'nodart', |
| 181 'nodefine'): |
179 if self.node.GetProperty(property_name): | 182 if self.node.GetProperty(property_name): |
180 properties[property_name.lower()] = True | 183 properties[property_name.lower()] = True |
181 for option_name, sanitizer in [ | 184 for option_name, sanitizer in [ |
182 ('maxListeners', int), | 185 ('maxListeners', int), |
183 ('supportsFilters', lambda s: s == 'true'), | 186 ('supportsFilters', lambda s: s == 'true'), |
184 ('supportsListeners', lambda s: s == 'true'), | 187 ('supportsListeners', lambda s: s == 'true'), |
185 ('supportsRules', lambda s: s == 'true')]: | 188 ('supportsRules', lambda s: s == 'true')]: |
186 if self.node.GetProperty(option_name): | 189 if self.node.GetProperty(option_name): |
187 if 'options' not in properties: | 190 if 'options' not in properties: |
188 properties['options'] = {} | 191 properties['options'] = {} |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 raise ValueError('Did not process %s %s' % (child.cls, child)) | 353 raise ValueError('Did not process %s %s' % (child.cls, child)) |
351 enum.append(enum_value) | 354 enum.append(enum_value) |
352 elif node.cls == 'Comment': | 355 elif node.cls == 'Comment': |
353 self.description = ProcessComment(node.GetName())[0] | 356 self.description = ProcessComment(node.GetName())[0] |
354 else: | 357 else: |
355 sys.exit('Did not process %s %s' % (node.cls, node)) | 358 sys.exit('Did not process %s %s' % (node.cls, node)) |
356 result = {'id' : self.node.GetName(), | 359 result = {'id' : self.node.GetName(), |
357 'description': self.description, | 360 'description': self.description, |
358 'type': 'string', | 361 'type': 'string', |
359 'enum': enum} | 362 'enum': enum} |
360 for property_name in ( | 363 for property_name in ('cpp_enum_prefix_override', 'inline_doc', |
361 'inline_doc', 'noinline_doc', 'nodoc', 'cpp_enum_prefix_override',): | 364 'noinline_doc', 'nodefine', 'nodoc',): |
362 if self.node.GetProperty(property_name): | 365 if self.node.GetProperty(property_name): |
363 result[property_name] = self.node.GetProperty(property_name) | 366 result[property_name] = self.node.GetProperty(property_name) |
364 if self.node.GetProperty('deprecated'): | 367 if self.node.GetProperty('deprecated'): |
365 result['deprecated'] = self.node.GetProperty('deprecated') | 368 result['deprecated'] = self.node.GetProperty('deprecated') |
366 return result | 369 return result |
367 | 370 |
368 | 371 |
369 class Namespace(object): | 372 class Namespace(object): |
370 ''' | 373 ''' |
371 Given an IDLNode representing an IDL namespace, converts into a Python | 374 Given an IDLNode representing an IDL namespace, converts into a Python |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
548 print json.dumps(schema, indent=2) | 551 print json.dumps(schema, indent=2) |
549 else: | 552 else: |
550 contents = sys.stdin.read() | 553 contents = sys.stdin.read() |
551 idl = idl_parser.IDLParser().ParseData(contents, '<stdin>') | 554 idl = idl_parser.IDLParser().ParseData(contents, '<stdin>') |
552 schema = IDLSchema(idl).process() | 555 schema = IDLSchema(idl).process() |
553 print json.dumps(schema, indent=2) | 556 print json.dumps(schema, indent=2) |
554 | 557 |
555 | 558 |
556 if __name__ == '__main__': | 559 if __name__ == '__main__': |
557 Main() | 560 Main() |
OLD | NEW |