Пример #1
0
def _readPools(data, dot, avroTypeBuilder):
    if isinstance(data, dict):
        at = data.get("@")
        for k in data.keys():
            if k != "@" and not validSymbolName(k):
                raise PFASyntaxException("\"{0}\" is not a valid symbol name".format(k), pos(dot, at))
        return dict((k, _readPool(data[k], dot, avroTypeBuilder)) for k, v in data.items() if k != "@")
    else:
        raise PFASyntaxException("expected map of pools, not " + _trunc(repr(data)), None)
Пример #2
0
def _readPools(data, dot, avroTypeBuilder):
    if isinstance(data, dict):
        at = data.get("@")
        for k in data.keys():
            if k != "@" and not validSymbolName(k):
                raise PFASyntaxException("\"{0}\" is not a valid symbol name".format(k), pos(dot, at))
        return dict((k, _readPool(data[k], dot, avroTypeBuilder)) for k, v in data.items() if k != "@")
    else:
        raise PFASyntaxException("expected map of pools, not " + _trunc(repr(data)), None)
Пример #3
0
def _readParam(data, dot, avroTypeBuilder):
    if isinstance(data, dict):
        at = data.get("@")
        keys = set(x for x in data.keys() if x != "@")
        if len(keys) != 1:
            raise PFASyntaxException("function parameter name-type map should have only one pair", pos(dot, at))
        n = list(keys)[0]
        if not validSymbolName(n):
            raise PFASyntaxException("\"{0}\" is not a valid symbol name".format(n))

        t = _readAvroPlaceholder(data[n], dot + " -> " + n, avroTypeBuilder)
        return {n: t}
    else:
        raise PFASyntaxException("expected function parameter name-type singleton map, not " + _trunc(repr(data)), pos(dot, at))
Пример #4
0
def _readParam(data, dot, avroTypeBuilder):
    if isinstance(data, dict):
        at = data.get("@")
        keys = set(x for x in data.keys() if x != "@")
        if len(keys) != 1:
            raise PFASyntaxException("function parameter name-type map should have only one pair", pos(dot, at))
        n = list(keys)[0]
        if not validSymbolName(n):
            raise PFASyntaxException("\"{0}\" is not a valid symbol name".format(n))

        t = _readAvroPlaceholder(data[n], dot + " -> " + n, avroTypeBuilder)
        return {n: t}
    else:
        raise PFASyntaxException("expected function parameter name-type singleton map, not " + _trunc(repr(data)), pos(dot, at))
Пример #5
0
def _readCastCase(data, dot, avroTypeBuilder):
    if isinstance(data, dict):
        at = data.get("@")
        keys = set(x for x in data.keys() if x != "@")

        for key in keys:
            if key == "as": _as = _readAvroPlaceholder(data[key], dot + " -> " + key, avroTypeBuilder)
            elif key == "named": _named = _readString(data[key], dot + " -> " + key)
            elif key == "do":
                if isinstance(data[key], (list, tuple)):
                    _body = _readExpressionArray(data[key], dot + " -> " + key, avroTypeBuilder)
                else:
                    _body = [_readExpression(data[key], dot + " -> " + key, avroTypeBuilder)]
            else:
                raise PFASyntaxException("unexpected field in cast-case: {0}".format(key), pos(dot, at))

    if "named" in keys and not validSymbolName(_named):
        raise PFASyntaxException("\"{0}\" is not a valid symbol name".format(_named), pos(dot, at))

    required = set(["as", "named", "do"])
    if (keys != required):
        raise PFASyntaxException("wrong set of fields for a cast-case: \"{0}\"".format(", ".join(keys)), pos(dot, at))
    else:
        return CastCase(_as, _named, _body)
Пример #6
0
def _readCastCase(data, dot, avroTypeBuilder):
    if isinstance(data, dict):
        at = data.get("@")
        keys = set(x for x in data.keys() if x != "@")

        for key in keys:
            if key == "as": _as = _readAvroPlaceholder(data[key], dot + " -> " + key, avroTypeBuilder)
            elif key == "named": _named = _readString(data[key], dot + " -> " + key)
            elif key == "do":
                if isinstance(data[key], (list, tuple)):
                    _body = _readExpressionArray(data[key], dot + " -> " + key, avroTypeBuilder)
                else:
                    _body = [_readExpression(data[key], dot + " -> " + key, avroTypeBuilder)]
            else:
                raise PFASyntaxException("unexpected field in cast-case: {0}".format(key), pos(dot, at))

    if "named" in keys and not validSymbolName(_named):
        raise PFASyntaxException("\"{0}\" is not a valid symbol name".format(_named), pos(dot, at))

    required = set(["as", "named", "do"])
    if (keys != required):
        raise PFASyntaxException("wrong set of fields for a cast-case: \"{0}\"".format(", ".join(keys)), pos(dot, at))
    else:
        return CastCase(_as, _named, _body)
