diff --git a/ast_types.py b/ast_types.py index 1f07370..c7c31b3 100644 --- a/ast_types.py +++ b/ast_types.py @@ -8,6 +8,13 @@ def __repr__(self): return "Reference('%s')" % (self.value) +class Bool: + def __init__(self, value): + self.value = value + + def __repr__(self): + return "Bool(%s)" % (self.value) + class Text: def __init__(self, value): self.value = value diff --git a/interp.py b/interp.py index b1571e1..9d0500e 100644 --- a/interp.py +++ b/interp.py @@ -4,6 +4,19 @@ import ast_types import sys +class Bool: + def __init__(self, value): + self._value = value + + def __repr__(self): + return "Bool(%s)" % (self._value) + + def value(self): + return self._value + + def verb_ToText(self, args): + return Text(self._value) + class Text: def __init__(self, value): self._value = value @@ -58,6 +71,8 @@ raise InterpreterError("Unknown environment value %s" % (value.value)) elif value.__class__ == ast_types.Text: return Text(value.value) + elif value.__class__ == ast_types.Bool: + return Bool(value.value) else: raise InterpreterError("Unknown value type %s" % (value.__class__.__name__)) diff --git a/parse.py b/parse.py index 96ef191..8eba8e1 100644 --- a/parse.py +++ b/parse.py @@ -126,6 +126,9 @@ elif token == "BeginText": type = "text" value = self.read_text(line, column) + elif token in ["True", "False"]: + type = "bool" + value = (token == "True") elif token in keywords: type = "keyword" value = token @@ -184,6 +187,8 @@ ret = ast_types.Reference(value) elif type == "text": ret = ast_types.Text(value) + elif type == "bool": + ret = ast_types.Bool(value) else: raise ParseError(context, "Unexpected value type %s" % (type)) log.log(log.PARSER, log.TRACE, "Parsed value, AST is %s" % (ret)) @@ -279,8 +284,8 @@ def parse_directive(self, context): token = self.peek() - if token.type != "keyword" and token.type != "symbol": - raise ParseError(context, "Expected keyword or symbol, got %s" % (token.type)) + if token.type != "keyword" and token.type != "symbol" and token.type != "bool": + raise ParseError(context, "Expected keyword, symbol or bool, got %s" % (token.type)) if token.type == "keyword": if token.value == "Set": return self.parse_set(context)