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;
|
|
|
|
unsigned m_precedence;
|
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):
|
2014-10-21 01:40:55 +00:00
|
|
|
m_command(true), m_token(val), m_value(val), m_precedence(LEAN_DEFAULT_PRECEDENCE) {}
|
2014-06-18 16:14:50 +00:00
|
|
|
token_info(char const * token, char const * val):
|
2014-10-21 01:40:55 +00:00
|
|
|
m_command(true), m_token(token), m_value(val), m_precedence(LEAN_DEFAULT_PRECEDENCE) {}
|
2014-06-18 16:14:50 +00:00
|
|
|
token_info(char const * val, unsigned prec):
|
|
|
|
m_command(false), m_token(val), m_value(val), m_precedence(prec) {}
|
|
|
|
token_info(char const * token, char const * val, unsigned prec):
|
|
|
|
m_command(false), m_token(token), m_value(val), m_precedence(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; }
|
|
|
|
unsigned precedence() const { return m_precedence; }
|
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);
|
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);
|
2014-07-07 16:31:42 +00:00
|
|
|
void display(std::ostream & out, token_table const & s);
|
2014-06-10 16:11:45 +00:00
|
|
|
token_table const * find(token_table const & s, char c);
|
2014-06-15 05:13:25 +00:00
|
|
|
optional<unsigned> get_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
|
|
|
}
|