Пример #7
0
def _readArgument(data, dot, avroTypeBuilder):
    if data is None:
        return LiteralNull(dot)
    elif isinstance(data, bool):
        return LiteralBoolean(data, dot)
    elif isinstance(data, (int, long)):
        if -2147483648 <= data <= 2147483647:
            return LiteralInt(data, dot)
        elif -9223372036854775808 <= data <= 9223372036854775807:
            return LiteralLong(data, dot)
        else:
            raise PFASyntaxException("integer out of range: " + str(data), dot)
    elif isinstance(data, float):
        return LiteralDouble(data, dot)
    elif isinstance(data, basestring):
        if "." in data:
            words = data.split(".")
            ref = words[0]
            rest = words[1:]
            if not validSymbolName(ref):
                raise PFASyntaxException("\"{0}\" is not a valid symbol name".format(ref), dot)
            for i in xrange(len(rest)):
                try:
                    asint = int(rest[i])
                except ValueError:
                    rest[i] = LiteralString(rest[i], dot)
                else:
                    rest[i] = LiteralInt(asint, dot)
            return AttrGet(Ref(ref), rest, dot)
        elif validSymbolName(data):
            return Ref(data, dot)
        else:
            raise PFASyntaxException("\"{0}\" is not a valid symbol name".format(data), dot)

    elif isinstance(data, (list, tuple)):
        if len(data) == 1 and isinstance(data[0], basestring):
            return LiteralString(data[0], dot)
        else:
            raise PFASyntaxException("expecting expression, which may be [\"string\"], but no other array can be used as an expression", dot)

    elif isinstance(data, dict):
        at = data.get("@")
        keys = set(x for x in data.keys() if x != "@")

        _path = []
        _seq = True
        _partial = False
        _code = 0
        _newObject = None
        _newArray = None
        _filter = None

        for key in keys:
            if key == "int": _int = _readInt(data[key], dot + " -> " + key)
            elif key == "long": _long = _readLong(data[key], dot + " -> " + key)
            elif key == "float": _float = _readFloat(data[key], dot + " -> " + key)
            elif key == "double": _double = _readDouble(data[key], dot + " -> " + key)
            elif key == "string": _string = _readString(data[key], dot + " -> " + key)
            elif key == "base64": _bytes = _readBase64(data[key], dot + " -> " + key)
            elif key == "type": _avroType = _readAvroPlaceholder(data[key], dot + " -> " + key, avroTypeBuilder)
            elif key == "value": _value = _readJsonToString(data[key], dot + " -> " + key)

            elif key == "let": _let = _readExpressionMap(data[key], dot + " -> " + key, avroTypeBuilder)
            elif key == "set": _set = _readExpressionMap(data[key], dot + " -> " + key, avroTypeBuilder)
            elif key == "for": _forlet = _readExpressionMap(data[key], dot + " -> " + key, avroTypeBuilder)
            elif key == "step": _forstep = _readExpressionMap(data[key], dot + " -> " + key, avroTypeBuilder)
            elif key == "ifnotnull": _ifnotnull = _readExpressionMap(data[key], dot + " -> " + key, avroTypeBuilder)

            elif key == "do":
                if isinstance(data[key], (list, tuple)):
                    _body = _readExpressionArray(data[key], dot + " -> " + key, avroTypeBuilder)
                else:
                    _body = [_readExpression(data[key], dot + " -> " + key, avroTypeBuilder)]
            elif key == "then":
                if isinstance(data[key], (list, tuple)):
                    _thenClause = _readExpressionArray(data[key], dot + " -> " + key, avroTypeBuilder)
                else:
                    _thenClause = [_readExpression(data[key], dot + " -> " + key, avroTypeBuilder)]
            elif key == "else":
                if isinstance(data[key], (list, tuple)):
                    _elseClause = _readExpressionArray(data[key], dot + " -> " + key, avroTypeBuilder)
                else:
                    _elseClause = [_readExpression(data[key], dot + " -> " + key, avroTypeBuilder)]
            elif key == "log":
                if isinstance(data[key], (list, tuple)):
                    _log = _readExpressionArray(data[key], dot + " -> " + key, avroTypeBuilder)
                else:
                    _log = [_readExpression(data[key], dot + " -> " + key, avroTypeBuilder)]
            elif key == "path":
                _path = _readExpressionArray(data[key], dot + " -> " + key, avroTypeBuilder)
            elif key == "args":
                _callwithargs = _readExpressionArray(data[key], dot + " -> " + key, avroTypeBuilder)
            elif key == "try":
                if isinstance(data[key], (list, tuple)):
                    _trycatch = _readExpressionArray(data[key], dot + " -> " + key, avroTypeBuilder)
                else:
                    _trycatch = [_readExpression(data[key], dot + " -> " + key, avroTypeBuilder)]

            elif key == "attr": _attr = _readExpression(data[key], dot + " -> " + key, avroTypeBuilder)
            elif key == "if": _ifPredicate = _readExpression(data[key], dot + " -> " + key, avroTypeBuilder)
            elif key == "while": _whilePredicate = _readExpression(data[key], dot + " -> " + key, avroTypeBuilder)
            elif key == "until": _until = _readExpression(data[key], dot + " -> " + key, avroTypeBuilder)
            elif key == "unpack": _unpack = _readExpression(data[key], dot + " -> " + key, avroTypeBuilder)
            elif key == "del": _dell = _readExpression(data[key], dot + " -> " + key, avroTypeBuilder)

            elif key == "cond":
                _cond = _readExpressionArray(data[key], dot + " -> " + key, avroTypeBuilder)
                if any(x.elseClause is not None for x in _cond):
                    raise PFASyntaxException("cond expression must only contain else-less if expressions", pos(dot, at))

            elif key == "cases": _cases = _readCastCaseArray(data[key], dot + " -> " + key, avroTypeBuilder)

            elif key == "foreach": _foreach = _readString(data[key], dot + " -> " + key)
            elif key == "forkey": _forkey = _readString(data[key], dot + " -> " + key)
            elif key == "forval": _forval = _readString(data[key], dot + " -> " + key)
            elif key == "fcn": _fcnref = _readString(data[key], dot + " -> " + key)
            elif key == "cell": _cell = _readString(data[key], dot + " -> " + key)
            elif key == "pool": _pool = _readString(data[key], dot + " -> " + key)

            elif key == "in": _in = _readExpression(data[key], dot + " -> " + key, avroTypeBuilder)
            elif key == "cast": _cast = _readExpression(data[key], dot + " -> " + key, avroTypeBuilder)
            elif key == "upcast": _upcast = _readExpression(data[key], dot + " -> " + key, avroTypeBuilder)
            elif key == "init": _init = _readExpression(data[key], dot + " -> " + key, avroTypeBuilder)
            elif key == "call": _callwith = _readExpression(data[key], dot + " -> " + key, avroTypeBuilder)

            elif key == "seq": _seq = _readBoolean(data[key], dot + " -> " + key)
            elif key == "partial": _partial = _readBoolean(data[key], dot + " -> " + key)

            elif key == "doc": _doc = _readString(data[key], dot + " -> " + key)
            elif key == "error": _error = _readString(data[key], dot + " -> " + key)
            elif key == "code": _code = _readInt(data[key], dot + " -> " + key)
            elif key == "namespace": _namespace = _readString(data[key], dot + " -> " + key)

            elif key == "new":
                if isinstance(data[key], dict):
                    _newObject = _readExpressionMap(data[key], dot + " -> " + key, avroTypeBuilder)
                elif isinstance(data[key], (list, tuple)):
                    _newArray = _readExpressionArray(data[key], dot + " -> " + key, avroTypeBuilder)
                else:
                    raise PFASyntaxException("\"new\" must be an object (map, record) or an array", pos(dot, at))

            elif key == "params": _params = _readParams(data[key], dot + " -> " + key, avroTypeBuilder)
            elif key == "ret": _ret = _readAvroPlaceholder(data[key], dot + " -> " + key, avroTypeBuilder)
            elif key == "as": _as = _readAvroPlaceholder(data[key], dot + " -> " + key, avroTypeBuilder)

            elif key == "to": _to = _readArgument(data[key], dot + " -> " + key, avroTypeBuilder)

            elif key == "fill": _fill = _readArgumentMap(data[key], dot + " -> " + key, avroTypeBuilder)

            elif key == "filter": _filter = _readStringOrIntArray(data[key], dot + " -> " + key)

            elif key == "format": _format = _readStringPairs(data[key], dot + " -> " + key)
            elif key == "pack": _pack = _readStringExpressionPairs(data[key], dot + " -> " + key, avroTypeBuilder)

            else:
                _callName = key
                if isinstance(data[key], (list, tuple)):
                    _callArgs = _readArgumentArray(data[key], dot + " -> " + key, avroTypeBuilder)
                else:
                    _callArgs = [_readArgument(data[key], dot + " -> " + key, avroTypeBuilder)]

        if "foreach" in keys and not validSymbolName(_foreach):
            raise PFASyntaxException("\"{0}\" is not a valid symbol name".format(data[keys]), pos(dot, at))
        if "forkey" in keys and not validSymbolName(_forkey):
            raise PFASyntaxException("\"{0}\" is not a valid symbol name".format(data[keys]), pos(dot, at))
        if "forval" in keys and not validSymbolName(_forval):
            raise PFASyntaxException("\"{0}\" is not a valid symbol name".format(data[keys]), pos(dot, at))
        if "fcn" in keys and not validFunctionName(_fcnref):
            raise PFASyntaxException("\"{0}\" is not a valid function name".format(data[keys]), pos(dot, at))

        if keys == set(["int"]):                             return LiteralInt(_int, pos(dot, at))
        elif keys == set(["long"]):                          return LiteralLong(_long, pos(dot, at))
        elif keys == set(["float"]):                         return LiteralFloat(_float, pos(dot, at))
        elif keys == set(["double"]):                        return LiteralDouble(_double, pos(dot, at))
        elif keys == set(["string"]):                        return LiteralString(_string, pos(dot, at))
        elif keys == set(["base64"]):                        return LiteralBase64(_bytes, pos(dot, at))
        elif keys == set(["type", "value"]):                 return Literal(_avroType, _value, pos(dot, at))

        elif keys == set(["new", "type"]) and _newObject is not None:
                                                             return NewObject(_newObject, _avroType, pos(dot, at))
        elif keys == set(["new", "type"]) and _newArray is not None:
                                                             return NewArray(_newArray, _avroType, pos(dot, at))

        elif keys == set(["do"]):                            return Do(_body, pos(dot, at))
        elif keys == set(["let"]):                           return Let(_let, pos(dot, at))
        elif keys == set(["set"]):                           return SetVar(_set, pos(dot, at))

        elif keys == set(["attr", "path"]):                  return AttrGet(_attr, _path, pos(dot, at))
        elif keys == set(["attr", "path", "to"]):            return AttrTo(_attr, _path, _to, pos(dot, at))
        elif keys == set(["cell"]) or \
             keys == set(["cell", "path"]):                  return CellGet(_cell, _path, pos(dot, at))
        elif keys == set(["cell", "to"]) or \
             keys == set(["cell", "path", "to"]):            return CellTo(_cell, _path, _to, pos(dot, at))
        elif keys == set(["pool", "path"]):                  return PoolGet(_pool, _path, pos(dot, at))
        elif keys == set(["pool", "path", "to", "init"]):    return PoolTo(_pool, _path, _to, _init, pos(dot, at))
        elif keys == set(["pool", "del"]):                   return PoolDel(_pool, _dell, pos(dot, at))

        elif keys == set(["if", "then"]):                    return If(_ifPredicate, _thenClause, None, pos(dot, at))
        elif keys == set(["if", "then", "else"]):            return If(_ifPredicate, _thenClause, _elseClause, pos(dot, at))
        elif keys == set(["cond"]):                          return Cond(_cond, None, pos(dot, at))
        elif keys == set(["cond", "else"]):                  return Cond(_cond, _elseClause, pos(dot, at))

        elif keys == set(["while", "do"]):                   return While(_whilePredicate, _body, pos(dot, at))
        elif keys == set(["do", "until"]):                   return DoUntil(_body, _until, pos(dot, at))
        elif keys == set(["for", "while", "step", "do"]):    return For(_forlet, _whilePredicate, _forstep, _body, pos(dot, at))

        elif keys == set(["foreach", "in", "do"]) or \
             keys == set(["foreach", "in", "do", "seq"]):    return Foreach(_foreach, _in, _body, _seq, pos(dot, at))
        elif keys == set(["forkey", "forval", "in", "do"]):  return Forkeyval(_forkey, _forval, _in, _body, pos(dot, at))

        elif keys == set(["cast", "cases"]) or \
             keys == set(["cast", "cases", "partial"]):      return CastBlock(_cast, _cases, _partial, pos(dot, at))
        elif keys == set(["upcast", "as"]):                  return Upcast(_upcast, _as, pos(dot, at))

        elif keys == set(["ifnotnull", "then"]):             return IfNotNull(_ifnotnull, _thenClause, None, pos(dot, at))
        elif keys == set(["ifnotnull", "then", "else"]):     return IfNotNull(_ifnotnull, _thenClause, _elseClause, pos(dot, at))

        elif keys == set(["pack"]):                          return Pack(_pack, pos(dot, at))
        elif keys == set(["unpack", "format", "then"]):      return Unpack(_unpack, _format, _thenClause, None, pos(dot, at))
        elif keys == set(["unpack", "format", "then", "else"]):
                                                             return Unpack(_unpack, _format, _thenClause, _elseClause, pos(dot, at))

        elif keys == set(["doc"]):                           return Doc(_doc, pos(dot, at))

        elif keys == set(["error"]):                         return Error(_error, None, pos(dot, at))
        elif keys == set(["error", "code"]):                 return Error(_error, _code, pos(dot, at))
        elif keys == set(["try"]) or \
             keys == set(["try", "filter"]):                 return Try(_trycatch, _filter, pos(dot, at))
        elif keys == set(["log"]):                           return Log(_log, None, pos(dot, at))
        elif keys == set(["log", "namespace"]):              return Log(_log, _namespace, pos(dot, at))

        elif keys == set(["params", "ret", "do"]):           return FcnDef(_params, _ret, _body, pos(dot, at))
        elif keys == set(["fcn"]):                           return FcnRef(_fcnref, pos(dot, at))
        elif keys == set(["fcn", "fill"]):                   return FcnRefFill(_fcnref, _fill, pos(dot, at))
        elif keys == set(["call", "args"]):                  return CallUserFcn(_callwith, _callwithargs, pos(dot, at))

        elif len(keys) == 1 and list(keys)[0] not in \
             set(["args", "as", "attr", "base64", "call", "cases", "cast", "cell", "code", "cond", "do", "doc", "double", "else",
                  "error", "fcn", "fill", "filter", "float", "for", "foreach", "forkey", "format", "forval", "if", "ifnotnull", "in", "init",
                  "int", "let", "log", "long", "namespace", "new", "pack", "params", "partial", "path", "pool", "ret", "seq",
                  "set", "step", "string", "then", "to", "try", "type", "unpack", "until", "upcast", "value", "while"]):
                                                             return Call(_callName, _callArgs, pos(dot, at))

        else: raise PFASyntaxException("unrecognized special form: {0} (not enough arguments? too many?)".format(", ".join(keys)), pos(dot, at))

    else:
        raise PFASyntaxException("expected expression, not " + _trunc(repr(data)), dot)
