def process(parsed, loc): parsed = ct.untangle(parsed) if len(parsed) == 2: return parsed[0] else: sty = parsed[0] tps = parsed[3] return ast.ExistentialType(sty, tps, loc)
def process(parsed, loc): prefixComponents, nullFlag = ct.untangle(parsed) prefix = prefixComponents[:-1] last = prefixComponents[-1] name = last.name typeArgs = last.typeArguments if last.typeArguments is not None else [] flags = set([nullFlag]) if nullFlag is not None else set() return ast.ClassType(prefix, name, typeArgs, flags, loc)
def processCall(receiver, parsed, loc): [methodName, typeArguments, arguments, isGetMethod] = ct.untangle(parsed) if isGetMethod: if methodName is None or \ typeArguments is not None or \ arguments is not None: return ct.FailValue() return ast.FunctionValueExpression(ast.PropertyExpression(receiver, methodName, loc), loc) elif methodName is not None or \ typeArguments is not None or \ arguments is not None: hasArguments = typeArguments is not None or arguments is not None if methodName is not None: method = ast.PropertyExpression(receiver, methodName, loc) else: method = receiver if hasArguments: return ast.CallExpression(method, typeArguments, arguments, loc) else: return method else: return ct.FailValue("not a call")
def process(parsed, loc): [attrs, _, elementType, _, getName, _, setName, _, lengthName, _] = ct.untangle(parsed) return ast.ArrayElementsStatement(attrs, elementType, getName, setName, lengthName, loc)
def process(parsed, loc): if parsed is None: return None, None else: [_, supertype, args] = ct.untangle(parsed) return supertype, args
def process(parsed, loc): [ats, _, params, _] = ct.untangle(parsed) return ast.AstPrimaryConstructorDefinition(ats, params, loc)
def process(parsed, loc): [ats, _, name, tps, ps, rty, body, _] = ct.untangle(parsed) return ast.AstFunctionDefinition(ats, name, tps, ps, rty, body, loc)
def process(parsed, loc): [ats, kw, pat, expr, _] = ct.untangle(parsed) return ast.AstVariableDefinition(ats, kw, pat, expr, loc)
def processSimple(parsed, loc): [_, p, _, e] = ct.untangle(parsed) return ast.AstPartialFunctionExpression([ast.AstPartialFunctionCase(p, None, e, loc)], loc)
def process(parsed, loc): [_, _, e, _, m] = ct.untangle(parsed) return ast.AstMatchExpression(e, m, loc)
def process(parsed, loc): _, _, tps, _, ty = ct.untangle(parsed) return ast.ExistentialType(tps, ty, loc)
def process(parsed, loc): _, first, _, rest, _, nullFlag = ct.untangle(parsed) flags = set([nullFlag]) if nullFlag else set() return ast.TupleType([first] + rest, flags, loc)
def process(parsed, loc): _, p, _ = ct.untangle(parsed) return p
def processSuffix(parsed, loc): return ct.untangle(parsed)[1]
def process(parsed, loc): [_, _, c, _, b] = ct.untangle(parsed) return ast.AstWhileExpression(c, b, loc)
def process(parsed, loc): [_, _, length, _, ty, args] = ct.untangle(parsed) return ast.NewArrayExpression(length, ty, args, loc)
def process(parsed, loc): [_, p, c, _, e, _] = ct.untangle(parsed) return ast.AstPartialFunctionCase(p, c, e, loc)
def process(parsed, loc): [ats, var, name, upper, lower] = ct.untangle(parsed) return ast.AstTypeParameter(ats, var, name, upper, lower, loc)
def process(parsed, loc): [_, e, c, f] = ct.untangle(parsed) if c is None and f is None: return ct.FailValue("expected 'catch' or 'finally' in 'try'-expression") else: return ast.AstTryCatchExpression(e, c, f, loc)
def process(parsed, loc): [ats, var, pat] = ct.untangle(parsed) return ast.AstParameter(ats, var, pat, loc)
def process(parsed, loc): [_, n, tps, _, ps, _, b] = ct.untangle(parsed) return ast.AstLambdaExpression(n, tps, ps, b, loc)
def process(parsed, loc): name, typeArgs, nullFlag = ct.untangle(parsed) typeArgs = [] if typeArgs is None else typeArgs flags = set([nullFlag]) if nullFlag else set() return ast.AstClassType(name, typeArgs, flags, loc)
def process(parsed, loc): [_, ast, _] = ct.untangle(parsed) return ast
def callSuffix(): methodNameOpt = ct.Opt(keyword(".") + symbol ^ (lambda p, _: p[1])) argumentsOpt = ct.Opt(keyword("(") + ct.RepSep(ct.Lazy(expression), keyword(",")) + keyword(")")) ^ \ (lambda p, _: ct.untangle(p)[1] if p else None) getMethodOpt = ct.Opt(keyword("_")) ^ (lambda p, _: bool(p)) return methodNameOpt + typeArguments() + argumentsOpt + getMethodOpt
def process(parsed, loc): [ats, _, name, tps, ctor, sty, sargs, ms, _] = ct.untangle(parsed) return ast.AstClassDefinition(ats, name, tps, ctor, sty, sargs, ms, loc)
def process(parsed, _): [_, e, _] = ct.untangle(parsed) return e
def processArgs(parsed, loc): return ct.untangle(parsed)[1] if parsed is not None else []
def process(parsed, loc): [_, _, c, _, t, f] = ct.untangle(parsed) return ast.AstIfExpression(c, t, f, loc)
def process(parsed, _): return ct.untangle(parsed)[1] if parsed else []
def process(parsed, loc): _, prefix, suffixFn, _ = ct.untangle(parsed) bindings = suffixFn(prefix) return ast.ImportStatement(prefix, bindings, loc)