[KSS-checkins] r37662 - in kukit/kukit.js/trunk: kukit tests
reebalazs at codespeak.net
reebalazs at codespeak.net
Wed Jan 31 12:44:50 CET 2007
Author: reebalazs
Date: Wed Jan 31 12:44:46 2007
New Revision: 37662
Modified:
kukit/kukit.js/trunk/kukit/kssparser.js
kukit/kukit.js/trunk/tests/test_kssparser.js
Log:
Fix evt and action parameters in a way that namespace-name is needed uniformly everywhere. (This means also a little syntactic change in the kss rules.)
Modified: kukit/kukit.js/trunk/kukit/kssparser.js
==============================================================================
--- kukit/kukit.js/trunk/kukit/kssparser.js (original)
+++ kukit/kukit.js/trunk/kukit/kssparser.js Wed Jan 31 12:44:46 2007
@@ -69,10 +69,15 @@
// Parse the part in an embedded parser
var src = new kukit.tk.Cursor(key + ' ');
var parser = new kukit.kssp.KssSelector(src, null, true);
- // check the evt_name equals the actual event name
- if (block.evt_name != null && block.evt_name != parser.kssSelector.name) {
- // XXX this should be done in another way, so that we can see where the error happened.
- block.emitError('In evt-xxx-yyy xxx must correspond to the event name, "' + block.evt_name + '" != "' + parser.kssSelector.name + '"');
+ // check the event name and namespace use in evt- parameters
+ // equals the event name and namespace set in the kss selector.
+ if (block.evt_name != null) {
+ // We have evt- parms in the rule.
+ if (block.evt_name != parser.kssSelector.name || block.evt_namespace != parser.kssSelector.namespace) {
+ // XXX this should be done in another way, so that we can see where the error happened.
+ block.emitError('kss param key evt-[<namespace>-]<name>-yyy must not have different [namespace and] name then the kss selector at the top of the rule, "'
+ + key + '", and inside we have "' + block.evt_namespace + '-' + block.evt_name + '"');
+ }
}
// Create the event rule. (one action only)
var eventRule = new kukit.rd.EventRule(parser.kssSelector, block.evt_parms, block.actions);
@@ -104,6 +109,7 @@
//this.parms = {};
this.evt_parms = {};
this.evt_name = null; // we don't know at this point
+ this.evt_namespace = null; // we don't know at this point
this.actions = new kukit.rd.ActionSet();
var cursor = {'next': 1};
while (cursor.next < this.result.length-1) {
@@ -127,87 +133,146 @@
// the keys look like this:
//
// evt-<EVTNAME>-<KEY>: <VALUE>
+ // evt-<NAMESPACE>-<EVTNAME>-<KEY>: <VALUE>
//
// action-server: <ACTIONNAME>
// action-client: <ACTIONNAME>
+ // action-client: <NAMESPACE>-<ACTIONNAME>
// action-cancel: <ACTIONNAME>
+ // action-cancel: <NAMESPACE>-<ACTIONNAME>
//
// <ACTIONNAME>-<KEY>: <VALUE>
+ // <NAMESPACE>-<ACTIONNAME>-<KEY>: <VALUE>
// <ACTIONNAME>-error: <VALUE>
+ // <NAMESPACE>-<ACTIONNAME>-error: <VALUE>
//
// default-<KEY>: <VALUE>
// default-error: <VALUE>
//
- var KSS_PARAM_SYNTAX_ERROR = 'kss param key must be like xxx-yyy or evt-xxx-yyy"';
var splitkey = key.split('-');
- if (splitkey.length < 2 || splitkey.length > 3) {
- this.emitError(KSS_PARAM_SYNTAX_ERROR + key + '"');
+ if (splitkey.length < 2 || splitkey.length > 4) {
+ this.emitError(
+ 'kss param key must be like xxx-yyy or nnn-xxx-yyy or evt-xxx-yyy or evt-nnn-xxx-yyy"'
+ + key + '"');
}
var name = splitkey[0];
- var qualifier = splitkey[1];
- if (splitkey.length == 3) {
- if (name != 'evt') {
- this.emitError('kss param key must be like xxx-yyy or evt-xxx-yyy"' + key + '"');
- }
- if (this.evt_name != null && qualifier != this.evt_name) {
- this.emitError('kss param key evt-<name>-yyy must not have different names "' + key + '", it must be "' + this.evt_name + '"');
- }
+ if (name == 'evt') {
+ // evt-<EVTNAME>-<KEY>: <VALUE>
+ // evt-<NAMESPACE>-<EVTNAME>-<KEY>: <VALUE>
+ if (splitkey.length < 3) {
+ this.emitError(
+ 'kss param key must be like xxx-yyy or nnn-xxx-yyy or evt-xxx-yyy or evt-nnn-xxx-yyy"'
+ + key + '"');
+ }
+ var enamespace;
+ var ename;
+ var ekey;
+ if (splitkey.length == 3) {
+ // evt-<EVTNAME>-<KEY>: <VALUE>
+ ename = splitkey[1];
+ ekey = splitkey[2];
+ } else {
+ // evt-<NAMESPACE>-<EVTNAME>-<KEY>: <VALUE>
+ enamespace = splitkey[1];
+ ename = splitkey[2];
+ ekey = splitkey[3];
+ }
+ if (this.evt_name == null) {
+ // This is the first evt- parameter, so we set it up
+ // so that we can check it stays the same within the block.
+ this.evt_name = ename;
+ this.evt_namespace = enamespace;
+ } else {
+ if (ename != this.evt_name || enamespace != this.evt_namespace) {
+ // Do not allow deviation from the previous event names.
+ this.emitError('kss param key evt-[<namespace>-]<name>-yyy must not have different [namespace and] name inside the same rule,"'
+ + key + '", it must be "' + this.evt_namespace + '-' + this.evt_name + '"');
+ }
+ }
+ if (value.isMethod != false) {
+ this.emitError('evt-[nnn-]xxx-yyy: parameter producers are not allowed as value, key "'
+ + key + '"');
+ }
+ // set it
+ this.evt_parms[ekey] = value.txt;
+ } else if (name == 'action') {
+ // action-server: <ACTIONNAME>
+ // action-client: <ACTIONNAME>
+ // action-client: <NAMESPACE>-<ACTIONNAME>
+ // action-cancel: <ACTIONNAME>
+ // action-cancel: <NAMESPACE>-<ACTIONNAME>
+ if (splitkey.length != 2) {
+ this.emitError(
+ 'action-xxx must not have more "-" in it, key "' +
+ key + '"');
+ }
if (value.isMethod != false) {
- /*XXX what does this error message mean ? */
- this.emitError('evt-xxx-yyy: cannot use method as parm value, key "' + key + '"');
+ this.emitError('action-xxx: parameter producers are not allowed as value, key "'
+ + key + '"');
+ }
+ var atab = {'server': 'S', 'client': 'C', 'cancel': 'X'}
+ var actionType = atab[splitkey[1]];
+ if (! actionType) {
+ this.emitError('action-xxx: key must be action-server or action-client or action-cancel, key "'
+ + key + '"');
+ }
+ // force value to be <ACTIONNAME> or <NAMESPACE>-<ACTIONNAME>
+ var splitvalue = value.txt.split('-');
+ if (splitvalue.length > 2) {
+ this.emitError('action-xxx: value must be <ACTIONNAME> or <NAMESPACE>-<ACTIONNAME>, key "'
+ + key + '"');
}
- this.evt_name = qualifier;
- var qualifier2 = splitkey[2];
// set it
- this.evt_parms[qualifier2] = value.txt;
+ var action = this.actions.getOrCreateAction(value.txt);
+ if (actionType != 'X' || action.type == null) {
+ action.setType(actionType);
+ } else {
+ this.actions.deleteAction(value.txt);
+ }
} else {
- // xxx-yyy, two tags only
- if (name == 'evt') {
- this.emitError('kss param key must be like xxx-yyy or evt-xxx-yyy"' + key + '"');
- } else if (name == 'action') {
- if (value.isMethod != false) {
- this.emitError('action-xxx: cannot use method as parm value, key "' + key + '"');
- }
- var actionType;
- switch (qualifier) {
- case 'server': {
- actionType = 'S';
- } break;
- case 'client': {
- actionType = 'C';
- } break;
- case 'cancel': {
- actionType = 'X';
- } break;
- default: {
- this.emitError('kss param key must be action-server or action-client or action-cancel "' + key + '"');
- } break;
- }
- var action = this.actions.getOrCreateAction(value.txt);
- if (actionType != 'X' || action.type == null) {
- action.setType(actionType);
- } else {
- this.actions.deleteAction(value.txt);
- }
+ // <ACTIONNAME>-<KEY>: <VALUE>
+ // <NAMESPACE>-<ACTIONNAME>-<KEY>: <VALUE>
+ // <ACTIONNAME>-error: <VALUE>
+ // <NAMESPACE>-<ACTIONNAME>-error: <VALUE>
+ // default-<KEY>: <VALUE>
+ // default-error: <VALUE>
+ var aname;
+ var akey;
+ if (splitkey.length == 2) {
+ // <ACTIONNAME>-<KEY>: <VALUE>
+ // <ACTIONNAME>-error: <VALUE>
+ // default-<KEY>: <VALUE>
+ // default-error: <VALUE>
+ aname = splitkey[0];
+ akey = splitkey[1];
} else {
- // name is the action name.
- var action = this.actions.getOrCreateAction(name);
- switch (qualifier) {
- case 'error': {
- if (value.isMethod != false) {
- this.emitError('xxx-error: cannot use method as parm value, key "' + key + '"');
- }
- action.setError(value.txt);
- // also create the action for the error itself.
- var err_action = this.actions.getOrCreateAction(value.txt);
- err_action.setType('E');
- } break;
- default: {
- // qualifier is the name of the key
- // these may be either txt or method parms, and they stored with the wrapper.
- action.parms[qualifier] = value;
- } break;
- }
+ // <NAMESPACE>-<ACTIONNAME>-<KEY>: <VALUE>
+ // <NAMESPACE>-<ACTIONNAME>-error: <VALUE>
+ aname = splitkey[0] + '-' + splitkey[1];
+ akey = splitkey[2];
+ }
+ // set it
+ var action = this.actions.getOrCreateAction(aname);
+ switch (akey) {
+ case 'error': {
+ // <ACTIONNAME>-error: <VALUE>
+ // default-error: <VALUE>
+ if (value.isMethod != false) {
+ this.emitError('xxx-error: parameter producers are not allowed as value, key "'
+ + key + '"');
+ }
+ action.setError(value.txt);
+ // also create the action for the error itself.
+ var err_action = this.actions.getOrCreateAction(value.txt);
+ err_action.setType('E');
+ } break;
+ default: {
+ // <ACTIONNAME>-<KEY>: <VALUE>
+ // default-<KEY>: <VALUE>
+ //
+ // value may be either txt or method parms, and they get stored with the wrapper.
+ action.parms[akey] = value;
+ } break;
}
}
};
Modified: kukit/kukit.js/trunk/tests/test_kssparser.js
==============================================================================
--- kukit/kukit.js/trunk/tests/test_kssparser.js (original)
+++ kukit/kukit.js/trunk/tests/test_kssparser.js Wed Jan 31 12:44:46 2007
@@ -634,16 +634,20 @@
+" getCurrentTime-effect: fade; \n"
+" action-client: log;\n"
+' log-message: "Logging";\n'
+ +"}\n"
+ +"document:annoyClicker-annoy(annoyMe) {\n"
+ +" evt-annoyClicker-annoy-preventdefault: true;\n"
+ +" action-client: namespaced-alert;\n"
+ +' namespaced-alert-message: "You are an idiot! Ha ha ha. (But just keep on trying...)";\n'
+"}\n";
-
var src = new kukit.tk.Cursor(txt);
// XXX TODO change comments
var parser = new kukit.kssp.Document(src, null, true);
this.assertEquals(parser.finished, true);
- this.assertEquals(parser.eventRules.length, 9);
+ this.assertEquals(parser.eventRules.length, 10);
var rule;
var action;
@@ -666,7 +670,7 @@
// rule 1
// div#update-area:timeout {
- // evt-delay: 2000;
+ // evt-timeout-delay: 2000;
// effect: fade;
// kss-action: getCurrentTime;
// }
@@ -824,6 +828,28 @@
'message': new kukit.rd.KssTextValue('Logging')
});
+ // rule 9
+ //document:annoyClicker-annoy(annoyMe) {\n"
+ // evt-annoyClicker-annoy-preventdefault: true;\n"
+ // action-client: namespaced-alert;\n"
+ // namespaced-alert-message: "You are an idiot! Ha ha ha. (But just keep on trying...)";\n'
+ //}
+ rule = parser.eventRules[9];
+ this.assertDictEquals(rule.parms, {'preventdefault': 'true'});
+ this.assertEquals(rule.kss_selector.css, 'document');
+ this.assertEquals(rule.kss_selector.isMethodSelector, true);
+ this.assertEquals(rule.kss_selector.name, 'annoy');
+ this.assertEquals(rule.kss_selector.namespace, 'annoyClicker');
+ this.assertEquals(rule.kss_selector.id, 'annoyMe');
+ action = rule.actions.content['namespaced-alert'];
+ this.assertEquals(action.type, 'C');
+ this.assertEquals(action.name, 'namespaced-alert');
+ this.assertEquals(action.error, null);
+ this.assertKssParmEquals(action.parms, {
+ 'message': new kukit.rd.KssTextValue( "You are an idiot! Ha ha ha. (But just keep on trying...)")
+ });
+
+
};
};
More information about the Kukit-checkins
mailing list