feat(frontends/lean): parse "decreasing" expressions

This commit is contained in:
Leonardo de Moura 2014-12-04 15:11:23 -08:00
parent e267b2d120
commit 52334dca29
4 changed files with 22 additions and 15 deletions

View file

@ -18,6 +18,7 @@ Author: Leonardo de Moura
#include "library/typed_expr.h" #include "library/typed_expr.h"
#include "library/choice.h" #include "library/choice.h"
#include "library/let.h" #include "library/let.h"
#include "library/definitional/equations.h"
#include "frontends/lean/builtin_exprs.h" #include "frontends/lean/builtin_exprs.h"
#include "frontends/lean/token_table.h" #include "frontends/lean/token_table.h"
#include "frontends/lean/calc.h" #include "frontends/lean/calc.h"
@ -507,7 +508,8 @@ parse_table init_nud_table() {
parse_table init_led_table() { parse_table init_led_table() {
parse_table r(false); parse_table r(false);
r = r.add({transition("->", mk_expr_action(get_arrow_prec()-1))}, mk_arrow(Var(1), Var(1))); r = r.add({transition("->", mk_expr_action(get_arrow_prec()-1))}, mk_arrow(Var(1), Var(1)));
r = r.add({transition("<d", mk_expr_action(get_decreasing_prec()))}, mk_decreasing(Var(1), Var(0)));
return r; return r;
} }
} }

View file

@ -32,6 +32,7 @@ Author: Leonardo de Moura
namespace lean { namespace lean {
void initialize_frontend_lean_module() { void initialize_frontend_lean_module() {
initialize_info_annotation();
initialize_tokens(); initialize_tokens();
initialize_token_table(); initialize_token_table();
initialize_parse_table(); initialize_parse_table();
@ -42,7 +43,6 @@ void initialize_frontend_lean_module() {
initialize_pp_options(); initialize_pp_options();
initialize_scanner(); initialize_scanner();
initialize_parser(); initialize_parser();
initialize_info_annotation();
initialize_tactic_hint(); initialize_tactic_hint();
initialize_class(); initialize_class();
initialize_parser_config(); initialize_parser_config();
@ -73,7 +73,6 @@ void finalize_frontend_lean_module() {
finalize_parser_config(); finalize_parser_config();
finalize_class(); finalize_class();
finalize_tactic_hint(); finalize_tactic_hint();
finalize_info_annotation();
finalize_parser(); finalize_parser();
finalize_scanner(); finalize_scanner();
finalize_pp_options(); finalize_pp_options();
@ -84,5 +83,6 @@ void finalize_frontend_lean_module() {
finalize_parse_table(); finalize_parse_table();
finalize_token_table(); finalize_token_table();
finalize_tokens(); finalize_tokens();
finalize_info_annotation();
} }
} }

View file

@ -10,12 +10,14 @@ Author: Leonardo de Moura
#include "frontends/lean/token_table.h" #include "frontends/lean/token_table.h"
namespace lean { namespace lean {
static unsigned g_arrow_prec = 25; static unsigned g_arrow_prec = 25;
static unsigned g_max_prec = 1024; static unsigned g_decreasing_prec = 25;
static unsigned g_plus_prec = 65; static unsigned g_max_prec = 1024;
static unsigned g_cup_prec = 60; static unsigned g_plus_prec = 65;
static unsigned g_cup_prec = 60;
unsigned get_max_prec() { return g_max_prec; } unsigned get_max_prec() { return g_max_prec; }
unsigned get_arrow_prec() { return g_arrow_prec; } unsigned get_arrow_prec() { return g_arrow_prec; }
unsigned get_decreasing_prec() { return g_decreasing_prec; }
token_table add_command_token(token_table const & s, char const * token) { token_table add_command_token(token_table const & s, char const * token) {
return insert(s, token, token_info(token)); return insert(s, token, token_info(token));
} }
@ -60,12 +62,13 @@ void display(std::ostream & out, token_table const & s) {
}); });
} }
static char const * g_lambda_unicode = "\u03BB"; static char const * g_lambda_unicode = "\u03BB";
static char const * g_pi_unicode = "\u03A0"; static char const * g_pi_unicode = "\u03A0";
static char const * g_forall_unicode = "\u2200"; static char const * g_forall_unicode = "\u2200";
static char const * g_arrow_unicode = "\u2192"; static char const * g_arrow_unicode = "\u2192";
static char const * g_cup = "\u2294"; static char const * g_cup = "\u2294";
static char const * g_qed_unicode = ""; static char const * g_qed_unicode = "";
static char const * g_decreasing_unicode = "";
void init_token_table(token_table & t) { void init_token_table(token_table & t) {
pair<char const *, unsigned> builtin[] = pair<char const *, unsigned> builtin[] =
@ -76,8 +79,8 @@ void init_token_table(token_table & t) {
{"using", 0}, {"|", 0}, {"!", g_max_prec}, {"with", 0}, {"...", 0}, {",", 0}, {"using", 0}, {"|", 0}, {"!", g_max_prec}, {"with", 0}, {"...", 0}, {",", 0},
{".", 0}, {":", 0}, {"::", 0}, {"calc", 0}, {":=", 0}, {"--", 0}, {"#", 0}, {".", 0}, {":", 0}, {"::", 0}, {"calc", 0}, {":=", 0}, {"--", 0}, {"#", 0},
{"(*", 0}, {"/-", 0}, {"begin", g_max_prec}, {"proof", g_max_prec}, {"qed", 0}, {"@", g_max_prec}, {"(*", 0}, {"/-", 0}, {"begin", g_max_prec}, {"proof", g_max_prec}, {"qed", 0}, {"@", g_max_prec},
{"sorry", g_max_prec}, {"+", g_plus_prec}, {g_cup, g_cup_prec}, {"->", g_arrow_prec}, {"local", 0}, {"sorry", g_max_prec}, {"+", g_plus_prec}, {g_cup, g_cup_prec}, {"->", g_arrow_prec},
{"renaming", 0}, {"extends", 0}, {nullptr, 0}}; {"<d", g_decreasing_prec}, {"local", 0}, {"renaming", 0}, {"extends", 0}, {nullptr, 0}};
char const * commands[] = char const * commands[] =
{"theorem", "axiom", "variable", "protected", "private", "opaque", "definition", "example", "coercion", {"theorem", "axiom", "variable", "protected", "private", "opaque", "definition", "example", "coercion",
@ -116,6 +119,7 @@ void init_token_table(token_table & t) {
it3++; it3++;
} }
t = add_token(t, g_arrow_unicode, "->", get_arrow_prec()); t = add_token(t, g_arrow_unicode, "->", get_arrow_prec());
t = add_token(t, g_decreasing_unicode, "<d", get_decreasing_prec());
auto it4 = cmd_aliases; auto it4 = cmd_aliases;
while (it4->first) { while (it4->first) {

View file

@ -18,6 +18,7 @@ Author: Leonardo de Moura
namespace lean { namespace lean {
unsigned get_max_prec(); unsigned get_max_prec();
unsigned get_arrow_prec(); unsigned get_arrow_prec();
unsigned get_decreasing_prec();
class token_info { class token_info {
bool m_command; bool m_command;
name m_token; name m_token;