2014-06-12 03:56:10 +00:00
|
|
|
/*
|
|
|
|
Copyright (c) 2014 Microsoft Corporation. All rights reserved.
|
|
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
|
|
|
|
Author: Leonardo de Moura
|
|
|
|
*/
|
|
|
|
#include "frontends/lean/builtin_exprs.h"
|
2014-06-13 22:13:32 +00:00
|
|
|
#include "frontends/lean/token_table.h"
|
2014-06-12 16:08:38 +00:00
|
|
|
#include "frontends/lean/parser.h"
|
2014-06-12 03:56:10 +00:00
|
|
|
|
|
|
|
namespace lean {
|
|
|
|
namespace notation {
|
2014-06-12 16:08:38 +00:00
|
|
|
static name g_llevel_curly(".{");
|
|
|
|
static name g_rcurly("}");
|
|
|
|
|
|
|
|
static expr parse_Type(parser & p, unsigned, expr const *) {
|
|
|
|
if (p.curr_is_token(g_llevel_curly)) {
|
|
|
|
p.next();
|
|
|
|
level l = p.parse_level();
|
|
|
|
p.check_token_next(g_rcurly, "invalid Type expression, '}' expected");
|
|
|
|
return mk_sort(l);
|
|
|
|
} else {
|
2014-06-13 18:24:26 +00:00
|
|
|
return p.mk_Type();
|
2014-06-12 16:08:38 +00:00
|
|
|
}
|
|
|
|
}
|
2014-06-12 03:56:10 +00:00
|
|
|
|
|
|
|
parse_table init_nud_table() {
|
|
|
|
action Expr(mk_expr_action());
|
|
|
|
action Skip(mk_skip_action());
|
|
|
|
action Binders(mk_binders_action());
|
|
|
|
expr x0 = mk_var(0);
|
|
|
|
parse_table r;
|
|
|
|
r.add({transition("Bool", Skip)}, Bool);
|
|
|
|
r.add({transition("(", Expr), transition(")", Skip)}, x0);
|
|
|
|
r.add({transition("fun", Binders), transition(",", mk_scoped_expr_action(x0))}, x0);
|
|
|
|
r.add({transition("Pi", Binders), transition(",", mk_scoped_expr_action(x0, 0, false))}, x0);
|
2014-06-12 16:08:38 +00:00
|
|
|
r.add({transition("Type", mk_ext_action(parse_Type))}, x0);
|
2014-06-12 03:56:10 +00:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
parse_table init_led_table() {
|
2014-06-13 22:13:32 +00:00
|
|
|
parse_table r(false);
|
2014-06-14 00:30:35 +00:00
|
|
|
r.add({transition("->", mk_expr_action(get_arrow_prec()-1))}, mk_arrow(Var(0), Var(2)));
|
2014-06-12 03:56:10 +00:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
parse_table get_builtin_nud_table() {
|
|
|
|
static optional<parse_table> r;
|
|
|
|
if (!r)
|
|
|
|
r = notation::init_nud_table();
|
|
|
|
return *r;
|
|
|
|
}
|
|
|
|
|
|
|
|
parse_table get_builtin_led_table() {
|
|
|
|
static optional<parse_table> r;
|
|
|
|
if (!r)
|
|
|
|
r = notation::init_led_table();
|
|
|
|
return *r;
|
|
|
|
}
|
|
|
|
}
|