OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/python2.4 |
| 2 # Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. |
| 5 |
| 6 '''Maps each node type to an implementation class. |
| 7 When adding a new node type, you add to this mapping. |
| 8 ''' |
| 9 |
| 10 |
| 11 from grit import exception |
| 12 |
| 13 from grit.node import empty |
| 14 from grit.node import message |
| 15 from grit.node import misc |
| 16 from grit.node import variant |
| 17 from grit.node import structure |
| 18 from grit.node import include |
| 19 from grit.node import io |
| 20 |
| 21 |
| 22 _ELEMENT_TO_CLASS = { |
| 23 'includes' : empty.IncludesNode, |
| 24 'messages' : empty.MessagesNode, |
| 25 'structures' : empty.StructuresNode, |
| 26 'translations' : empty.TranslationsNode, |
| 27 'outputs' : empty.OutputsNode, |
| 28 'message' : message.MessageNode, |
| 29 'ph' : message.PhNode, |
| 30 'ex' : message.ExNode, |
| 31 'grit' : misc.GritNode, |
| 32 'include' : include.IncludeNode, |
| 33 'structure' : structure.StructureNode, |
| 34 'skeleton' : variant.SkeletonNode, |
| 35 'release' : misc.ReleaseNode, |
| 36 'file' : io.FileNode, |
| 37 'output' : io.OutputNode, |
| 38 'emit' : io.EmitNode, |
| 39 'identifiers' : empty.IdentifiersNode, |
| 40 'identifier' : misc.IdentifierNode, |
| 41 'if' : misc.IfNode, |
| 42 } |
| 43 |
| 44 |
| 45 def ElementToClass(name, typeattr): |
| 46 '''Maps an element to a class that handles the element. |
| 47 |
| 48 Args: |
| 49 name: 'element' (the name of the element) |
| 50 typeattr: 'type' (the value of the type attribute, if present, else None) |
| 51 |
| 52 Return: |
| 53 type |
| 54 ''' |
| 55 if not _ELEMENT_TO_CLASS.has_key(name): |
| 56 raise exception.UnknownElement() |
| 57 return _ELEMENT_TO_CLASS[name] |
| 58 |
OLD | NEW |