Пример #8
0
def _readArgument(data, dot, avroTypeBuilder):
    if data is None:
        return LiteralNull(dot)
    elif isinstance(data, bool):
        return LiteralBoolean(data, dot)
    elif isinstance(data, int):
        if -2147483648 <= data <= 2147483647:
            return LiteralInt(data, dot)
        elif -9223372036854775808 <= data <= 9223372036854775807:
            return LiteralLong(data, dot)
        else:
            raise PFASyntaxException("integer out of range: " + str(data), dot)
    elif isinstance(data, float):
        return LiteralDouble(data, dot)
    elif isinstance(data, str):
        if "." in data:
            words = data.split(".")
            ref = words[0]
            rest = words[1:]
            if not validSymbolName(ref):
                raise PFASyntaxException("\"{0}\" is not a valid symbol name".format(ref), dot)
            for i in range(len(rest)):
                try:
                    asint = int(rest[i])
                except ValueError:
                    rest[i] = LiteralString(rest[i], dot)
                else:
                    rest[i] = LiteralInt(asint, dot)
            return AttrGet(Ref(ref), rest, dot)
        elif validSymbolName(data):
            return Ref(data, dot)
        else:
            raise PFASyntaxException("\"{0}\" is not a valid symbol name".format(data), dot)

    elif isinstance(data, (list, tuple)):
        if len(data) == 1 and isinstance(data[0], str):
            return LiteralString(data[0], dot)
        else:
            raise PFASyntaxException("expecting expression, which may be [\"string\"], but no other array can be used as an expression", dot)

    elif isinstance(data, dict):
        at = data.get("@")
        keys = set(x for x in data.keys() if x != "@")

        _path = []
        _seq = True
        _partial = False
        _code = 0
        _newObject = None
        _newArray = None
        _filter = None

        for key in keys:
            if key == "int": _int = _readInt(data[key], dot + " -> " + key)
            elif key == "long": _long = _readLong(data[key], dot + " -> " + key)
            elif key == "float": _float = _readFloat(data[key], dot + " -> " + key)
            elif key == "double": _double = _readDouble(data[key], dot + " -> " + key)
            elif key == "string": _string = _readString(data[key], dot + " -> " + key)
            elif key == "base64": _bytes = _readBase64(data[key], dot + " -> " + key)
            elif key == "type": _avroType = _readAvroPlaceholder(data[key], dot + " -> " + key, avroTypeBuilder)
            elif key == "value": _value = _readJsonToString(data[key], dot + " -> " + key)

            elif key == "let": _let = _readExpressionMap(data[key], dot + " -> " + key, avroTypeBuilder)
            elif key == "set": _set = _readExpressionMap(data[key], dot + " -> " + key, avroTypeBuilder)
            elif key == "for": _forlet = _readExpressionMap(data[key], dot + " -> " + key, avroTypeBuilder)
            elif key == "step": _forstep = _readExpressionMap(data[key], dot + " -> " + key, avroTypeBuilder)
            elif key == "ifnotnull": _ifnotnull = _readExpressionMap(data[key], dot + " -> " + key, avroTypeBuilder)

            elif key == "do":
                if isinstance(data[key], (list, tuple)):
                    _body = _readExpressionArray(data[key], dot + " -> " + key, avroTypeBuilder)
                else:
                    _body = [_readExpression(data[key], dot + " -> " + key, avroTypeBuilder)]
            elif key == "then":
                if isinstance(data[key], (list, tuple)):
                    _thenClause = _readExpressionArray(data[key], dot + " -> " + key, avroTypeBuilder)
                else:
                    _thenClause = [_readExpression(data[key], dot + " -> " + key, avroTypeBuilder)]
            elif key == "else":
                if isinstance(data[key], (list, tuple)):
                    _elseClause = _readExpressionArray(data[key], dot + " -> " + key, avroTypeBuilder)
                else:
                    _elseClause = [_readExpression(data[key], dot + " -> " + key, avroTypeBuilder)]
            elif key == "log":
                if isinstance(data[key], (list, tuple)):
                    _log = _readExpressionArray(data[key], dot + " -> " + key, avroTypeBuilder)
                else:
                    _log = [_readExpression(data[key], dot + " -> " + key, avroTypeBuilder)]
            elif key == "path":
                _path = _readExpressionArray(data[key], dot + " -> " + key, avroTypeBuilder)
            elif key == "args":
                _callwithargs = _readExpressionArray(data[key], dot + " -> " + key, avroTypeBuilder)
            elif key == "try":
                if isinstance(data[key], (list, tuple)):
                    _trycatch = _readExpressionArray(data[key], dot + " -> " + key, avroTypeBuilder)
                else:
                    _trycatch = [_readExpression(data[key], dot + " -> " + key, avroTypeBuilder)]

            elif key == "attr": _attr = _readExpression(data[key], dot + " -> " + key, avroTypeBuilder)
            elif key == "if": _ifPredicate = _readExpression(data[key], dot + " -> " + key, avroTypeBuilder)
            elif key == "while": _whilePredicate = _readExpression(data[key], dot + " -> " + key, avroTypeBuilder)
            elif key == "until": _until = _readExpression(data[key], dot + " -> " + key, avroTypeBuilder)
            elif key == "unpack": _unpack = _readExpression(data[key], dot + " -> " + key, avroTypeBuilder)
            elif key == "del": _dell = _readExpression(data[key], dot + " -> " + key, avroTypeBuilder)

            elif key == "cond":
                _cond = _readExpressionArray(data[key], dot + " -> " + key, avroTypeBuilder)
                if any(x.elseClause is not None for x in _cond):
                    raise PFASyntaxException("cond expression must only contain else-less if expressions", pos(dot, at))

            elif key == "cases": _cases = _readCastCaseArray(data[key], dot + " -> " + key, avroTypeBuilder)

            elif key == "foreach": _foreach = _readString(data[key], dot + " -> " + key)
            elif key == "forkey": _forkey = _readString(data[key], dot + " -> " + key)
            elif key == "forval": _forval = _readString(data[key], dot + " -> " + key)
            elif key == "fcn": _fcnref = _readString(data[key], dot + " -> " + key)
            elif key == "cell": _cell = _readString(data[key], dot + " -> " + key)
            elif key == "pool": _pool = _readString(data[key], dot + " -> " + key)

            elif key == "in": _in = _readExpression(data[key], dot + " -> " + key, avroTypeBuilder)
            elif key == "cast": _cast = _readExpression(data[key], dot + " -> " + key, avroTypeBuilder)
            elif key == "upcast": _upcast = _readExpression(data[key], dot + " -> " + key, avroTypeBuilder)
            elif key == "init": _init = _readExpression(data[key], dot + " -> " + key, avroTypeBuilder)
            elif key == "call": _callwith = _readExpression(data[key], dot + " -> " + key, avroTypeBuilder)

            elif key == "seq": _seq = _readBoolean(data[key], dot + " -> " + key)
            elif key == "partial": _partial = _readBoolean(data[key], dot + " -> " + key)

            elif key == "doc": _doc = _readString(data[key], dot + " -> " + key)
            elif key == "error": _error = _readString(data[key], dot + " -> " + key)
            elif key == "code": _code = _readInt(data[key], dot + " -> " + key)
            elif key == "namespace": _namespace = _readString(data[key], dot + " -> " + key)

            elif key == "new":
                if isinstance(data[key], dict):
                    _newObject = _readExpressionMap(data[key], dot + " -> " + key, avroTypeBuilder)
                elif isinstance(data[key], (list, tuple)):
                    _newArray = _readExpressionArray(data[key], dot + " -> " + key, avroTypeBuilder)
                else:
                    raise PFASyntaxException("\"new\" must be an object (map, record) or an array", pos(dot, at))

            elif key == "params": _params = _readParams(data[key], dot + " -> " + key, avroTypeBuilder)
            elif key == "ret": _ret = _readAvroPlaceholder(data[key], dot + " -> " + key, avroTypeBuilder)
            elif key == "as": _as = _readAvroPlaceholder(data[key], dot + " -> " + key, avroTypeBuilder)

            elif key == "to": _to = _readArgument(data[key], dot + " -> " + key, avroTypeBuilder)

            elif key == "fill": _fill = _readArgumentMap(data[key], dot + " -> " + key, avroTypeBuilder)

            elif key == "filter": _filter = _readStringOrIntArray(data[key], dot + " -> " + key)

            elif key == "format": _format = _readStringPairs(data[key], dot + " -> " + key)
            elif key == "pack": _pack = _readStringExpressionPairs(data[key], dot + " -> " + key, avroTypeBuilder)

            else:
                _callName = key
                if isinstance(data[key], (list, tuple)):
                    _callArgs = _readArgumentArray(data[key], dot + " -> " + key, avroTypeBuilder)
                else:
                    _callArgs = [_readArgument(data[key], dot + " -> " + key, avroTypeBuilder)]

        if "foreach" in keys and not validSymbolName(_foreach):
            raise PFASyntaxException("\"{0}\" is not a valid symbol name".format(data[keys]), pos(dot, at))
        if "forkey" in keys and not validSymbolName(_forkey):
            raise PFASyntaxException("\"{0}\" is not a valid symbol name".format(data[keys]), pos(dot, at))
        if "forval" in keys and not validSymbolName(_forval):
            raise PFASyntaxException("\"{0}\" is not a valid symbol name".format(data[keys]), pos(dot, at))
        if "fcn" in keys and not validFunctionName(_fcnref):
            raise PFASyntaxException("\"{0}\" is not a valid function name".format(data[keys]), pos(dot, at))

        if keys == set(["int"]):                             return LiteralInt(_int, pos(dot, at))
        elif keys == set(["long"]):                          return LiteralLong(_long, pos(dot, at))
        elif keys == set(["float"]):                         return LiteralFloat(_float, pos(dot, at))
        elif keys == set(["double"]):                        return LiteralDouble(_double, pos(dot, at))
        elif keys == set(["string"]):                        return LiteralString(_string, pos(dot, at))
        elif keys == set(["base64"]):                        return LiteralBase64(_bytes, pos(dot, at))
        elif keys == set(["type", "value"]):                 return Literal(_avroType, _value, pos(dot, at))

        elif keys == set(["new", "type"]) and _newObject is not None:
                                                             return NewObject(_newObject, _avroType, pos(dot, at))
        elif keys == set(["new", "type"]) and _newArray is not None:
                                                             return NewArray(_newArray, _avroType, pos(dot, at))

        elif keys == set(["do"]):                            return Do(_body, pos(dot, at))
        elif keys == set(["let"]):                           return Let(_let, pos(dot, at))
        elif keys == set(["set"]):                           return SetVar(_set, pos(dot, at))

        elif keys == set(["attr", "path"]):                  return AttrGet(_attr, _path, pos(dot, at))
        elif keys == set(["attr", "path", "to"]):            return AttrTo(_attr, _path, _to, pos(dot, at))
        elif keys == set(["cell"]) or \
             keys == set(["cell", "path"]):                  return CellGet(_cell, _path, pos(dot, at))
        elif keys == set(["cell", "to"]) or \
             keys == set(["cell", "path", "to"]):            return CellTo(_cell, _path, _to, pos(dot, at))
        elif keys == set(["pool", "path"]):                  return PoolGet(_pool, _path, pos(dot, at))
        elif keys == set(["pool", "path", "to", "init"]):    return PoolTo(_pool, _path, _to, _init, pos(dot, at))
        elif keys == set(["pool", "del"]):                   return PoolDel(_pool, _dell, pos(dot, at))

        elif keys == set(["if", "then"]):                    return If(_ifPredicate, _thenClause, None, pos(dot, at))
        elif keys == set(["if", "then", "else"]):            return If(_ifPredicate, _thenClause, _elseClause, pos(dot, at))
        elif keys == set(["cond"]):                          return Cond(_cond, None, pos(dot, at))
        elif keys == set(["cond", "else"]):                  return Cond(_cond, _elseClause, pos(dot, at))

        elif keys == set(["while", "do"]):                   return While(_whilePredicate, _body, pos(dot, at))
        elif keys == set(["do", "until"]):                   return DoUntil(_body, _until, pos(dot, at))
        elif keys == set(["for", "while", "step", "do"]):    return For(_forlet, _whilePredicate, _forstep, _body, pos(dot, at))

        elif keys == set(["foreach", "in", "do"]) or \
             keys == set(["foreach", "in", "do", "seq"]):    return Foreach(_foreach, _in, _body, _seq, pos(dot, at))
        elif keys == set(["forkey", "forval", "in", "do"]):  return Forkeyval(_forkey, _forval, _in, _body, pos(dot, at))

        elif keys == set(["cast", "cases"]) or \
             keys == set(["cast", "cases", "partial"]):      return CastBlock(_cast, _cases, _partial, pos(dot, at))
        elif keys == set(["upcast", "as"]):                  return Upcast(_upcast, _as, pos(dot, at))

        elif keys == set(["ifnotnull", "then"]):             return IfNotNull(_ifnotnull, _thenClause, None, pos(dot, at))
        elif keys == set(["ifnotnull", "then", "else"]):     return IfNotNull(_ifnotnull, _thenClause, _elseClause, pos(dot, at))

        elif keys == set(["pack"]):                          return Pack(_pack, pos(dot, at))
        elif keys == set(["unpack", "format", "then"]):      return Unpack(_unpack, _format, _thenClause, None, pos(dot, at))
        elif keys == set(["unpack", "format", "then", "else"]):
                                                             return Unpack(_unpack, _format, _thenClause, _elseClause, pos(dot, at))

        elif keys == set(["doc"]):                           return Doc(_doc, pos(dot, at))

        elif keys == set(["error"]):                         return Error(_error, None, pos(dot, at))
        elif keys == set(["error", "code"]):                 return Error(_error, _code, pos(dot, at))
        elif keys == set(["try"]) or \
             keys == set(["try", "filter"]):                 return Try(_trycatch, _filter, pos(dot, at))
        elif keys == set(["log"]):                           return Log(_log, None, pos(dot, at))
        elif keys == set(["log", "namespace"]):              return Log(_log, _namespace, pos(dot, at))

        elif keys == set(["params", "ret", "do"]):           return FcnDef(_params, _ret, _body, pos(dot, at))
        elif keys == set(["fcn"]):                           return FcnRef(_fcnref, pos(dot, at))
        elif keys == set(["fcn", "fill"]):                   return FcnRefFill(_fcnref, _fill, pos(dot, at))
        elif keys == set(["call", "args"]):                  return CallUserFcn(_callwith, _callwithargs, pos(dot, at))

        elif len(keys) == 1 and list(keys)[0] not in \
             set(["args", "as", "attr", "base64", "call", "cases", "cast", "cell", "code", "cond", "do", "doc", "double", "else",
                  "error", "fcn", "fill", "filter", "float", "for", "foreach", "forkey", "format", "forval", "if", "ifnotnull", "in", "init",
                  "int", "let", "log", "long", "namespace", "new", "pack", "params", "partial", "path", "pool", "ret", "seq",
                  "set", "step", "string", "then", "to", "try", "type", "unpack", "until", "upcast", "value", "while"]):
                                                             return Call(_callName, _callArgs, pos(dot, at))

        else: raise PFASyntaxException("unrecognized special form: {0} (not enough arguments? too many?)".format(", ".join(keys)), pos(dot, at))

    else:
        raise PFASyntaxException("expected expression, not " + _trunc(repr(data)), dot)