Example #1
0
 def p_body_do(self, ss, semi, e):
     assert ast.isloc(ss)
     if e is None:
         e = ast.update_value(semi, val.symbol('pass'))
     assert ast.isloc(e)
     do = ast.locmerge(ss, e, val.symbol('do'))
     return ast.locmerge(ss, e, [do] + ss.value + [e])
Example #2
0
 def p_primary_if(self, k, po, p, pc, co, c, cc, ke, ao, a, ac):
     assert ast.isloc(p)
     assert ast.isloc(c)
     assert ast.isloc(a)
     return ast.locmerge(
         k, ac,
         [ast.map_value(val.symbol, ast.update_value(k, 'if')), p, c, a])
Example #3
0
 def p_primary_language(self, ll):
     assert ast.isloc(ll), '%r' % (ll, )
     l = ll.value
     (start, _end) = ll.loc
     assert ast.isloc(l), '%r' % (l, )
     l_ = adjlocust(l, start)
     return l_
Example #4
0
 def _p_binop(self, l, op, r):
     assert ast.isloc(l)
     assert ast.isloc(r)
     if op.value in operators:
         # Perform operator substitution
         new_op = ast.update_value(op, operators[op.value])
     else:
         # Leave it
         new_op = op
     app = [ast.map_value(val.symbol, new_op), l, r]
     return ast.locmerge(l, r, app)
Example #5
0
 def p_arrow_tuple(self, po, params, pc, op, body):
     assert ast.isloc(body)
     return ast.locmerge(po, body, [
         ast.map_value(val.symbol, ast.update_value(op, 'lambda')),
         ast.locmerge(po, pc, params),
         body,
     ])
Example #6
0
 def p_primary_proc(self, k, po, params, pc, bo, body, bc):
     assert ast.isloc(body)
     return ast.locmerge(k, bc, [
         ast.map_value(val.symbol, ast.update_value(k, 'lambda')),
         ast.locmerge(po, pc, params),
         body,
     ])
Example #7
0
 def p_arrow_one(self, param, op, body):
     assert ast.isloc(body)
     param = ast.map_value(val.symbol, param)
     return ast.locmerge(param, body, [
         ast.map_value(val.symbol, ast.update_value(op, 'lambda')),
         ast.update_value(param, [param]),
         body,
     ])
Example #8
0
def delocust(l):
    # XXX Why do we bother with tuples in the first place?
    if isinstance(l, dict) and sorted(l.keys()) == ['loc', 'value']:
        return delocust(l['value'])
    elif ast.isloc(l):
        return delocust(l.value)
    elif isinstance(l, list) or isinstance(l, tuple):
        return [delocust(v) for v in l]
    elif isinstance(l, dict):
        return dict((k, delocust(v)) for k, v in l.iteritems())
    else:
        return l
Example #9
0
def parse(f, context, languages=None):
    scanner = scan.Scanner(f, context, languages)
    semantics = Semantics()
    parser = grammar.Parser(semantics)
    while True:
        token = scanner.read()
        if token[0] == -1:  # error
            semantics.syntax_error(token)
        else:
            if token[0] == 0:  # EOF
                # Implicit ; at EOF.
                loc = (scanner.cur_pos, scanner.cur_pos)
                parser.feed((grammar.T_SEMI, ast.Located(loc, ';')))
            parser.feed(token)
        if token[0] == 0:  # EOF
            break
    assert isinstance(semantics.answer, list)
    for i in semantics.answer:
        assert ast.isloc(i)
    return semantics.answer
Example #10
0
 def p_applicative_lookup(self, a, o, index, c):
     assert ast.isloc(a)
     assert ast.isloc(index)
     lookup = ast.update_value(o, val.sym('lookup'))
     return ast.locmerge(a, c, [lookup, a, index])
Example #11
0
 def p_applicative_none(self, e):
     assert ast.isloc(e)
     return e
Example #12
0
 def p_path_expression_some(self, more, slash, s):
     # XXX Is this just _p_binop with the "slash" operator?
     assert ast.isloc(s)
     intersect = ast.update_value(slash, val.symbol('by_walk'))
     app = [intersect, more, s]
     return ast.locmerge(more, s, app)
Example #13
0
 def p_applicative_app(self, fn, o, args, c):
     assert ast.isloc(fn)
     for arg in args:
         assert ast.isloc(arg)
     return ast.locmerge(fn, c, [fn] + args)
Example #14
0
 def p_body_exp(self, e):
     assert ast.isloc(e)
     return e
Example #15
0
 def p_expression_opt_some(self, e):
     assert ast.isloc(e)
     return e
Example #16
0
 def p_action_sample(self, k, e):
     assert ast.isloc(e)
     i = ast.update_value(k, val.symbol('sample'))
     app = [i, e]
     return ast.locmerge(i, e, app)
Example #17
0
 def p_statements_one(self, s):
     assert ast.isloc(s)
     return ast.update_value(s, [s])
Example #18
0
 def p_action_directive(self, d):
     assert ast.isloc(d)
     return d
Example #19
0
 def p_statement_letvalues(self, l, po, names, pc, eq, e):
     assert ast.isloc(e)
     assert all(map(ast.isloc, names))
     let = ast.update_value(l, val.symbol('let_values'))
     names = ast.locmerge(po, pc, names)
     return ast.locmerge(let, e, [let, names, e])
Example #20
0
 def p_do_bind_labelled(self, n, op, l):
     assert ast.isloc(l)
     # XXX Yes, this remains infix, for the macro expander to handle...
     # XXX Convert <~ to <- for the macro expander's sake
     expression = [n, ast.update_value(op, val.symbol("<-")), l]
     return ast.locmerge(n, l, expression)
Example #21
0
 def _p_exp(self, e):
     assert ast.isloc(e)
     return e
Example #22
0
 def p_statement_labelled(self, d):
     assert ast.isloc(d)
     return d
Example #23
0
 def p_primary_brace(self, o, e, c):
     assert ast.isloc(e)
     return ast.locmerge(o, c, e.value)
Example #24
0
 def p_statement_mutrec(self, l, n, eq, e):
     assert ast.isloc(e)
     let = ast.update_value(l, val.symbol('mutrec'))
     n = ast.map_value(val.symbol, n)
     return ast.locmerge(let, e, [let, n, e])
Example #25
0
 def p_statements_many(self, ss, semi, s):
     assert ast.isloc(s)
     assert ast.isloc(s)
     ss.value.append(s)
     return ast.locmerge(ss, s, ss.value)
Example #26
0
 def p_statement_assign(self, n, eq, e):
     assert ast.isloc(e)
     let = ast.update_value(eq, val.symbol('let'))
     n = ast.map_value(val.symbol, n)
     return ast.locmerge(n, e, [let, n, e])
Example #27
0
 def p_primary_literal(self, l):
     assert ast.isloc(l)
     return l
Example #28
0
 def p_path_expression_one(self, slash, s):
     assert ast.isloc(s)
     top = ast.update_value(slash, val.symbol('by_top'))
     intersect = ast.update_value(slash, val.symbol('by_walk'))
     app = [intersect, ast.loclist([top]), s]
     return ast.locmerge(top, s, app)
Example #29
0
 def p_action_force(self, k, e1, eq, e2):
     assert ast.isloc(e1)
     assert ast.isloc(e2)
     i = ast.update_value(k, val.symbol('force'))
     app = [i, e1, e2]
     return ast.locmerge(i, e2, app)
Example #30
0
 def p_statement_none(self, e):
     assert ast.isloc(e)
     return e