Author: reebalazs
Date: Sat Feb 17 16:07:14 2007
New Revision: 39114
Modified:
kukit/kukit.js/trunk/kukit/kssparser.js
kukit/kukit.js/trunk/kukit/providerreg.js
kukit/kukit.js/trunk/kukit/resourcedata.js
kukit/kukit.js/trunk/kukit/selectorreg.js
Log:
Prepare and refactor for kssXxxx (action) parameters.
Modified: kukit/kukit.js/trunk/kukit/kssparser.js
==============================================================================
--- kukit/kukit.js/trunk/kukit/kssparser.js (original)
+++ kukit/kukit.js/trunk/kukit/kssparser.js Sat Feb 17 16:07:14 2007
@@ -327,10 +327,18 @@
}
}
this.result = [];
- // Check the syntax of the value, enables early error detection.
+ }
+ //
if (typeof this.value != 'undefined') {
+ // Check the syntax of the value, enables early error detection.
+ // use a different registry, if it's a kssXxx parameter
+ var registry = kukit.pprovidersGlobalRegistry;
+ // XXX This is lame. We should not do it this way.
+ // TODO change this, it should be decided from the name of the key.
+ if (! registry.exists(this.value.methodname)) {
+ registry = kukit.selectorTypesGlobalRegistry;
try {
- this.value.check();
+ this.value.check(kukit.pprovidersGlobalRegistry);
} catch(e) {
throw new kukit.err.tk.ParsingError('Error in value: ' + e,
this.src.makeMarker(this.startpos));
}
Modified: kukit/kukit.js/trunk/kukit/providerreg.js
==============================================================================
--- kukit/kukit.js/trunk/kukit/providerreg.js (original)
+++ kukit/kukit.js/trunk/kukit/providerreg.js Sat Feb 17 16:07:14 2007
@@ -50,7 +50,12 @@
var func = this.content[name];
if (! func) {
// not found
- throw 'Error : undefined parameter provider "' + name + '"';
+ if (name == '') {
+ // default provider for the strings
+ return kukit.pr.IdentityPP;
+ } else {
+ throw 'Error : undefined parameter provider "' + name + '"';
+ }
}
return func;
};
@@ -73,8 +78,27 @@
* provider. The default parameters are used if an action is called
* programmatically but in this case the parameters to be propagated
* must be explicitely declared using the provider "pass()".
+*
+* The special key '' is held for the parameter provider that just returns
+* the string itself. This is by default defined as the identity function, but
+* can be overwritten to do something with the string value. The usage is that
+* this provider expects a single parameter, the string.
*/
+kukit.pr.IdentityPP = function() {};
+kukit.pr.IdentityPP.prototype = {
+ check: function(args) {
+ // check does not need to be used here actually.
+ if (args.length != 1) {
+ throw 'internal error, IdentityPP needs 1 argument';
+ }
+ },
+ eval: function(args, node) {
+ return args[0];
+ }
+};
+kukit.pprovidersGlobalRegistry.register('', kukit.pr.IdentityPP);
+
kukit.pr.FormVarPP = function() {};
kukit.pr.FormVarPP.prototype = {
check: function(args) {
Modified: kukit/kukit.js/trunk/kukit/resourcedata.js
==============================================================================
--- kukit/kukit.js/trunk/kukit/resourcedata.js (original)
+++ kukit/kukit.js/trunk/kukit/resourcedata.js Sat Feb 17 16:07:14 2007
@@ -96,10 +96,15 @@
this.txt = txt;
};
kukit.rd.KssTextValue.prototype.isMethod = false;
-kukit.rd.KssTextValue.prototype.check = function() {
-};
-kukit.rd.KssTextValue.prototype.evaluate = function(parms, key) {
- parms[key] = this.txt;
+kukit.rd.KssTextValue.prototype.check = function(registry) {
+ // use the IdentityPP provider.
+ this.pprovider = new (registry.get(''))();
+};
+kukit.rd.KssTextValue.prototype.evaluate = function(parms, key, node,
defaultparms) {
+ // For normal string parameters, this would return the string itself.
+ // In other execution contexts (like kssSelector, for example) this can
+ // do something else.
+ parms[key] = this.pprovider.eval([this.txt], node, defaultparms);
};
/*
@@ -112,9 +117,9 @@
this.args = args;
};
kukit.rd.KssMethodValue.prototype.isMethod = true;
-kukit.rd.KssMethodValue.prototype.check = function() {
+kukit.rd.KssMethodValue.prototype.check = function(registry) {
// Check syntax
- this.pprovider = new
(kukit.pprovidersGlobalRegistry.get(this.methodname))();
+ this.pprovider = new (registry.get(this.methodname))();
this.pprovider.check(this.args);
};
@@ -441,27 +446,38 @@
}
};
-kukit.rd.Action.prototype.getParms = function(node, defaultparms) {
- // Return the completed action parameters, based on the node
+kukit.rd.Action.prototype.makeActionOper = function(oper, defaultparms) {
+ // Fill the completed action parameters, based on the node
// if defaultparms is given, its values can be used with the
// pass() function.
+ // The kssXxx parameters, reserved for the action, are put into
+ // aparms.
+ // A cloned oper is returned.
var parms = {};
+ var aparms = {};
if (typeof(defaultparms) == 'undefined') {
defaultparms = {};
}
for (var key in this.parms) {
var kssvalue = this.parms[key];
- // evaluate the method parameters into parms
- kssvalue.evaluate(parms, key, node, defaultparms);
+ if (key.match(/^kss/)) {
+ // kssXxx parameters are separated to aparms.
+ kssvalue.evaluate(aparms, key, oper.node, defaultparms);
+ } else {
+ // evaluate the method parameters into parms
+ kssvalue.evaluate(parms, key, oper.node, defaultparms);
+ }
}
- return parms;
+ var aoper = oper.clone({
+ 'parms': parms,
+ 'aparms': aparms,
+ 'action': this
+ });
+ return aoper;
};
kukit.rd.Action.prototype.execute = function(oper) {
- oper = oper.clone({
- 'parms': this.getParms(oper.node, oper.parms),
- 'action': this
- });
+ oper = this.makeActionOper(oper, oper.parms);
switch (this.type) {
case 'D': {
// Default action.
Modified: kukit/kukit.js/trunk/kukit/selectorreg.js
==============================================================================
--- kukit/kukit.js/trunk/kukit/selectorreg.js (original)
+++ kukit/kukit.js/trunk/kukit/selectorreg.js Sat Feb 17 16:07:14 2007
@@ -22,6 +22,48 @@
kukit.sr = {};
+// Registry of the pprovider functions for selecting
+
+kukit.sr.pproviderSelRegistry = new kukit.pr.ParamProviderRegistry();
+
+// This will provide the default case (string)
+kukit.sr.DefaultPP = function() {};
+kukit.sr.DefaultPP.prototype = {
+ check: function(args) {
+ // check does not need to be used here actually.
+ if (args.length != 1) {
+ throw 'internal error, DefaultPP needs 1 argument';
+ }
+ },
+ eval: function(args, node) {
+ return args[0];
+ }
+};
+kukit.sr.pproviderSelRegistry.register('', kukit.sr.DefaultPP);
+
+
+// this will provide an arbitrary selector, and is designed to
+// be used with the makeAnyPP factory function.
+kukit.sr.AnyPP = function() {};
+kukit.sr.AnyPP.prototype = {
+ check: kukit.sr.DefaultPP.prototype.check,
+ eval: function(args, node) {
+ var f = kukit.selectorTypesGlobalRegistry.get(this.selector_type);
+ return f(args[0], node);
+ }
+};
+
+
+kukit.sr.makeAnyPP = function(selector_type) {
+ var pp = function () {};
+ pp.prototype = kukit.sr.AnyPP.prototype;
+ pp.prototype.selector_type = selector_type;
+ return pp;
+};
+
+
+
+
/*
* class SelectorTypeRegistry
*
@@ -48,6 +90,11 @@
return;
}
this.mapping[name] = func;
+ // Also register the selector param provider (not for samenode though)
+ if (name != 'sanenode') {
+ var pp = kukit.sr.makeAnyPP(name);
+ kukit.sr.pproviderSelRegistry.register(name, pp);
+ }
};
kukit.sr.SelectorTypeRegistry.prototype.get = function(name) {
@@ -85,3 +132,5 @@
return nodes;
});
+
+
_______________________________________________
Kukit-checkins mailing list
[email protected]
http://codespeak.net/mailman/listinfo/kukit-checkins