2014-06-10 17:39:22 +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
|
|
|
|
*/
|
|
|
|
#pragma once
|
2014-06-17 17:12:04 +00:00
|
|
|
#include <string>
|
2014-06-10 17:39:22 +00:00
|
|
|
#include "kernel/environment.h"
|
|
|
|
#include "frontends/lean/token_table.h"
|
|
|
|
#include "frontends/lean/parse_table.h"
|
2014-06-11 00:02:06 +00:00
|
|
|
#include "frontends/lean/cmd_table.h"
|
2014-06-10 17:39:22 +00:00
|
|
|
|
|
|
|
namespace lean {
|
2014-06-17 17:12:04 +00:00
|
|
|
struct token_entry {
|
|
|
|
std::string m_token;
|
|
|
|
unsigned m_prec;
|
|
|
|
token_entry(std::string const & tk, unsigned prec):m_token(tk), m_prec(prec) {}
|
|
|
|
};
|
|
|
|
|
2014-10-03 20:47:49 +00:00
|
|
|
enum class notation_entry_kind { NuD, LeD, Numeral };
|
|
|
|
|
|
|
|
class notation_entry {
|
2014-06-17 17:12:04 +00:00
|
|
|
typedef notation::transition transition;
|
2014-10-03 20:47:49 +00:00
|
|
|
notation_entry_kind m_kind;
|
|
|
|
union {
|
|
|
|
list<transition> m_transitions;
|
|
|
|
mpz m_num;
|
|
|
|
};
|
|
|
|
expr m_expr;
|
|
|
|
bool m_overload;
|
2014-10-18 18:49:27 +00:00
|
|
|
bool m_safe_ascii;
|
2014-10-21 20:30:40 +00:00
|
|
|
bool m_reserve;
|
2014-10-03 20:47:49 +00:00
|
|
|
public:
|
|
|
|
notation_entry();
|
|
|
|
notation_entry(notation_entry const & e);
|
2014-10-21 20:30:40 +00:00
|
|
|
notation_entry(bool is_nud, list<transition> const & ts, expr const & e, bool overload, bool reserve);
|
2014-10-03 20:47:49 +00:00
|
|
|
notation_entry(mpz const & val, expr const & e, bool overload);
|
|
|
|
notation_entry(notation_entry const & e, bool overload);
|
|
|
|
~notation_entry();
|
|
|
|
notation_entry_kind kind() const { return m_kind; }
|
|
|
|
bool is_numeral() const { return m_kind == notation_entry_kind::Numeral; }
|
|
|
|
bool is_nud() const { return m_kind == notation_entry_kind::NuD; }
|
|
|
|
list<transition> const & get_transitions() const { lean_assert(!is_numeral()); return m_transitions; }
|
|
|
|
mpz const & get_num() const { lean_assert(is_numeral()); return m_num; }
|
|
|
|
expr const & get_expr() const { return m_expr; }
|
|
|
|
bool overload() const { return m_overload; }
|
2014-10-18 18:49:27 +00:00
|
|
|
bool is_safe_ascii() const { return m_safe_ascii; }
|
2014-10-21 20:30:40 +00:00
|
|
|
bool reserve() const { return m_reserve; }
|
2014-06-17 17:12:04 +00:00
|
|
|
};
|
2014-10-18 18:49:27 +00:00
|
|
|
bool operator==(notation_entry const & e1, notation_entry const & e2);
|
|
|
|
inline bool operator!=(notation_entry const & e1, notation_entry const & e2) {
|
|
|
|
return !(e1 == e2);
|
|
|
|
}
|
2014-06-17 17:12:04 +00:00
|
|
|
|
2014-07-19 23:23:55 +00:00
|
|
|
/** \brief Apply \c f to expressions embedded in the notation entry */
|
|
|
|
notation_entry replace(notation_entry const & e, std::function<expr(expr const &)> const & f);
|
|
|
|
|
2014-06-17 17:12:04 +00:00
|
|
|
environment add_token(environment const & env, token_entry const & e);
|
|
|
|
environment add_notation(environment const & env, notation_entry const & e);
|
|
|
|
|
2014-06-15 05:13:25 +00:00
|
|
|
environment add_token(environment const & env, char const * val, unsigned prec);
|
2014-09-26 21:54:39 +00:00
|
|
|
environment add_nud_notation(environment const & env, unsigned num, notation::transition const * ts, expr const & a,
|
2014-10-21 20:30:40 +00:00
|
|
|
bool overload = true, bool reserve = false);
|
2014-09-26 21:54:39 +00:00
|
|
|
environment add_led_notation(environment const & env, unsigned num, notation::transition const * ts, expr const & a,
|
2014-10-21 20:30:40 +00:00
|
|
|
bool overload = true, bool reserve = false);
|
2014-06-15 18:50:41 +00:00
|
|
|
environment add_nud_notation(environment const & env, std::initializer_list<notation::transition> const & ts, expr const & a,
|
|
|
|
bool overload = true);
|
|
|
|
environment add_led_notation(environment const & env, std::initializer_list<notation::transition> const & ts, expr const & a,
|
|
|
|
bool overload = true);
|
2014-06-15 05:13:25 +00:00
|
|
|
token_table const & get_token_table(environment const & env);
|
|
|
|
parse_table const & get_nud_table(environment const & env);
|
|
|
|
parse_table const & get_led_table(environment const & env);
|
2014-10-21 20:30:40 +00:00
|
|
|
parse_table const & get_reserved_nud_table(environment const & env);
|
|
|
|
parse_table const & get_reserved_led_table(environment const & env);
|
2014-06-15 05:13:25 +00:00
|
|
|
cmd_table const & get_cmd_table(environment const & env);
|
2014-06-23 23:10:36 +00:00
|
|
|
/** \brief Force notation from namespace \c n to shadow any existing notation */
|
|
|
|
environment overwrite_notation(environment const & env, name const & n);
|
2014-09-23 00:30:29 +00:00
|
|
|
|
2014-09-26 21:54:39 +00:00
|
|
|
/** \brief Add \c n as notation for \c e */
|
|
|
|
environment add_mpz_notation(environment const & env, mpz const & n, expr const & e, bool overload = true);
|
|
|
|
/** \brief Return the additional interpretations for \c n in the current environment.
|
|
|
|
|
|
|
|
\remark It does not include the default one based on the \c num inductive datatype.
|
|
|
|
*/
|
|
|
|
list<expr> get_mpz_notation(environment const & env, mpz const & n);
|
|
|
|
|
2014-10-18 18:49:27 +00:00
|
|
|
/** \brief Return the notation declaration that start with a given head symbol.
|
|
|
|
|
|
|
|
\remark Notation declarations that contain C++ and Lua actions are not indexed.
|
|
|
|
Thus, they are to included in the result.
|
|
|
|
*/
|
|
|
|
list<notation_entry> get_notation_entries(environment const & env, head_index const & idx);
|
|
|
|
|
2014-09-23 00:30:29 +00:00
|
|
|
void initialize_parser_config();
|
|
|
|
void finalize_parser_config();
|
2014-06-10 17:39:22 +00:00
|
|
|
}
|