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