[KSS-checkins] r44814 - in kukit/kukit.js/branch/ree-binding-improvements: kukit tests

reebalazs at codespeak.net reebalazs at codespeak.net
Sat Jul 7 00:20:40 CEST 2007


Author: reebalazs
Date: Sat Jul  7 00:20:40 2007
New Revision: 44814

Modified:
   kukit/kukit.js/branch/ree-binding-improvements/kukit/kssparser.js
   kukit/kukit.js/branch/ree-binding-improvements/kukit/resourcedata.js
   kukit/kukit.js/branch/ree-binding-improvements/tests/test_kssparser.js
Log:
First parser modifications, to have the event id accept a pprovider

Modified: kukit/kukit.js/branch/ree-binding-improvements/kukit/kssparser.js
==============================================================================
--- kukit/kukit.js/branch/ree-binding-improvements/kukit/kssparser.js	(original)
+++ kukit/kukit.js/branch/ree-binding-improvements/kukit/kssparser.js	Sat Jul  7 00:20:40 2007
@@ -1,7 +1,7 @@
 /*
 * Copyright (c) 2005-2007
 * Authors: KSS Project Contributors (see docs/CREDITS.txt)
-*   Martin Heidegger <mastakaneda at gmail.com>
+*          Martin Heidegger <mastakaneda at gmail.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as published
@@ -313,6 +313,7 @@
     this.digestTxt(cursor, kukit.tk.Fraction, kukit.kssp.Comment);
     this.txt = '';
     var txt = cursor.txt;
+    
     if (this.ifToken(cursor, kukit.kssp.String)) {
         // The previous txt must be all whitespace.
         if (txt) {
@@ -382,7 +383,7 @@
 /*
 * class PropValueInPseudo
 *
-* PropValue in pseudo must ba single word with no spaces around.
+* PropValue in pseudo must be single word with no spaces around.
 */
 kukit.kssp.PropValueInPseudo = kukit.tk.mkParser('propvalue', {
     "{": 'this.emitAndReturn()',
@@ -392,11 +393,61 @@
     "\r": 'this.emitAndReturn()',
     "\/\*": 'this.emitAndReturn()',
     ":": 'this.emitAndReturn()',
-    "(": 'this.emitAndReturn(new kukit.kssp.MethodArgs(this.src, kukit.kssp.openparent))'
+    "(": '[new kukit.kssp.openparent(this.src), new kukit.kssp.PropValue(this.src)]',
+    ")": 'this.emitAndReturn(new kukit.kssp.closeparent(this.src))'
     });
 kukit.kssp.PropValueInPseudo.prototype.multiword_allowed = false;
