mirror of
https://github.com/ChaiScript/ChaiScript.git
synced 2026-02-07 10:19:57 +08:00
Merge branch 'release-5.x' into develop
This commit is contained in:
commit
332a62769b
@ -1311,11 +1311,8 @@ namespace chaiscript
|
|||||||
try {
|
try {
|
||||||
retval = this->children[0]->eval(t_ss);
|
retval = this->children[0]->eval(t_ss);
|
||||||
}
|
}
|
||||||
catch (exception::eval_error &) {
|
catch (const exception::eval_error &e) {
|
||||||
if (this->children.back()->identifier == AST_Node_Type::Finally) {
|
retval = handle_exception(t_ss, Boxed_Value(std::ref(e)));
|
||||||
this->children.back()->children[0]->eval(t_ss);
|
|
||||||
}
|
|
||||||
throw;
|
|
||||||
}
|
}
|
||||||
catch (const std::runtime_error &e) {
|
catch (const std::runtime_error &e) {
|
||||||
retval = handle_exception(t_ss, Boxed_Value(std::ref(e)));
|
retval = handle_exception(t_ss, Boxed_Value(std::ref(e)));
|
||||||
|
|||||||
@ -1735,12 +1735,16 @@ namespace chaiscript
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Reads a class block from input
|
/// Reads a class block from input
|
||||||
bool Class() {
|
bool Class(const bool t_class_allowed) {
|
||||||
bool retval = false;
|
bool retval = false;
|
||||||
|
|
||||||
size_t prev_stack_top = m_match_stack.size();
|
size_t prev_stack_top = m_match_stack.size();
|
||||||
|
|
||||||
if (Keyword("class")) {
|
if (Keyword("class")) {
|
||||||
|
if (!t_class_allowed) {
|
||||||
|
throw exception::eval_error("Class definitions only allowed at top scope", File_Position(m_position.line, m_position.col), *m_filename);
|
||||||
|
}
|
||||||
|
|
||||||
retval = true;
|
retval = true;
|
||||||
|
|
||||||
if (!Id(true)) {
|
if (!Id(true)) {
|
||||||
@ -2421,7 +2425,7 @@ namespace chaiscript
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Top level parser, starts parsing of all known parses
|
/// Top level parser, starts parsing of all known parses
|
||||||
bool Statements() {
|
bool Statements(const bool t_class_allowed = false) {
|
||||||
bool retval = false;
|
bool retval = false;
|
||||||
|
|
||||||
bool has_more = true;
|
bool has_more = true;
|
||||||
@ -2429,7 +2433,7 @@ namespace chaiscript
|
|||||||
|
|
||||||
while (has_more) {
|
while (has_more) {
|
||||||
const auto start = m_position;
|
const auto start = m_position;
|
||||||
if (Def() || Try() || If() || While() || Class() || For() || Switch()) {
|
if (Def() || Try() || If() || While() || Class(t_class_allowed) || For() || Switch()) {
|
||||||
if (!saw_eol) {
|
if (!saw_eol) {
|
||||||
throw exception::eval_error("Two function definitions missing line separator", File_Position(start.line, start.col), *m_filename);
|
throw exception::eval_error("Two function definitions missing line separator", File_Position(start.line, start.col), *m_filename);
|
||||||
}
|
}
|
||||||
@ -2492,7 +2496,7 @@ namespace chaiscript
|
|||||||
/// \todo respect // -*- coding: utf-8 -*- on line 1 or 2 see: http://evanjones.ca/python-utf8.html)
|
/// \todo respect // -*- coding: utf-8 -*- on line 1 or 2 see: http://evanjones.ca/python-utf8.html)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Statements()) {
|
if (Statements(true)) {
|
||||||
if (m_position.has_more()) {
|
if (m_position.has_more()) {
|
||||||
throw exception::eval_error("Unparsed input", File_Position(m_position.line, m_position.col), t_fname);
|
throw exception::eval_error("Unparsed input", File_Position(m_position.line, m_position.col), t_fname);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
8
unittests/class_inside_scope.chai
Normal file
8
unittests/class_inside_scope.chai
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
|
||||||
|
|
||||||
|
try {
|
||||||
|
parse("{ class C { var data; def C() {} } }")
|
||||||
|
assert_false(true)
|
||||||
|
} catch (e) {
|
||||||
|
assert_true(true)
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user