Fixing 4.x grammar to be backward compatible.
Added 3.x unit tests back to show this.
This commit is contained in:
@@ -402,7 +402,7 @@ namespace chaiscript
|
||||
m->add(fun(&dispatch::Dynamic_Object::get_attrs), "get_attrs");
|
||||
m->add(fun(&dispatch::Dynamic_Object::get_attr), "get_attr");
|
||||
|
||||
m->eval("def Dynamic_Object::clone() { auto &new_o = Dynamic_Object(this.get_type_name()); for_each(this.get_attrs(), bind([](new_o, x) { new_o.get_attr(x.first) = x.second; }, new_o, _) ); return new_o; }");
|
||||
m->eval("def Dynamic_Object::clone() { auto &new_o = Dynamic_Object(this.get_type_name()); for_each(this.get_attrs(), bind(fun(new_o, x) { new_o.get_attr(x.first) = x.second; }, new_o, _) ); return new_o; }");
|
||||
|
||||
m->add(fun(&has_guard), "has_guard");
|
||||
m->add(fun(&get_guard), "get_guard");
|
||||
|
||||
@@ -321,6 +321,13 @@ namespace chaiscript
|
||||
throw exception::eval_error("Missing clone or copy constructor for right hand side of equation", e.parameters, t_ss);
|
||||
}
|
||||
}
|
||||
else if (this->children[1]->text == ":=") {
|
||||
if (lhs.is_undef() || Boxed_Value::type_match(lhs, retval)) {
|
||||
lhs.assign(retval);
|
||||
} else {
|
||||
throw exception::eval_error("Mismatched types in equation");
|
||||
}
|
||||
}
|
||||
else {
|
||||
try {
|
||||
retval = t_ss.call_function(this->children[1]->text, lhs, retval);
|
||||
|
||||
@@ -1119,11 +1119,7 @@ namespace chaiscript
|
||||
|
||||
size_t prev_stack_top = m_match_stack.size();
|
||||
|
||||
//if (Keyword("fun")) {
|
||||
if (Char('[')) {
|
||||
if (!Char(']')) {
|
||||
throw exception::eval_error("Closure list not currently supported", File_Position(m_line, m_col), *m_filename);
|
||||
}
|
||||
if (Keyword("fun")) {
|
||||
retval = true;
|
||||
|
||||
if (Char('(')) {
|
||||
@@ -1546,7 +1542,7 @@ namespace chaiscript
|
||||
|
||||
size_t prev_stack_top = m_match_stack.size();
|
||||
|
||||
if (Keyword("auto")) {
|
||||
if (Keyword("auto") || Keyword("var")) {
|
||||
retval = true;
|
||||
|
||||
if (!(Reference() || Id(true))) {
|
||||
@@ -1601,10 +1597,10 @@ namespace chaiscript
|
||||
|
||||
size_t prev_stack_top = m_match_stack.size();
|
||||
|
||||
if (Char('{')) {
|
||||
if (Char('[')) {
|
||||
retval = true;
|
||||
Container_Arg_List();
|
||||
if (!Char('}')) {
|
||||
if (!Char(']')) {
|
||||
throw exception::eval_error("Missing closing brace '}' in container initializer", File_Position(m_line, m_col), *m_filename);
|
||||
}
|
||||
if ((prev_stack_top != m_match_stack.size()) && (m_match_stack.back()->children.size() > 0)) {
|
||||
@@ -1893,7 +1889,7 @@ namespace chaiscript
|
||||
|
||||
if (Operator()) {
|
||||
retval = true;
|
||||
if (Symbol("=", true, true) || Symbol("+=", true, true) ||
|
||||
if (Symbol("=", true, true) || Symbol(":=", true, true) || Symbol("+=", true, true) ||
|
||||
Symbol("-=", true, true) || Symbol("*=", true, true) || Symbol("/=", true, true) ||
|
||||
Symbol("%=", true, true) || Symbol("<<=", true, true) || Symbol(">>=", true, true) ||
|
||||
Symbol("&=", true, true) || Symbol("^=", true, true) || Symbol("|=", true, true)) {
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#ifndef CHAISCRIPT_PRELUDE_HPP_
|
||||
#define CHAISCRIPT_PRELUDE_HPP_
|
||||
|
||||
//Note, the expression "{x,y}" in "collate" is parsed as two separate expressions
|
||||
//Note, the expression "[x,y]" in "collate" is parsed as two separate expressions
|
||||
//by C++, so CODE_STRING, takes two expressions and adds in the missing comma
|
||||
#define CODE_STRING(x, y) #x ", " #y
|
||||
|
||||
@@ -23,7 +23,7 @@ def to_string(x) : call_exists(first, x) && call_exists(second, x) { \n\
|
||||
}\n\
|
||||
# to_string for containers\n\
|
||||
def to_string(x) : call_exists(range, x) && !x.is_type("string"){ \n\
|
||||
"{" + x.join(", ") + "}"; \n\
|
||||
"[" + x.join(", ") + "]"; \n\
|
||||
}\n\
|
||||
# Basic to_string function\n\
|
||||
def to_string(x) { \n\
|
||||
@@ -259,7 +259,7 @@ def generate_range(x, y) { \n\
|
||||
}\n\
|
||||
# Returns a new Vector with the first value to the second value as its elements\n\
|
||||
def collate(x, y) { \n\
|
||||
return {x, y}; \n\
|
||||
return [x, y]; \n\
|
||||
} \n\
|
||||
def zip_with(f, x, y, inserter) : call_exists(range, x) && call_exists(range, y) { \n\
|
||||
auto r_x = range(x); \n\
|
||||
@@ -305,10 +305,10 @@ def string::find_last_not_of(list) : is_type(list, "string") { \n\
|
||||
int(find_last_not_of(this, list, -1)); \n\
|
||||
} \n\
|
||||
def string::ltrim() { \n\
|
||||
drop_while(this, [](x) { x == ' ' || x == '\t' || x == '\r' || x == '\n'}); \n\
|
||||
drop_while(this, fun(x) { x == ' ' || x == '\t' || x == '\r' || x == '\n'}); \n\
|
||||
} \n\
|
||||
def string::rtrim() { \n\
|
||||
reverse(drop_while(reverse(this), [](x) { x == ' ' || x == '\t' || x == '\r' || x == '\n'})); \n\
|
||||
reverse(drop_while(reverse(this), fun(x) { x == ' ' || x == '\t' || x == '\r' || x == '\n'})); \n\
|
||||
} \n\
|
||||
def string::trim() { \n\
|
||||
ltrim(rtrim(this)); \n\
|
||||
|
||||
Reference in New Issue
Block a user