| OLD | NEW |
| (Empty) |
| 1 #!/usr/bin/env python | |
| 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 | |
| 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 'identifiers' : empty.IdentifiersNode, | |
| 24 'includes' : empty.IncludesNode, | |
| 25 'messages' : empty.MessagesNode, | |
| 26 'outputs' : empty.OutputsNode, | |
| 27 'structures' : empty.StructuresNode, | |
| 28 'translations' : empty.TranslationsNode, | |
| 29 'include' : include.IncludeNode, | |
| 30 'emit' : io.EmitNode, | |
| 31 'file' : io.FileNode, | |
| 32 'output' : io.OutputNode, | |
| 33 'ex' : message.ExNode, | |
| 34 'message' : message.MessageNode, | |
| 35 'ph' : message.PhNode, | |
| 36 'else' : misc.ElseNode, | |
| 37 'grit' : misc.GritNode, | |
| 38 'identifier' : misc.IdentifierNode, | |
| 39 'if' : misc.IfNode, | |
| 40 'part' : misc.PartNode, | |
| 41 'release' : misc.ReleaseNode, | |
| 42 'then' : misc.ThenNode, | |
| 43 'structure' : structure.StructureNode, | |
| 44 'skeleton' : variant.SkeletonNode, | |
| 45 } | |
| 46 | |
| 47 | |
| 48 def ElementToClass(name, typeattr): | |
| 49 '''Maps an element to a class that handles the element. | |
| 50 | |
| 51 Args: | |
| 52 name: 'element' (the name of the element) | |
| 53 typeattr: 'type' (the value of the type attribute, if present, else None) | |
| 54 | |
| 55 Return: | |
| 56 type | |
| 57 ''' | |
| 58 if name not in _ELEMENT_TO_CLASS: | |
| 59 raise exception.UnknownElement() | |
| 60 return _ELEMENT_TO_CLASS[name] | |
| 61 | |
| OLD | NEW |