Fixed prefix operator precedence bug. Added collate(?), zip_with, and zip
This commit is contained in:
@@ -1044,7 +1044,7 @@ namespace chaiscript
|
|||||||
if (Symbol("-")) {
|
if (Symbol("-")) {
|
||||||
retval = true;
|
retval = true;
|
||||||
|
|
||||||
if (!Additive()) {
|
if (!Dot_Access()) {
|
||||||
throw Parse_Error("Incomplete negation expression", File_Position(line, col), filename);
|
throw Parse_Error("Incomplete negation expression", File_Position(line, col), filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1053,7 +1053,7 @@ namespace chaiscript
|
|||||||
else if (Symbol("!")) {
|
else if (Symbol("!")) {
|
||||||
retval = true;
|
retval = true;
|
||||||
|
|
||||||
if (!Expression()) {
|
if (!Dot_Access()) {
|
||||||
throw Parse_Error("Incomplete '!' expression", File_Position(line, col), filename);
|
throw Parse_Error("Incomplete '!' expression", File_Position(line, col), filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1062,7 +1062,7 @@ namespace chaiscript
|
|||||||
if (Symbol("++", true)) {
|
if (Symbol("++", true)) {
|
||||||
retval = true;
|
retval = true;
|
||||||
|
|
||||||
if (!Expression()) {
|
if (!Dot_Access()) {
|
||||||
throw Parse_Error("Incomplete '++' expression", File_Position(line, col), filename);
|
throw Parse_Error("Incomplete '++' expression", File_Position(line, col), filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1071,7 +1071,7 @@ namespace chaiscript
|
|||||||
else if (Symbol("--", true)) {
|
else if (Symbol("--", true)) {
|
||||||
retval = true;
|
retval = true;
|
||||||
|
|
||||||
if (!Expression()) {
|
if (!Dot_Access()) {
|
||||||
throw Parse_Error("Incomplete '--' expression", File_Position(line, col), filename);
|
throw Parse_Error("Incomplete '--' expression", File_Position(line, col), filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -6,58 +6,75 @@
|
|||||||
|
|
||||||
const char *chaiscript_prelude = " \
|
const char *chaiscript_prelude = " \
|
||||||
def to_string(x) : call_exists(first, x) && call_exists(second, x) { \n\
|
def to_string(x) : call_exists(first, x) && call_exists(second, x) { \n\
|
||||||
\"<\" + x.first.to_string() + \", \" + x.second.to_string() + \">\"\n\
|
\"<\" + x.first.to_string() + \", \" + x.second.to_string() + \">\"\n\
|
||||||
}\n\
|
}\n\
|
||||||
def to_string(x) : call_exists(range, x) { \n\
|
def to_string(x) : call_exists(range, x) { \n\
|
||||||
\"[\" + x.join(\", \") + \"]\"\n\
|
\"[\" + x.join(\", \") + \"]\"\n\
|
||||||
}\n\
|
}\n\
|
||||||
def to_string(x) { \n\
|
def to_string(x) { \n\
|
||||||
return internal_to_string(x)\n\
|
return internal_to_string(x)\n\
|
||||||
}\n\
|
}\n\
|
||||||
def puts(x) { \n\
|
def puts(x) { \n\
|
||||||
print_string(x.to_string()) \n\
|
print_string(x.to_string()) \n\
|
||||||
}; \n\
|
}; \n\
|
||||||
def print(x) { \n\
|
def print(x) { \n\
|
||||||
println_string(x.to_string()) \n\
|
println_string(x.to_string()) \n\
|
||||||
}; \n\
|
}; \n\
|
||||||
def for_each(container, func) { \n\
|
def for_each(container, func) { \n\
|
||||||
var range = range(container); \n\
|
var range = range(container); \n\
|
||||||
while (!range.empty()) { \n\
|
while (!range.empty()) { \n\
|
||||||
func(range.front()) \n\
|
func(range.front()) \n\
|
||||||
range.pop_front() \n\
|
range.pop_front() \n\
|
||||||
} \n\
|
} \n\
|
||||||
} \n\
|
} \n\
|
||||||
def map(container, func) { \n\
|
def map(container, func) { \n\
|
||||||
var retval = Vector() \n\
|
var retval = Vector() \n\
|
||||||
var range = range(container) \n\
|
var range = range(container) \n\
|
||||||
while (!range.empty()) { \n\
|
while (!range.empty()) { \n\
|
||||||
retval.push_back(func(range.front())) \n\
|
retval.push_back(func(range.front())) \n\
|
||||||
range.pop_front() \n\
|
range.pop_front() \n\
|
||||||
} \n\
|
} \n\
|
||||||
retval \n\
|
retval \n\
|
||||||
} \n\
|
} \n\
|
||||||
def reduce(container, func, initial) { \n\
|
def reduce(container, func, initial) { \n\
|
||||||
var retval = initial \n\
|
var retval = initial \n\
|
||||||
var range = range(container) \n\
|
var range = range(container) \n\
|
||||||
while (!range.empty()) { \n\
|
while (!range.empty()) { \n\
|
||||||
retval = (func(range.front(), retval)) \n\
|
retval = (func(range.front(), retval)) \n\
|
||||||
range.pop_front() \n\
|
range.pop_front() \n\
|
||||||
} \n\
|
} \n\
|
||||||
retval \n\
|
retval \n\
|
||||||
} \n\
|
} \n\
|
||||||
def join(container, delim) { \n\
|
def join(container, delim) { \n\
|
||||||
var retval = \"\" \n\
|
var retval = \"\" \n\
|
||||||
var range = range(container) \n\
|
var range = range(container) \n\
|
||||||
if (!range.empty()) { \n\
|
if (!range.empty()) { \n\
|
||||||
retval += to_string(range.front()) \n\
|
retval += to_string(range.front()) \n\
|
||||||
range.pop_front() \n\
|
range.pop_front() \n\
|
||||||
while (!range.empty()) { \n\
|
while (!range.empty()) { \n\
|
||||||
retval += delim \n\
|
retval += delim \n\
|
||||||
retval += to_string(range.front()) \n\
|
retval += to_string(range.front()) \n\
|
||||||
range.pop_front() \n\
|
range.pop_front() \n\
|
||||||
} \n\
|
} \n\
|
||||||
} \n\
|
} \n\
|
||||||
retval \n\
|
retval \n\
|
||||||
}";
|
} \n\
|
||||||
|
def collate(x, y) { \n\
|
||||||
|
[x, y] \n\
|
||||||
|
} \n\
|
||||||
|
def zip_with(f, x, y) : call_exists(range, x) && call_exists(range, y) { \n\
|
||||||
|
var r_x = range(x); \n\
|
||||||
|
var r_y = range(y); \n\
|
||||||
|
var retval = Vector(); \n\
|
||||||
|
while (!r_x.empty() && !r_y.empty()) { \n\
|
||||||
|
retval.push_back(f(r_x.front(), r_y.front())); \n\
|
||||||
|
r_x.pop_front(); \n\
|
||||||
|
r_y.pop_front(); \n\
|
||||||
|
} \n\
|
||||||
|
retval \n\
|
||||||
|
} \n\
|
||||||
|
def zip(x, y) { \n\
|
||||||
|
zip_with(collate, x, y) \n\
|
||||||
|
}\n";
|
||||||
|
|
||||||
#endif /* CHAISCRIPT_PRELUDE_HPP_ */
|
#endif /* CHAISCRIPT_PRELUDE_HPP_ */
|
||||||
|
Reference in New Issue
Block a user