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
|
|
|
|
|
|
|
namespace lean {
|
2014-06-13 22:13:32 +00:00
|
|
|
unsigned get_arrow_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):
|
|
|
|
m_command(true), m_token(val), m_value(val), m_precedence(0) {}
|
|
|
|
token_info(char const * token, char const * val):
|
|
|
|
m_command(true), m_token(token), m_value(val), m_precedence(0) {}
|
|
|
|
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);
|
|
|
|
token_table add_token(token_table const & s, char const * token, unsigned prec = 0);
|
|
|
|
token_table add_token(token_table const & s, char const * token, char const * val, unsigned prec = 0);
|
|
|
|
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);
|
2014-06-15 05:13:25 +00:00
|
|
|
optional<unsigned> get_precedence(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-06-03 09:34:12 +00:00
|
|
|
}
|