-kukit.kssp.PropValueInPseudo.prototype.process = kukit.kssp.PropValue.prototype.process;
-kukit.kssp.PropValueInPseudo.prototype.valueClass = kukit.rd.KssPseudoValue;
+kukit.kssp.PropValueInPseudo.prototype.process = function() {
+    var cursor = {'next': 0};
+    this.digestTxt(cursor, kukit.tk.Fraction, kukit.kssp.Comment);
+    this.txt = '';
+    var txt = cursor.txt;
+    if (this.ifToken(cursor, kukit.kssp.String)) {
+        // The previous txt must be all whitespace.
+        if (txt) {
+            ;;; kukit.E = 'Excess characters before the string in property value';
+            this.emitError(kukit.E);
+        }
+        // the next one must be a string.
+        this.expectToken(cursor, kukit.kssp.String);
+        this.produceTxt(cursor.token.txt);
+    } else if (this.ifToken(cursor, kukit.kssp.openparent)) {
+        this.expectToken(cursor, kukit.kssp.openparent);
+        this.expectToken(cursor, kukit.kssp.PropValue);
+        this.value = new kukit.rd.KssPseudoValue(txt, cursor.token.value);
+        this.digestTxt(cursor, kukit.tk.Fraction, kukit.kssp.Comment);
+        // we have to be at the end and have no text after
+        if (cursor.txt) {
+            ;;; kukit.E = 'Excess characters before the closing parenthesis. Only one parameter is allowed.';
+            this.emitError(kukit.E);
+        }
+        // eat up everything before the closing parent
+        this.expectToken(cursor, kukit.kssp.closeparent);
+    } else {
+        // not a string or method: check if we allowed multiword.
+        if (! this.multiword_allowed && txt.indexOf(' ') != -1) {
+            ;;; kukit.E = 'Property value must be one word';
+            this.emitError(kukit.E);
+        }
+        this.produceTxt(txt);
+    }
+    // see what's after
+    if (cursor.next < this.result.length) {
+        this.digestTxt(cursor, kukit.tk.Fraction, kukit.kssp.Comment);
+        // we have to be at the end and have no text after
+        if (cursor.next < this.result.length || cursor.txt) {
+            ;;; kukit.E = 'Excess characters after the property value';
+            this.emitError(kukit.E);
+        }
+    }
+    this.result = [];
+};
+
+
+
+
+
+//kukit.kssp.PropValueInPseudo.prototype.valueClass = kukit.rd.KssPseudoValue;
 kukit.kssp.PropValueInPseudo.prototype.produceTxt = function(txt) {
     // txt parms are returned embedded
     this.value = new kukit.rd.KssPseudoValue(txt, []);
@@ -493,8 +544,10 @@
 * embedded parser to parse the selector
 * kss event selector: (has spaces in it)
 *      <css selector> selector:name(id)
+*      <css selector> selector:name(pprov(id))
 * kss method selector: (has no spaces in it)
 *      document:name(id) or behaviour:name(id)
+*      document:name(pprov(id)) or behaviour:name(pprov(id))
 */
 kukit.kssp.KssSelector = kukit.tk.mkParser('kssselector', {
     ":": '[new kukit.kssp.colon(this.src), new kukit.kssp.PropValueInPseudo(this.src)]',
@@ -551,10 +604,6 @@
         ;;; kukit.E = 'Kss event selector must have a one-word name after the colon';
         this.emitError(kukit.E);
     }
-    if (pseudotoken.value.args.length > 1) {
-        ;;; kukit.E = 'Kss pseudo value must not have more then one parameters';
-        this.emitError(kukit.E);
-    }
     css = this.src.text.substring(this.startpos, commatoken.startpos);
     //print ('>>' + css + ':' + pseudotoken.value.methodname);
     // Decide if we have an event or a method selector.
@@ -570,8 +619,14 @@
     }
     // create the selector.
     var id = null;
-    if (pseudotoken.value.args.length == 1) {
-        id = pseudotoken.value.args[0];
+    var ppid = null;
+    // XXX I think this could be simplified.
+    if (pseudotoken.value.arg.isMethod) {
+        // we have a param provider here. Just store.
+        ppid = pseudotoken.value.arg;
+    } else {
+        // just an id. Express in txt.
+        id = pseudotoken.value.arg.txt;
     }
     var name = pseudotoken.value.methodname;
     var splitname = name.split('-');
@@ -585,7 +640,7 @@
     }
     // Protect the error for better logging
     ;;; try {
-        this.kssSelector = new kukit.rd.KssSelector(isEvent, css, name, namespace, id);
+        this.kssSelector = new kukit.rd.KssSelector(isEvent, css, name, namespace, id, ppid);
     ;;; } catch(e) {
     ;;;     if (e.name == 'KssSelectorError') {
     ;;;         // Log the message
@@ -631,6 +686,7 @@
         ;;;     // foolishly, we don't know the position at this point
         ;;;     throw new kukit.err.tk.ParsingError('Undefined event name="' + rule.kss_selector.name + '", namespace="' + rule.kss_selector.namespace + '"');
         ;;; }
+        rule.kss_selector.evalId(); // XXX XXX XXX
         kukit.engine.rules.push(rule);
     }
 };

Modified: kukit/kukit.js/branch/ree-binding-improvements/kukit/resourcedata.js
==============================================================================
--- kukit/kukit.js/branch/ree-binding-improvements/kukit/resourcedata.js	(original)
+++ kukit/kukit.js/branch/ree-binding-improvements/kukit/resourcedata.js	Sat Jul  7 00:20:40 2007
@@ -41,7 +41,7 @@
 /*
 *  class KssSelector
 */
