mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-13 14:07:01 -04:00
non-optional keyword parameters
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@236 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -941,7 +941,11 @@ keyword parameter type:
|
|||||||
match: [^(.,\n]+
|
match: [^(.,\n]+
|
||||||
keyword parameter type:
|
keyword parameter type:
|
||||||
name: prefix
|
name: prefix
|
||||||
|
description: Prefix for things like "<something>walk"
|
||||||
|
placeholder: land
|
||||||
|
optional: false
|
||||||
match: [A-Z][a-z]*
|
match: [A-Z][a-z]*
|
||||||
|
example: Forest
|
||||||
|
|
||||||
############################# All Magic keywords
|
############################# All Magic keywords
|
||||||
# By JrEye and Neko_Asakami
|
# By JrEye and Neko_Asakami
|
||||||
|
|||||||
+12
-4
@@ -18,11 +18,18 @@ DECLARE_TYPEOF_COLLECTION(const Keyword*);
|
|||||||
|
|
||||||
// ----------------------------------------------------------------------------- : Reflection
|
// ----------------------------------------------------------------------------- : Reflection
|
||||||
|
|
||||||
|
KeywordParam::KeywordParam()
|
||||||
|
: optional(true)
|
||||||
|
{}
|
||||||
|
|
||||||
IMPLEMENT_REFLECTION(KeywordParam) {
|
IMPLEMENT_REFLECTION(KeywordParam) {
|
||||||
REFLECT(name);
|
REFLECT(name);
|
||||||
REFLECT(description);
|
REFLECT(description);
|
||||||
|
REFLECT(placeholder);
|
||||||
|
REFLECT(optional);
|
||||||
REFLECT(match);
|
REFLECT(match);
|
||||||
REFLECT(script);
|
REFLECT(script);
|
||||||
|
REFLECT(example);
|
||||||
}
|
}
|
||||||
IMPLEMENT_REFLECTION(KeywordMode) {
|
IMPLEMENT_REFLECTION(KeywordMode) {
|
||||||
REFLECT(name);
|
REFLECT(name);
|
||||||
@@ -129,7 +136,7 @@ void Keyword::prepare(const vector<KeywordParamP>& param_types, bool force) {
|
|||||||
}
|
}
|
||||||
parameters.push_back(p);
|
parameters.push_back(p);
|
||||||
// modify regex
|
// modify regex
|
||||||
regex += _(")(") + make_non_capturing(p->match) + _(")?(");
|
regex += _(")(") + make_non_capturing(p->match) + _(")") + (p->optional ? _("?") : _("")) + _("(");
|
||||||
i = skip_tag(match, end);
|
i = skip_tag(match, end);
|
||||||
} else {
|
} else {
|
||||||
regex += regex_escape(c);
|
regex += regex_escape(c);
|
||||||
@@ -365,17 +372,18 @@ String KeywordDatabase::expand(const String& text,
|
|||||||
String part = s.substr(start, part_end - start);
|
String part = s.substr(start, part_end - start);
|
||||||
if ((j % 2) == 0) {
|
if ((j % 2) == 0) {
|
||||||
// parameter
|
// parameter
|
||||||
|
KeywordParam& kwp = *kw->parameters[j/2-1];
|
||||||
String param = untagged.substr(start_u, len_u); // untagged version
|
String param = untagged.substr(start_u, len_u); // untagged version
|
||||||
if (param.empty()) {
|
if (param.empty()) {
|
||||||
// placeholder
|
// placeholder
|
||||||
param = _("<atom-kwpph>‹") + kw->parameters[j/2-1]->name + _("›</atom-kwpph>");
|
param = _("<atom-kwpph>‹") + (kwp.placeholder.empty() ? kwp.name : kwp.placeholder) + _("›</atom-kwpph>");
|
||||||
part = part + param; // keep tags
|
part = part + param; // keep tags
|
||||||
} else if (kw->parameters[j/2-1]->script) {
|
} else if (kw->parameters[j/2-1]->script) {
|
||||||
// apply parameter script
|
// apply parameter script
|
||||||
ctx.setVariable(_("input"), to_script(part));
|
ctx.setVariable(_("input"), to_script(part));
|
||||||
part = kw->parameters[j/2-1]->script.invoke(ctx)->toString();
|
part = kwp.script.invoke(ctx)->toString();
|
||||||
ctx.setVariable(_("input"), to_script(part));
|
ctx.setVariable(_("input"), to_script(part));
|
||||||
param = kw->parameters[j/2-1]->script.invoke(ctx)->toString();
|
param = kwp.script.invoke(ctx)->toString();
|
||||||
}
|
}
|
||||||
ctx.setVariable(String(_("param")) << (int)(j/2), to_script(param));
|
ctx.setVariable(String(_("param")) << (int)(j/2), to_script(param));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,8 +23,11 @@ class KeywordTrie;
|
|||||||
/// Parameter type of keywords
|
/// Parameter type of keywords
|
||||||
class KeywordParam {
|
class KeywordParam {
|
||||||
public:
|
public:
|
||||||
|
KeywordParam();
|
||||||
String name; ///< Name of the parameter type
|
String name; ///< Name of the parameter type
|
||||||
String description; ///< Description of the type
|
String description; ///< Description of the parameter type
|
||||||
|
String placeholder; ///< Placholder for <atom-kwpph>, name is used if this is empty
|
||||||
|
bool optional; ///< Can this parameter be left out (a placeholder is then used)
|
||||||
String match; ///< Regular expression to match
|
String match; ///< Regular expression to match
|
||||||
OptionalScript script; ///< Transformation of the value for showing in the reminder text
|
OptionalScript script; ///< Transformation of the value for showing in the reminder text
|
||||||
String example; ///< Example for preview dialog
|
String example; ///< Example for preview dialog
|
||||||
|
|||||||
Reference in New Issue
Block a user