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

Side by Side Diff: lib/dom/scripts/idlnode.py

Issue 10591002: Properly parse IDL arrays. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Next it Created 8 years, 6 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 | « no previous file | lib/dom/scripts/idlparser.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 2 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
3 # for details. All rights reserved. Use of this source code is governed by a 3 # for details. All rights reserved. Use of this source code is governed by a
4 # BSD-style license that can be found in the LICENSE file. 4 # BSD-style license that can be found in the LICENSE file.
5 5
6 import sys 6 import sys
7 7
8 8
9 class IDLNode(object): 9 class IDLNode(object):
10 """Base class for all IDL elements. 10 """Base class for all IDL elements.
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 # Search for a 'ScopedName' or any label ending with 'Type'. 315 # Search for a 'ScopedName' or any label ending with 'Type'.
316 if isinstance(ast, list): 316 if isinstance(ast, list):
317 self.id = self._find_first(ast, 'ScopedName') 317 self.id = self._find_first(ast, 'ScopedName')
318 if not self.id: 318 if not self.id:
319 # FIXME: use regexp search instead 319 # FIXME: use regexp search instead
320 for childAst in ast: 320 for childAst in ast:
321 (label, childAst) = childAst 321 (label, childAst) = childAst
322 if label.endswith('Type'): 322 if label.endswith('Type'):
323 self.id = self._label_to_type(label, ast) 323 self.id = self._label_to_type(label, ast)
324 break 324 break
325 array_modifiers = self._find_first(ast, 'ArrayModifiers')
326 if array_modifiers:
327 self.id += array_modifiers
325 elif isinstance(ast, tuple): 328 elif isinstance(ast, tuple):
326 (label, value) = ast 329 (label, value) = ast
327 if label == 'ScopedName': 330 if label == 'ScopedName':
328 self.id = value 331 self.id = value
329 else: 332 else:
330 self.id = self._label_to_type(label, ast) 333 self.id = self._label_to_type(label, ast)
331 elif isinstance(ast, str): 334 elif isinstance(ast, str):
332 self.id = ast 335 self.id = ast
333 if not self.id: 336 if not self.id:
334 raise SyntaxError('Could not parse type %s' % (ast)) 337 raise SyntaxError('Could not parse type %s' % (ast))
335 338
336 def _label_to_type(self, label, ast): 339 def _label_to_type(self, label, ast):
337 if label == 'AnyArrayType':
338 return 'any[]'
339 if label == 'DOMStringArrayType':
340 return 'DOMString[]'
341 if label == 'LongLongType': 340 if label == 'LongLongType':
342 label = 'long long' 341 label = 'long long'
343 elif label.endswith('Type'): 342 elif label.endswith('Type'):
344 # Omit 'Type' suffix and lowercase the rest. 343 # Omit 'Type' suffix and lowercase the rest.
345 label = '%s%s' % (label[0].lower(), label[1:-4]) 344 label = '%s%s' % (label[0].lower(), label[1:-4])
346 345
347 # Add unsigned qualifier. 346 # Add unsigned qualifier.
348 if self._has(ast, 'Unsigned'): 347 if self._has(ast, 'Unsigned'):
349 label = 'unsigned %s' % label 348 label = 'unsigned %s' % label
350 return label 349 return label
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 """IDLDictNode specialization for one annotation.""" 490 """IDLDictNode specialization for one annotation."""
492 def __init__(self, ast=None): 491 def __init__(self, ast=None):
493 IDLDictNode.__init__(self, ast) 492 IDLDictNode.__init__(self, ast)
494 self.id = None 493 self.id = None
495 if not ast: 494 if not ast:
496 return 495 return
497 for arg in self._find_all(ast, 'AnnotationArg'): 496 for arg in self._find_all(ast, 'AnnotationArg'):
498 name = self._find_first(arg, 'Id') 497 name = self._find_first(arg, 'Id')
499 value = self._find_first(arg, 'AnnotationArgValue') 498 value = self._find_first(arg, 'AnnotationArgValue')
500 self[name] = value 499 self[name] = value
OLDNEW
« no previous file with comments | « no previous file | lib/dom/scripts/idlparser.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698