summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCasey Dahlin <cdahlin@redhat.com>2009-01-19 23:46:56 -0500
committerCasey Dahlin <cdahlin@redhat.com>2009-01-19 23:46:56 -0500
commita79618db8a4337d7b0f1b97aa5b8deed688043bd (patch)
tree8ad7917d58554e4d730f3d4b54288dfa20e9957e
parent50692b144eba59725bd3720f29f2ece20cf2b897 (diff)
downloadupstate-a79618db8a4337d7b0f1b97aa5b8deed688043bd.tar.gz
upstate-a79618db8a4337d7b0f1b97aa5b8deed688043bd.tar.xz
upstate-a79618db8a4337d7b0f1b97aa5b8deed688043bd.zip
Add CatSpec.to_category and ArgSpec.to_hash
-rw-r--r--confparse.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/confparse.py b/confparse.py
index 1e5cd5a..a5cecf2 100644
--- a/confparse.py
+++ b/confparse.py
@@ -1,4 +1,8 @@
# -*- coding: utf-8 -*-
+
+from category import Category
+from pattern import Pattern
+
class ParseError(Exception):
"""
Raised when there is an error while parsing. Duh.
@@ -396,6 +400,12 @@ class CatSpec(ParseTreeNode):
del toks[0]
self.args = ArgSpec(toks)
+ def to_category(self):
+ """
+ convert this catspec to a category object.
+ """
+ return Category(self.name.word, **self.args.to_hash())
+
def children(self):
"""
List of child nodes of this parse tree node
@@ -437,6 +447,15 @@ class ArgSpec(ParseTreeNode):
else:
raise ParseError("Unexpected %s token" % toks[0])
+ def to_hash(self):
+ """
+ convert `self` to an actual hash object
+ """
+ ret = {}
+ for i in self.items:
+ ret[i.name.word] = Pattern(i.truth, i.value.word)
+ return ret
+
def children(self):
"""
List of child nodes of this parse tree node