diff options
| -rw-r--r-- | confparse.py | 19 |
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 |
