summaryrefslogtreecommitdiffstats
path: root/tools/grit/grit/node/mapping.py
diff options
context:
space:
mode:
authorNico Weber <thakis@chromium.org>2015-11-12 11:05:30 -0800
committerNico Weber <thakis@chromium.org>2015-11-12 19:08:05 +0000
commit3dbdb83c0fee5863171e20174ded8a8b74d16e9e (patch)
tree522b4e652e0910f251dfbde876d97ee7ce9ea7b3 /tools/grit/grit/node/mapping.py
parent4771dd55cdc2ca26c955776056d540ec62da40e6 (diff)
downloadchromium_src-3dbdb83c0fee5863171e20174ded8a8b74d16e9e.zip
chromium_src-3dbdb83c0fee5863171e20174ded8a8b74d16e9e.tar.gz
chromium_src-3dbdb83c0fee5863171e20174ded8a8b74d16e9e.tar.bz2
Move grit from DEPS into src.
This copies the currently DEPS'd in revision, r201. No intended behavior change. BUG=553682 R=primiano@chromium.org TBR=mnaganov Review URL: https://codereview.chromium.org/1410853008 . Cr-Commit-Position: refs/heads/master@{#359352}
Diffstat (limited to 'tools/grit/grit/node/mapping.py')
-rwxr-xr-xtools/grit/grit/node/mapping.py61
1 files changed, 61 insertions, 0 deletions
diff --git a/tools/grit/grit/node/mapping.py b/tools/grit/grit/node/mapping.py
new file mode 100755
index 0000000..259be97
--- /dev/null
+++ b/tools/grit/grit/node/mapping.py
@@ -0,0 +1,61 @@
+#!/usr/bin/env python
+# Copyright (c) 2012 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+'''Maps each node type to an implementation class.
+When adding a new node type, you add to this mapping.
+'''
+
+
+from grit import exception
+
+from grit.node import empty
+from grit.node import message
+from grit.node import misc
+from grit.node import variant
+from grit.node import structure
+from grit.node import include
+from grit.node import io
+
+
+_ELEMENT_TO_CLASS = {
+ 'identifiers' : empty.IdentifiersNode,
+ 'includes' : empty.IncludesNode,
+ 'messages' : empty.MessagesNode,
+ 'outputs' : empty.OutputsNode,
+ 'structures' : empty.StructuresNode,
+ 'translations' : empty.TranslationsNode,
+ 'include' : include.IncludeNode,
+ 'emit' : io.EmitNode,
+ 'file' : io.FileNode,
+ 'output' : io.OutputNode,
+ 'ex' : message.ExNode,
+ 'message' : message.MessageNode,
+ 'ph' : message.PhNode,
+ 'else' : misc.ElseNode,
+ 'grit' : misc.GritNode,
+ 'identifier' : misc.IdentifierNode,
+ 'if' : misc.IfNode,
+ 'part' : misc.PartNode,
+ 'release' : misc.ReleaseNode,
+ 'then' : misc.ThenNode,
+ 'structure' : structure.StructureNode,
+ 'skeleton' : variant.SkeletonNode,
+}
+
+
+def ElementToClass(name, typeattr):
+ '''Maps an element to a class that handles the element.
+
+ Args:
+ name: 'element' (the name of the element)
+ typeattr: 'type' (the value of the type attribute, if present, else None)
+
+ Return:
+ type
+ '''
+ if name not in _ELEMENT_TO_CLASS:
+ raise exception.UnknownElement()
+ return _ELEMENT_TO_CLASS[name]
+