xo-reader: distinguish interactive sessions
+ allow top-level i64 literals
This commit is contained in:
parent
2025969068
commit
a12a236bc1
16 changed files with 196 additions and 13 deletions
|
|
@ -245,6 +245,18 @@ namespace xo {
|
|||
this->illegal_input_error(self_name, tk);
|
||||
}
|
||||
|
||||
void
|
||||
define_xs::on_i64_token(const token_type & tk,
|
||||
parserstatemachine * /*p_psm*/)
|
||||
{
|
||||
constexpr bool c_debug_flag = true;
|
||||
scope log(XO_DEBUG(c_debug_flag));
|
||||
|
||||
constexpr const char * self_name = "define_xs::on_i64";
|
||||
|
||||
this->illegal_input_error(self_name, tk);
|
||||
}
|
||||
|
||||
void
|
||||
define_xs::on_f64_token(const token_type & tk,
|
||||
parserstatemachine * /*p_psm*/)
|
||||
|
|
|
|||
|
|
@ -172,6 +172,17 @@ namespace xo {
|
|||
return;
|
||||
}
|
||||
|
||||
void
|
||||
expect_expr_xs::on_i64_token(const token_type & tk,
|
||||
parserstatemachine * p_psm)
|
||||
{
|
||||
constexpr bool c_debug_flag = true;
|
||||
scope log(XO_DEBUG(c_debug_flag));
|
||||
|
||||
progress_xs::start
|
||||
(Constant<int64_t>::make(tk.i64_value()),
|
||||
p_psm);
|
||||
}
|
||||
|
||||
void
|
||||
expect_expr_xs::on_f64_token(const token_type & tk,
|
||||
|
|
|
|||
|
|
@ -3,25 +3,28 @@
|
|||
#include "exprseq_xs.hpp"
|
||||
#include "parserstatemachine.hpp"
|
||||
#include "exprstatestack.hpp"
|
||||
#include "exprseq_xs.hpp"
|
||||
#include "expect_expr_xs.hpp"
|
||||
#include "define_xs.hpp"
|
||||
#include "expect_symbol_xs.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
std::unique_ptr<exprseq_xs>
|
||||
exprseq_xs::make()
|
||||
exprseq_xs::make(exprseqtype seqtype)
|
||||
{
|
||||
return std::make_unique<exprseq_xs>(exprseq_xs());
|
||||
return std::make_unique<exprseq_xs>(exprseq_xs(seqtype));
|
||||
}
|
||||
|
||||
void
|
||||
exprseq_xs::start(parserstatemachine * p_psm)
|
||||
exprseq_xs::start(exprseqtype seqtype, parserstatemachine * p_psm)
|
||||
{
|
||||
p_psm->push_exprstate(exprseq_xs::make());
|
||||
p_psm->push_exprstate(exprseq_xs::make(seqtype));
|
||||
}
|
||||
|
||||
exprseq_xs::exprseq_xs()
|
||||
: exprstate(exprstatetype::expect_toplevel_expression_sequence)
|
||||
exprseq_xs::exprseq_xs(exprseqtype x)
|
||||
: exprstate(exprstatetype::expect_toplevel_expression_sequence),
|
||||
xseqtype_{x}
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -51,6 +54,24 @@ namespace xo {
|
|||
this->illegal_input_error(c_self_name, tk);
|
||||
}
|
||||
|
||||
void
|
||||
exprseq_xs::on_i64_token(const token_type & tk,
|
||||
parserstatemachine * p_psm)
|
||||
{
|
||||
constexpr bool c_debug_flag = true;
|
||||
scope log(XO_DEBUG(c_debug_flag));
|
||||
|
||||
constexpr const char * c_self_name = "exprseq_xs::on_i64_token";
|
||||
|
||||
if (xseqtype_ == exprseqtype::toplevel_interactive)
|
||||
{
|
||||
expect_expr_xs::start(p_psm);
|
||||
p_psm->top_exprstate().on_i64_token(tk, p_psm);
|
||||
} else {
|
||||
this->illegal_input_error(c_self_name, tk);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
exprseq_xs::on_typedescr(TypeDescr /*td*/,
|
||||
parserstatemachine * /*p_psm*/)
|
||||
|
|
@ -73,6 +94,21 @@ namespace xo {
|
|||
*p_emit_expr = expr.promote();
|
||||
} /*on_expr*/
|
||||
|
||||
void
|
||||
exprseq_xs::on_expr_with_semicolon(ref::brw<Expression> expr,
|
||||
parserstatemachine * p_psm)
|
||||
{
|
||||
/* toplevel expression sequence accepts an
|
||||
* arbitrary number of expressions.
|
||||
*
|
||||
* semicolons are sometimes mandatory to avoid ambiguity.
|
||||
*/
|
||||
|
||||
auto p_emit_expr = p_psm->p_emit_expr_;
|
||||
|
||||
*p_emit_expr = expr.promote();
|
||||
}
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
|
|
|
|||
|
|
@ -251,6 +251,18 @@ namespace xo {
|
|||
this->illegal_input_error(self_name, tk);
|
||||
}
|
||||
|
||||
void
|
||||
exprstate::on_i64_token(const token_type & tk,
|
||||
parserstatemachine * /*p_psm*/)
|
||||
{
|
||||
constexpr bool c_debug_flag = true;
|
||||
scope log(XO_DEBUG(c_debug_flag));
|
||||
|
||||
constexpr const char * self_name = "exprstate::on_i64";
|
||||
|
||||
this->illegal_input_error(self_name, tk);
|
||||
}
|
||||
|
||||
void
|
||||
exprstate::on_f64_token(const token_type & tk,
|
||||
parserstatemachine * /*p_psm*/)
|
||||
|
|
@ -284,7 +296,7 @@ namespace xo {
|
|||
return;
|
||||
|
||||
case tokentype::tk_i64:
|
||||
assert(false);
|
||||
this->on_i64_token(tk, p_psm);
|
||||
return;
|
||||
|
||||
case tokentype::tk_f64:
|
||||
|
|
|
|||
|
|
@ -170,6 +170,18 @@ namespace xo {
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
paren_xs::on_i64_token(const token_type & tk,
|
||||
parserstatemachine * /*p_psm*/)
|
||||
{
|
||||
constexpr bool c_debug_flag = true;
|
||||
scope log(XO_DEBUG(c_debug_flag));
|
||||
|
||||
constexpr const char * c_self_name = "paren_xs::on_i64";
|
||||
|
||||
this->illegal_input_error(c_self_name, tk);
|
||||
}
|
||||
|
||||
void
|
||||
paren_xs::on_f64_token(const token_type & tk,
|
||||
parserstatemachine * /*p_psm*/)
|
||||
|
|
|
|||
|
|
@ -29,6 +29,16 @@ namespace xo {
|
|||
return !xs_stack_.empty();
|
||||
}
|
||||
|
||||
void
|
||||
parser::begin_interactive_session() {
|
||||
/* note: not using emit expr here */
|
||||
parserstatemachine psm(&xs_stack_,
|
||||
&env_stack_,
|
||||
nullptr /*p_emit_expr*/);
|
||||
|
||||
exprseq_xs::start(exprseqtype::toplevel_interactive, &psm);
|
||||
}
|
||||
|
||||
void
|
||||
parser::begin_translation_unit() {
|
||||
/* note: not using emit expr here */
|
||||
|
|
@ -36,7 +46,7 @@ namespace xo {
|
|||
&env_stack_,
|
||||
nullptr /*p_emit_expr*/);
|
||||
|
||||
exprseq_xs::start(&psm);
|
||||
exprseq_xs::start(exprseqtype::toplevel_batch, &psm);
|
||||
}
|
||||
|
||||
rp<Expression>
|
||||
|
|
|
|||
|
|
@ -401,6 +401,22 @@ namespace xo {
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
progress_xs::on_i64_token(const token_type & tk,
|
||||
parserstatemachine * p_psm)
|
||||
{
|
||||
constexpr bool c_debug_flag = true;
|
||||
scope log(XO_DEBUG(c_debug_flag));
|
||||
|
||||
constexpr const char * self_name = "progress_xs::on_i64";
|
||||
|
||||
if (this->op_type_ == optype::invalid) {
|
||||
this->illegal_input_error(self_name, tk);
|
||||
} else {
|
||||
exprstate::on_i64_token(tk, p_psm);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
progress_xs::on_f64_token(const token_type & tk,
|
||||
parserstatemachine * p_psm)
|
||||
|
|
|
|||
|
|
@ -4,6 +4,16 @@
|
|||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
void
|
||||
reader::begin_interactive_session() {
|
||||
parser_.begin_interactive_session();
|
||||
}
|
||||
|
||||
reader_result
|
||||
reader::end_interactive_session() {
|
||||
return this->read_expr(span_type(nullptr, nullptr), true /*eof*/);
|
||||
}
|
||||
|
||||
void
|
||||
reader::begin_translation_unit() {
|
||||
parser_.begin_translation_unit();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue