aboutsummaryrefslogtreecommitdiffstats
path: root/libpathod/language/base.py
diff options
context:
space:
mode:
Diffstat (limited to 'libpathod/language/base.py')
-rw-r--r--libpathod/language/base.py29
1 files changed, 28 insertions, 1 deletions
diff --git a/libpathod/language/base.py b/libpathod/language/base.py
index 725a0d42..4179fa7d 100644
--- a/libpathod/language/base.py
+++ b/libpathod/language/base.py
@@ -224,7 +224,6 @@ class _Component(Token):
A value component of the primary specification of an message.
Components produce byte values desribe the bytes of the message.
"""
- @abc.abstractmethod
def values(self, settings): # pragma: no cover
"""
A sequence of values, which can either be strings or generators.
@@ -376,6 +375,34 @@ class Value(_Component):
return self.__class__(self.value.freeze(settings))
+class Boolean(_Component):
+ """
+ A boolean flag.
+ name = true
+ -name = false
+ """
+ name = ""
+
+ def __init__(self, value):
+ self.value = value
+
+ @classmethod
+ def expr(klass):
+ e = pp.Optional(pp.Literal("-"), default=True)
+ e += pp.Literal(klass.name).suppress()
+
+ def parse(s, loc, toks):
+ val = True
+ if toks[0] == "-":
+ val = False
+ return klass(val)
+
+ return e.setParseAction(parse)
+
+ def spec(self):
+ return "%s%s"%("-" if not self.value else "", self.name)
+
+
class IntField(_Component):
"""
An integer field, where values can optionally specified by name.