mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 13:06:59 -04:00
Added some more classes for ScriptErrors;
Added split_text function, which is the 'opposite' of break_text; Script code "f\n(stuff)" now parses as "f;stuff" instead of a function call, "f(stuff)"; Fixed bug in cursor movement, which caused the closing > of a tag at end of input to be overwritten. git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@1175 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -110,14 +110,14 @@ SCRIPT_FUNCTION(to_int) {
|
||||
} else if (str.empty()) {
|
||||
result = 0;
|
||||
} else {
|
||||
return delayError(_ERROR_3_("can't convert value", str, input->typeName(), _TYPE_("integer")));
|
||||
return delay_error(ScriptErrorConversion(str, input->typeName(), _TYPE_("integer")));
|
||||
}
|
||||
} else {
|
||||
result = (int)*input;
|
||||
}
|
||||
SCRIPT_RETURN(result);
|
||||
} catch (const ScriptError& e) {
|
||||
return new_intrusive1<ScriptDelayedError>(e);
|
||||
return delay_error(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,14 +136,14 @@ SCRIPT_FUNCTION(to_real) {
|
||||
if (str.empty()) {
|
||||
result = 0.0;
|
||||
} else if (!str.ToDouble(&result)) {
|
||||
return delayError(_ERROR_3_("can't convert value", str, input->typeName(), _TYPE_("double")));
|
||||
return delay_error(ScriptErrorConversion(str, input->typeName(), _TYPE_("double")));
|
||||
}
|
||||
} else {
|
||||
result = (double)*input;
|
||||
}
|
||||
SCRIPT_RETURN(result);
|
||||
} catch (const ScriptError& e) {
|
||||
return new_intrusive1<ScriptDelayedError>(e);
|
||||
return delay_error(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,11 +170,11 @@ SCRIPT_FUNCTION(to_number) {
|
||||
} else if (str.empty()) {
|
||||
SCRIPT_RETURN(0);
|
||||
} else {
|
||||
return delayError(_ERROR_3_("can't convert value", str, input->typeName(), _TYPE_("double")));
|
||||
return delay_error(ScriptErrorConversion(str, input->typeName(), _TYPE_("double")));
|
||||
}
|
||||
}
|
||||
} catch (const ScriptError& e) {
|
||||
return new_intrusive1<ScriptDelayedError>(e);
|
||||
return delay_error(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -190,7 +190,7 @@ SCRIPT_FUNCTION(to_boolean) {
|
||||
}
|
||||
SCRIPT_RETURN(result);
|
||||
} catch (const ScriptError& e) {
|
||||
return new_intrusive1<ScriptDelayedError>(e);
|
||||
return delay_error(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -199,7 +199,7 @@ SCRIPT_FUNCTION(to_color) {
|
||||
SCRIPT_PARAM_C(AColor, input);
|
||||
SCRIPT_RETURN(input);
|
||||
} catch (const ScriptError& e) {
|
||||
return new_intrusive1<ScriptDelayedError>(e);
|
||||
return delay_error(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -124,7 +124,7 @@ SCRIPT_FUNCTION(symbol_variation) {
|
||||
if (value) {
|
||||
filename = value->filename;
|
||||
} else if (valueO) {
|
||||
throw ScriptError(_ERROR_2_("can't convert", valueO->typeName(), _TYPE_("symbol" )));
|
||||
throw ScriptErrorConversion(valueO->typeName(), _TYPE_("symbol" ));
|
||||
} else {
|
||||
filename = from_script<String>(symbol);
|
||||
}
|
||||
|
||||
@@ -192,6 +192,38 @@ SCRIPT_FUNCTION_SIMPLIFY_CLOSURE(break_text) {
|
||||
return ScriptValueP();
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : Rules : regex split
|
||||
|
||||
SCRIPT_FUNCTION_WITH_SIMPLIFY(split_text) {
|
||||
SCRIPT_PARAM_C(String, input);
|
||||
SCRIPT_PARAM_C(ScriptRegexP, match);
|
||||
SCRIPT_PARAM_DEFAULT_N(bool, _("include empty"), include_empty, true);
|
||||
ScriptCustomCollectionP ret(new ScriptCustomCollection);
|
||||
// find all matches
|
||||
while (match->regex.Matches(input)) {
|
||||
// match, append to result
|
||||
size_t start, len;
|
||||
bool ok = match->regex.GetMatch(&start, &len, 0);
|
||||
assert(ok);
|
||||
if (include_empty || start > 0) {
|
||||
ret->value.push_back(to_script(input.substr(0,start)));
|
||||
}
|
||||
input = input.substr(start + len); // everything after the match
|
||||
}
|
||||
if (include_empty || !input.empty()) {
|
||||
ret->value.push_back(to_script(input));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
SCRIPT_FUNCTION_SIMPLIFY_CLOSURE(split_text) {
|
||||
FOR_EACH(b, closure.bindings) {
|
||||
if (b.first == SCRIPT_VAR_match) {
|
||||
b.second = regex_from_script(b.second); // pre-compile
|
||||
}
|
||||
}
|
||||
return ScriptValueP();
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : Rules : regex match
|
||||
|
||||
SCRIPT_FUNCTION_WITH_SIMPLIFY(match) {
|
||||
@@ -214,6 +246,7 @@ void init_script_regex_functions(Context& ctx) {
|
||||
ctx.setVariable(_("replace"), script_replace);
|
||||
ctx.setVariable(_("filter text"), script_filter_text);
|
||||
ctx.setVariable(_("break text"), script_break_text);
|
||||
ctx.setVariable(_("split text"), script_split_text);
|
||||
ctx.setVariable(_("match"), script_match);
|
||||
ctx.setVariable(_("replace rule"), new_intrusive1<ScriptRule>(script_replace));
|
||||
ctx.setVariable(_("filter rule"), new_intrusive1<ScriptRule>(script_filter_text));
|
||||
|
||||
Reference in New Issue
Block a user