2013-08-18 01:13:55 +00:00
|
|
|
/*
|
|
|
|
Copyright (c) 2013 Microsoft Corporation. All rights reserved.
|
|
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
|
|
|
|
Author: Leonardo de Moura
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <iostream>
|
2013-12-20 03:08:10 +00:00
|
|
|
#include "util/lua.h"
|
2013-12-18 22:37:55 +00:00
|
|
|
#include "kernel/environment.h"
|
|
|
|
#include "library/io_state.h"
|
2013-08-18 01:13:55 +00:00
|
|
|
|
|
|
|
namespace lean {
|
2013-11-27 22:57:33 +00:00
|
|
|
class script_state;
|
2013-08-25 17:34:19 +00:00
|
|
|
/** \brief Functional object for parsing commands and expressions */
|
|
|
|
class parser {
|
2013-12-26 20:58:47 +00:00
|
|
|
public:
|
2013-08-25 17:34:19 +00:00
|
|
|
class imp;
|
2013-12-26 20:58:47 +00:00
|
|
|
private:
|
2013-08-25 17:34:19 +00:00
|
|
|
std::unique_ptr<imp> m_ptr;
|
|
|
|
public:
|
2013-12-18 22:37:55 +00:00
|
|
|
parser(environment const & env, io_state const & st, std::istream & in, script_state * S, bool use_exceptions = true, bool interactive = false);
|
|
|
|
parser(environment const & env, std::istream & in, script_state * S, bool use_exceptions = true, bool interactive = false);
|
2013-08-25 17:34:19 +00:00
|
|
|
~parser();
|
|
|
|
|
|
|
|
/** \brief Parse a sequence of commands */
|
|
|
|
bool operator()();
|
|
|
|
|
|
|
|
/** \brief Parse a single expression */
|
|
|
|
expr parse_expr();
|
2013-12-18 22:37:55 +00:00
|
|
|
|
|
|
|
io_state get_io_state() const;
|
2013-08-25 17:34:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/** \brief Implements the Read Eval Print loop */
|
|
|
|
class shell {
|
2013-12-18 22:37:55 +00:00
|
|
|
environment m_env;
|
|
|
|
io_state m_io_state;
|
|
|
|
script_state * m_script_state;
|
2013-08-25 17:34:19 +00:00
|
|
|
public:
|
2013-12-18 22:37:55 +00:00
|
|
|
shell(environment const & env, io_state const & st, script_state * S);
|
|
|
|
shell(environment const & env, script_state * S);
|
2013-08-25 17:34:19 +00:00
|
|
|
~shell();
|
|
|
|
|
|
|
|
bool operator()();
|
2013-12-18 22:37:55 +00:00
|
|
|
io_state get_io_state() const { return m_io_state; }
|
2013-08-25 17:34:19 +00:00
|
|
|
};
|
|
|
|
|
2013-11-27 22:57:33 +00:00
|
|
|
bool parse_commands(environment const & env, io_state & st, std::istream & in, script_state * S = nullptr, bool use_exceptions = true, bool interactive = false);
|
|
|
|
expr parse_expr(environment const & env, io_state & st, std::istream & in, script_state * S = nullptr, bool use_exceptions = true);
|
2013-12-20 03:08:10 +00:00
|
|
|
|
|
|
|
void open_macros(lua_State * L);
|
2013-08-18 01:13:55 +00:00
|
|
|
}
|