-kukit.rd.KssSelector = function(isEvent, css, name, namespace, id) {
+kukit.rd.KssSelector = function(isEvent, css, name, namespace, id, ppid) {
     this.isEventSelector = isEvent;
     this.isMethodSelector = ! isEvent;
     if (! name) {
@@ -67,18 +67,24 @@
     this.namespace = namespace;
     this.classname = null;
     this.id = id;
+    this.ppid = ppid;
 };
 
 kukit.rd.KssSelector.prototype.setIdAndClass = function() {
     // Sets up id and class on the selector, based on registration info
     this.classname = kukit.eventsGlobalRegistry.get(this.namespace, this.name).classname;
-    if (this.id == null) {
-        // singleton for class
-        this.id = kukit.rd.makeId(this.namespace, this.classname);
-    }
-    // Also set the merge id. The rules with the same merge
-    // id should be merged on the same node.
-    this.mergeid = kukit.rd.makeMergeId(this.id, this.namespace, this.name);
+};
+
+kukit.rd.KssSelector.prototype.evalId = function() {
+    if (this.ppid == null) {
+        if (this.id == null && this.ppid == null) {
+            // singleton for class
+            this.id = kukit.rd.makeId(this.namespace, this.classname);
+        }
+        // Also set the merge id. The rules with the same merge
+        // id should be merged on the same node.
+        this.mergeid = kukit.rd.makeMergeId(this.id, this.namespace, this.name);
+    }
 };
 
 /*
@@ -135,11 +141,14 @@
 /*
 *  class KssPseudoValue
 */
-kukit.rd.KssPseudoValue = function(methodname, args) {
+kukit.rd.KssPseudoValue = function(methodname, arg) {
     // A method parameter in the format 
     //      methodname(v1)
+    // can be also:
+    //      methodname(methodname2(v2))
+    //  in both cases, arg is KssTextValue, or KssMethodValue
     this.methodname = methodname;
-    this.args = args;
+    this.arg = arg;
 };
 kukit.rd.KssPseudoValue.prototype.isMethod = true;
 kukit.rd.KssPseudoValue.prototype.check = function() {

Modified: kukit/kukit.js/branch/ree-binding-improvements/tests/test_kssparser.js
==============================================================================
--- kukit/kukit.js/branch/ree-binding-improvements/tests/test_kssparser.js	(original)
+++ kukit/kukit.js/branch/ree-binding-improvements/tests/test_kssparser.js	Sat Jul  7 00:20:40 2007
@@ -1,8 +1,7 @@
 /*
-* Copyright (c) 2005-2006
-* Authors:
-*   Martin Heidegger <mastakaneda at gmail.com>
-*   Balazs Ree <ree at greenfinity.hu>
+* Copyright (c) 2005-2007
+* Authors: KSS Project Contributors (see docs/CREDITS.txt) 
+*          Martin Heidegger <mastakaneda at gmail.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as published
@@ -218,7 +217,7 @@
     };
     
     this.testPropValueInPseudo = function() {
-        // Parsing prop values in pseudo (no methods allowed)
+        // Parsing prop values in pseudo (now methods allowed too)
 
         var txt= "b";
         var src = new kukit.tk.Cursor(txt);
@@ -256,7 +255,8 @@
         parser = new kukit.kssp.PropValueInPseudo(src, null, true);
         this.assertEquals(parser.finished, true);
         this.assertEquals(parser.value.methodname, 'click');
-        this.assertListEquals(parser.value.args, ['x']);
+        this.assertEquals(parser.value.arg.isMethod, false);
+        this.assertEquals(parser.value.arg.txt, 'x');
 
         // more then 1 args not ok (but we check it only from kss selector)
         //txt= "drag(x, y)";
@@ -268,6 +268,25 @@
         //this.assertParsingError(kukit.kssp.PropValueInPseudo, src, null, true,
         //    'Excess characters after the property value', 16);
 
+
+        // methods ok
+        txt= "click(kssAttr(x))";
+        src = new kukit.tk.Cursor(txt);
+        parser = new kukit.kssp.PropValueInPseudo(src, null, true);
+        this.assertEquals(parser.finished, true);
+        this.assertEquals(parser.value.methodname, 'click');
+        this.assertEquals(parser.value.arg.isMethod, true);
+        this.assertEquals(parser.value.arg.methodname, 'kssAttr');
+        this.assertListEquals(parser.value.arg.args, ['x']);
+
+        // no more values in the method
+        txt= "click(kssAttr(x), aaa)";
+        src = new kukit.tk.Cursor(txt);
+        this.assertParsingError(kukit.kssp.PropValueInPseudo, src, null, true,
+            'Excess characters before the closing parenthesis. Only one parameter is allowed.', 000);
+
+        // XXX add more failing cases, maybe?
+        
     };
 
     this.testMethodArgs = function() {
@@ -397,7 +416,7 @@
         txt= "a:drop('hello', bello)";
         src = new kukit.tk.Cursor(txt);
         this.assertParsingError(kukit.kssp.KssSelector, src, null, true,
-            'Kss pseudo value must not have more then one parameters', 22);
+            'Excess characters before the closing parenthesis. Only one parameter is allowed.', 000);
 
         // zero params: not std css but tolerated 
         txt= "a:drop()";
@@ -452,23 +471,24 @@
             'Kss event selector must end with an event qualifier :event or :event(id)', 20);
 
         // Spaces in the end
-        txt= "   a:lang(hu, uh) b:click    ";
+        ///txt= "   a:lang(hu, uh) b:click    "; // XXX not supported
+        txt= "   a:lang(hu-uh) b:click    ";
         src = new kukit.tk.Cursor(txt);
         parser = new kukit.kssp.KssSelector(src, null, true);
         this.assertEquals(parser.finished, true);
         this.assertEquals(parser.kssSelector.isEventSelector, true);
-        this.assertEquals(parser.kssSelector.css, "   a:lang(hu, uh) b");
+        this.assertEquals(parser.kssSelector.css, "   a:lang(hu-uh) b");
         this.assertEquals(parser.kssSelector.name, 'click');
         this.assertEquals(parser.kssSelector.namespace, null);
         this.assertEquals(parser.kssSelector.id, null);
 
         // Comment in the end
-        txt= "   a:lang(hu, uh) b:click/*comment here*/";
+        txt= "   a:lang(hu-uh) b:click/*comment here*/";
         src = new kukit.tk.Cursor(txt);
         parser = new kukit.kssp.KssSelector(src, null, true);
         this.assertEquals(parser.finished, true);
         this.assertEquals(parser.kssSelector.isEventSelector, true);
-        this.assertEquals(parser.kssSelector.css, "   a:lang(hu, uh) b");
+        this.assertEquals(parser.kssSelector.css, "   a:lang(hu-uh) b");
         this.assertEquals(parser.kssSelector.name, 'click');
         this.assertEquals(parser.kssSelector.namespace, null);
         this.assertEquals(parser.kssSelector.id, null);
@@ -572,6 +592,38 @@
         this.assertEquals(parser.kssSelector.namespace, null);
         this.assertEquals(parser.kssSelector.id, 'hello');
 
+        // Param providers within the event identification
+
+        var txt= "a:drag(kssAttr(hello))";
+        var src = new kukit.tk.Cursor(txt);
+        var parser = new kukit.kssp.KssSelector(src, null, true);
+        this.assertEquals(parser.finished, true);
+        this.assertEquals(parser.kssSelector.isEventSelector, true);
+        this.assertEquals(parser.kssSelector.css, 'a');
+        this.assertEquals(parser.kssSelector.name, 'drag');
+        this.assertEquals(parser.kssSelector.namespace, null);
+        this.assertEquals(parser.kssSelector.id, null);
+        this.assertEquals(parser.kssSelector.ppid.methodname, 'kssAttr');
+        this.assertListEquals(parser.kssSelector.ppid.args, ['hello']);
+
+        var txt= "a:drag(kssAttr(hello, true ))";
+        var src = new kukit.tk.Cursor(txt);
+        var parser = new kukit.kssp.KssSelector(src, null, true);
+        this.assertEquals(parser.finished, true);
+        this.assertEquals(parser.kssSelector.isEventSelector, true);
+        this.assertEquals(parser.kssSelector.css, 'a');
+        this.assertEquals(parser.kssSelector.name, 'drag');
+        this.assertEquals(parser.kssSelector.namespace, null);
+        this.assertEquals(parser.kssSelector.id, null);
+        this.assertEquals(parser.kssSelector.ppid.methodname, 'kssAttr');
+        this.assertListEquals(parser.kssSelector.ppid.args, ['hello', 'true']);
+
+        var txt= "a:drag(kssAttr(hello), xxx)";
+        var src = new kukit.tk.Cursor(txt);
+        this.assertParsingError(kukit.kssp.KssSelector, src, null, true,
+            'Excess characters before the closing parenthesis. Only one parameter is allowed.', 000);
+
+
     }
  
     this.testEmptyDoc = function() {
@@ -651,6 +703,9 @@
             +'setStyle-kssSelector: "#button_4";\n'
             +'setStyle-name: backgroundColor;\n'
             +'setStyle-value: #FFa0a0;\n'
+            +'}\n'
+            +"#button-one:annoyClicker-click(kssAttr(widannoy)) {\n"
+            +"   action-client:     alert;\n"
             +"}\n";
 
         var src = new kukit.tk.Cursor(txt);
@@ -659,13 +714,13 @@
         
         var parser = new kukit.kssp.Document(src, null, true);
         this.assertEquals(parser.finished, true);
-        this.assertEquals(parser.eventRules.length, 12);
+        this.assertEquals(parser.eventRules.length, 13);
         var rule;
         var action;
 
         // rule 0
             // #calendar-previous a:click {
-            //   kss-action : kukitresponse/kukitGetPreviousMonth;
+            //   action-server : kukitresponse/kukitGetPreviousMonth;
             // }
         rule = parser.eventRules[0];
         this.assertDictEquals(rule.parms, {});
@@ -684,7 +739,7 @@
             // div#update-area:timeout {
             //   evt-timeout-delay: 2000;
             //   effect: fade;
-            //   kss-action: getCurrentTime;
+            //   action-server: getCurrentTime;
             // }
         rule = parser.eventRules[1];
         this.assertDictEquals(rule.parms, {'delay': '2000'});
@@ -703,7 +758,7 @@
         
         // rule 2
             // #calendar-previous a:click {
-            //   kss-action : 'kukitresponse/kukitGetPreviousMonth' /* place comment here*/;
+            //   action-server : 'kukitresponse/kukitGetPreviousMonth' /* place comment here*/;
             // }
         rule = parser.eventRules[2];
         this.assertDictEquals(rule.parms, {});
@@ -720,7 +775,7 @@
 
         // rule 3
             // #calendar-previous a:click {
-            //   kss-action : 'kukitresponse/kukitGetPreviousMonth' /* place comment here*/;
+            //   action-server : 'kukitresponse/kukitGetPreviousMonth' /* place comment here*/;
             //   member: formVar(edit, 'f_member');
             // }
         rule = parser.eventRules[3];
@@ -740,7 +795,7 @@
          
         // rule 4
             // #calendar-previous a:dnd-drag(shelve) {
-            //   kss-action : whatever
+            //   action-server : whatever
             // }
         rule = parser.eventRules[4];
         this.assertDictEquals(rule.parms, {});
@@ -758,7 +813,7 @@
  
         // rule 5
             //#button-one:annoyClicker-click(annoyMe) {
-            //   kss-action:     clickedButton;
+            //   action-server:     clickedButton;
             //   id:             nodeAttr(id);
             //}
         rule = parser.eventRules[5];
@@ -778,7 +833,7 @@
 
         // rule 6
             // document:annoy(annoyMe) {
-            //   kss-action:    alert;
+            //   action-client:    alert;
             //   message:       "You are an idiot! Ha ha ha. (But just keep on trying...)";
             //}
         rule = parser.eventRules[6];
@@ -798,8 +853,7 @@
 
         // rule 7
             // document:annoyClicker-annoy(annoyMe) {
-            // annoy#annoy-me {
-            //   kss-action:    alert;
+            //   action-client:    alert;
             //   message:       "You are an idiot! Ha ha ha. (But just keep on trying...)";
             //}
         rule = parser.eventRules[7];
@@ -887,7 +941,7 @@
                 'kssSelector': new kukit.rd.KssMethodValue('htmlid', ['button_2'])
             });
 
-        // rule 10
+        // rule 11
             //#button_3:click {
             //    action-client: setStyle;
             //    setStyle-kssSelector: "#button_4";
@@ -913,8 +967,27 @@
                 'kssSelector': new kukit.rd.KssTextValue('#button_4')
             });
 
+        // rule 12
+            // #button-one:annoyClicker-click(kssAttr(widannoy)) {\n"
+            //   action-client:    alert;
+            //}
+        rule = parser.eventRules[12];
+        this.assertDictEquals(rule.parms, {});
+        this.assertEquals(rule.kss_selector.css, '#button-one');
+        this.assertEquals(rule.kss_selector.isEventSelector, true);
+        this.assertEquals(rule.kss_selector.name, 'click');
+        this.assertEquals(rule.kss_selector.namespace, 'annoyClicker');
+        this.assertEquals(rule.kss_selector.id, null);
+        this.assertEquals(rule.kss_selector.ppid.methodname, 'kssAttr');
+        this.assertListEquals(rule.kss_selector.ppid.args, ['widannoy']);
+        action = rule.actions.content['alert'];
+        this.assertEquals(action.type, 'C');
+        this.assertEquals(action.name, 'alert');
+        this.assertEquals(action.error, null);
+        this.assertKssParmEquals(action.parms, {
+            });
 
-        
+       
     };
 };
     


More information about the Kukit-checkins mailing list