Example #1
0
 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)
Example #2
0
 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)
Example #3
0
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")
Example #4
0
 def process(parsed, loc):
     [attrs, _, elementType, _, getName, _, setName, _, lengthName, _] = ct.untangle(parsed)
     return ast.ArrayElementsStatement(attrs, elementType,
                                          getName, setName, lengthName, loc)
Example #5
0
 def process(parsed, loc):
     if parsed is None:
         return None, None
     else:
         [_, supertype, args] = ct.untangle(parsed)
         return supertype, args
Example #6
0
 def process(parsed, loc):
     [ats, _, params, _] = ct.untangle(parsed)
     return ast.AstPrimaryConstructorDefinition(ats, params, loc)
Example #7
0
 def process(parsed, loc):
     [ats, _, name, tps, ps, rty, body, _] = ct.untangle(parsed)
     return ast.AstFunctionDefinition(ats, name, tps, ps, rty, body, loc)
Example #8
0
 def process(parsed, loc):
     [ats, kw, pat, expr, _] = ct.untangle(parsed)
     return ast.AstVariableDefinition(ats, kw, pat, expr, loc)
Example #9
0
 def processSimple(parsed, loc):
     [_, p, _, e] = ct.untangle(parsed)
     return ast.AstPartialFunctionExpression([ast.AstPartialFunctionCase(p, None, e, loc)], loc)
Example #10
0
 def process(parsed, loc):
     [_, _, e, _, m] = ct.untangle(parsed)
     return ast.AstMatchExpression(e, m, loc)
Example #11
0
 def process(parsed, loc):
     _, _, tps, _, ty = ct.untangle(parsed)
     return ast.ExistentialType(tps, ty, loc)
Example #12
0
 def process(parsed, loc):
     _, first, _, rest, _, nullFlag = ct.untangle(parsed)
     flags = set([nullFlag]) if nullFlag else set()
     return ast.TupleType([first] + rest, flags, loc)
Example #13
0
 def process(parsed, loc):
     _, p, _ = ct.untangle(parsed)
     return p
Example #14
0
 def processSuffix(parsed, loc):
     return ct.untangle(parsed)[1]
Example #15
0
 def process(parsed, loc):
     [_, _, c, _, b] = ct.untangle(parsed)
     return ast.AstWhileExpression(c, b, loc)
Example #16
0
 def process(parsed, loc):
     [_, _, length, _, ty, args] = ct.untangle(parsed)
     return ast.NewArrayExpression(length, ty, args, loc)
Example #17
0
 def process(parsed, loc):
     [_, p, c, _, e, _] = ct.untangle(parsed)
     return ast.AstPartialFunctionCase(p, c, e, loc)
Example #18
0
 def process(parsed, loc):
     [ats, var, name, upper, lower] = ct.untangle(parsed)
     return ast.AstTypeParameter(ats, var, name, upper, lower, loc)
Example #19
0
 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)
Example #20
0
 def process(parsed, loc):
     [ats, var, pat] = ct.untangle(parsed)
     return ast.AstParameter(ats, var, pat, loc)
Example #21
0
 def process(parsed, loc):
     [_, n, tps, _, ps, _, b] = ct.untangle(parsed)
     return ast.AstLambdaExpression(n, tps, ps, b, loc)
Example #22
0
 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)
Example #23
0
 def process(parsed, loc):
     [_, ast, _] = ct.untangle(parsed)
     return ast
Example #24
0
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
Example #25
0
 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)
Example #26
0
 def process(parsed, _):
     [_, e, _] = ct.untangle(parsed)
     return e
Example #27
0
 def processArgs(parsed, loc):
     return ct.untangle(parsed)[1] if parsed is not None else []
Example #28
0
 def process(parsed, loc):
     [_, _, c, _, t, f] = ct.untangle(parsed)
     return ast.AstIfExpression(c, t, f, loc)
Example #29
0
 def process(parsed, _):
     return ct.untangle(parsed)[1] if parsed else []
Example #30
0
 def process(parsed, loc):
     _, prefix, suffixFn, _ = ct.untangle(parsed)
     bindings = suffixFn(prefix)
     return ast.ImportStatement(prefix, bindings, loc)