2014-06-03 09:34:12 +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
|
|
|
|
#include <utility>
|
|
|
|
#include <string>
|
|
|
|
#include "util/trie.h"
|
2014-06-05 19:40:31 +00:00
|
|
|
#include "util/name.h"
|
2014-06-09 23:49:22 +00:00
|
|
|
#include "util/lua.h"
|
2014-06-03 09:34:12 +00:00
|
|
|
|
2014-10-21 01:40:55 +00:00
|
|
|
#ifndef LEAN_DEFAULT_PRECEDENCE
|
|
|
|
#define LEAN_DEFAULT_PRECEDENCE 1
|
|
|
|
#endif
|
|
|
|
|
2014-06-03 09:34:12 +00:00
|
|
|
namespace lean {
|
2015-01-20 02:40:33 +00:00
|
|
|
// User-level maximum precedence
|
2014-06-25 19:50:47 +00:00
|
|
|
unsigned get_max_prec();
|
2015-01-20 02:40:33 +00:00
|
|
|
// Internal maximum precedence used for @ and ! operators
|
|
|
|
unsigned get_Max_prec();
|
2014-06-13 22:13:32 +00:00
|
|
|
unsigned get_arrow_prec();
|
2014-12-04 23:11:23 +00:00
|
|
|
unsigned get_decreasing_prec();
|
2014-06-05 19:40:31 +00:00
|
|
|
class token_info {
|
|
|
|
bool m_command;
|
2014-06-18 16:14:50 +00:00
|
|
|
name m_token;
|
2014-06-05 19:40:31 +00:00
|
|
|
name m_value;
|
2015-04-28 20:43:05 +00:00
|
|
|
unsigned m_expr_precedence;
|
|
|
|
unsigned m_tactic_precedence;
|
|
|
|
token_info(bool c, name const & t, name const & v, unsigned ep, unsigned tp):
|
|
|
|
m_command(c), m_token(t), m_value(v), m_expr_precedence(ep), m_tactic_precedence(tp) {}
|
2014-06-03 09:34:12 +00:00
|
|
|
public:
|
2014-06-05 19:40:31 +00:00
|
|
|
token_info():m_command(true) {}
|
2014-06-18 16:14:50 +00:00
|
|
|
token_info(char const * val):
|
2015-04-28 20:43:05 +00:00
|
|
|
m_command(true), m_token(val), m_value(val), m_expr_precedence(0), m_tactic_precedence(0) {}
|
2014-06-18 16:14:50 +00:00
|
|
|
token_info(char const * token, char const * val):
|
2015-04-28 20:43:05 +00:00
|
|
|
m_command(true), m_token(token), m_value(val), m_expr_precedence(0), m_tactic_precedence(0) {}
|
|
|
|
token_info(char const * token, char const * val, unsigned prec, unsigned tac_prec):
|
|
|
|
m_command(false), m_token(token), m_value(val),
|
|
|
|
m_expr_precedence(prec), m_tactic_precedence(tac_prec) {}
|
2014-06-05 19:40:31 +00:00
|
|
|
bool is_command() const { return m_command; }
|
2014-06-18 16:14:50 +00:00
|
|
|
name const & token() const { return m_token; }
|
2014-06-05 19:40:31 +00:00
|
|
|
name const & value() const { return m_value; }
|
2015-04-28 20:43:05 +00:00
|
|
|
unsigned expr_precedence() const { return m_expr_precedence; }
|
|
|
|
unsigned tactic_precedence() const { return m_tactic_precedence; }
|
|
|
|
token_info update_expr_precedence(unsigned prec) const {
|
|
|
|
return token_info(m_command, m_token, m_value, prec, m_tactic_precedence);
|
|
|
|
}
|
|
|
|
token_info update_tactic_precedence(unsigned prec) const {
|
|
|
|
return token_info(m_command, m_token, m_value, m_expr_precedence, prec);
|
|
|
|
}
|
2014-06-03 09:34:12 +00:00
|
|
|
};
|
2014-06-05 19:40:31 +00:00
|
|
|
|
2014-06-10 16:11:45 +00:00
|
|
|
typedef ctrie<token_info> token_table;
|
|
|
|
token_table mk_token_table();
|
|
|
|
token_table mk_default_token_table();
|
|
|
|
token_table add_command_token(token_table const & s, char const * token);
|
|
|
|
token_table add_command_token(token_table const & s, char const * token, char const * val);
|
2014-10-21 01:40:55 +00:00
|
|
|
token_table add_token(token_table const & s, char const * token, unsigned prec = LEAN_DEFAULT_PRECEDENCE);
|
|
|
|
token_table add_token(token_table const & s, char const * token, char const * val, unsigned prec = LEAN_DEFAULT_PRECEDENCE);
|
2015-04-28 20:43:05 +00:00
|
|
|
token_table add_tactic_token(token_table const & s, char const * token, unsigned prec = LEAN_DEFAULT_PRECEDENCE);
|
|
|
|
token_table add_tactic_token(token_table const & s, char const * token, char const * val, unsigned prec = LEAN_DEFAULT_PRECEDENCE);
|
2014-06-10 16:11:45 +00:00
|
|
|
void for_each(token_table const & s, std::function<void(char const *, token_info const&)> const & fn);
|
|
|
|
token_table const * find(token_table const & s, char c);
|
2015-04-28 20:43:05 +00:00
|
|
|
optional<unsigned> get_expr_precedence(token_table const & s, char const * token);
|
|
|
|
optional<unsigned> get_tactic_precedence(token_table const & s, char const * token);
|
2014-09-06 03:59:14 +00:00
|
|
|
bool is_token(token_table const & s, char const * token);
|
2014-06-10 16:11:45 +00:00
|
|
|
token_info const * value_of(token_table const & s);
|
|
|
|
void open_token_table(lua_State * L);
|
2014-09-23 17:00:36 +00:00
|
|
|
void initialize_token_table();
|
|
|
|
void finalize_token_table();
|
2014-06-03 09:34:12 +00:00
|
|
|
}
|