[KSS-checkins] r46035 - in kukit/kukit.js/branch/commas-in-selectors: kukit tests

gotcha at codespeak.net gotcha at codespeak.net
Mon Aug 27 16:59:51 CEST 2007


Author: gotcha
Date: Mon Aug 27 16:59:51 2007
New Revision: 46035

Modified:
   kukit/kukit.js/branch/commas-in-selectors/kukit/kssparser.js
   kukit/kukit.js/branch/commas-in-selectors/kukit/tokenizer.js
   kukit/kukit.js/branch/commas-in-selectors/tests/test_kssparser.js
Log:
Code to work on

Modified: kukit/kukit.js/branch/commas-in-selectors/kukit/kssparser.js
==============================================================================
--- kukit/kukit.js/branch/commas-in-selectors/kukit/kssparser.js	(original)
+++ kukit/kukit.js/branch/commas-in-selectors/kukit/kssparser.js	Mon Aug 27 16:59:51 2007
@@ -66,30 +66,33 @@
 kukit.kssp.Document.prototype.addBlock = function(key, block) {
     // Parse the part in an embedded parser
     var src = new kukit.tk.Cursor(key + ' ');
-    var parser = new kukit.kssp.KssSelector(src, null, true);
+    var parser = new kukit.kssp.KssSelectors(src, null, true);
     // check the event name and namespace use in evt- rules
     // 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.
-;;;         kukit.E = 'Wrong prefix : we have "' + block.evt_namespace;
-;;;         kukit.E += '-' + block.evt_name + '" instead of "' + key;
-;;;         kukit.E += '". KSS prefix ';
-;;;         kukit.E += '"evt-[<NAMESPACE>-]<EVENTNAME>-<NAME>" ';
-;;;         kukit.E += 'must not have different [namespace and] ';
-;;;         kukit.E += 'name than the KSS selector at the top of the ';
-;;;         kukit.E += 'rule.';
-            block.emitError(kukit.E);
-        }
-    }
+//    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.
+//;;;         kukit.E = 'Wrong prefix : we have "' + block.evt_namespace;
+//;;;         kukit.E += '-' + block.evt_name + '" instead of "' + key;
+//;;;         kukit.E += '". KSS prefix ';
+//;;;         kukit.E += '"evt-[<NAMESPACE>-]<EVENTNAME>-<NAME>" ';
+//;;;         kukit.E += 'must not have different [namespace and] ';
+//;;;         kukit.E += 'name than the KSS selector at the top of the ';
+//;;;         kukit.E += 'rule.';
+//            block.emitError(kukit.E);
+//        }
+//    }
     // Create the event rule. (one action only)
-    var eventRule = new kukit.rd.EventRule(parser.kssSelector,
-        block.eventParameters, block.actions);
-    // Store the rule
-    this.eventRules.push(eventRule);
+    for(var i=0; i<parser.selectors.length; ++i) {
+        var parsedSelector = parser.selectors[i];
+        var eventRule = new kukit.rd.EventRule(parsedSelector.kssSelector,
+            block.eventParameters, block.actions);
+        // Store the rule
+        this.eventRules.push(eventRule);
+    };
 };
 
 /*
@@ -351,7 +354,7 @@
     this.digestTxt(cursor, kukit.tk.Fraction, kukit.kssp.Comment);
     this.txt = '';
     var txt = cursor.txt;
-    if (this.isToken(cursor, kukit.kssp.String)) {
+    if (this.notInTokens(cursor, kukit.kssp.String)) {
         // The previous txt must be all whitespace.
         if (txt) {
 ;;;         kukit.E = 'Wrong value : unallowed characters [' + txt + ']';
@@ -361,7 +364,7 @@
         // the next one must be a string.
         this.expectToken(cursor, kukit.kssp.String);
         this.produceTxt(cursor.token.txt);
-    } else if (this.isToken(cursor, kukit.kssp.MethodArgs)) {
+    } else if (this.notInTokens(cursor, kukit.kssp.MethodArgs)) {
         // see if not empty and has no spaces in it 
         if (! txt || txt.indexOf(' ') != -1) {
 ;;;         kukit.E = 'Wrong value : method name [' + txt + '] cannot ';
@@ -534,6 +537,39 @@
 };
 
 /*
+* class KssSelectors
+*
+* embedded parser to parse the block of selectors
+* KSS event selector: (has spaces in it)
+*      <css selector> selector:name(id)
+* KSS method selector: (has no spaces in it)
+*      document:name(id) or behaviour:name(id)
+*/
+kukit.kssp.KssSelectors = kukit.tk.mkParser('kssselectors', {
+    ",": 'new kukit.kssp.comma(this.src)',
+    "{": 'this.emitAndReturn()',
+    "\/\*": 'new kukit.kssp.Comment(this.src, kukit.kssp.commentbegin)'
+    });
+kukit.kssp.KssSelectors.prototype.process = function() {
+    this.selectors = [];
+    var cursor = {'next': 1};
+    
+    var parser = new kukit.kssp.KssSelector(this.result[0].txt, null, true);
+    this.selectors.push(parser);
+
+    while (cursor.next < this.result.length-1) {
+        this.digestTxt(cursor, kukit.kssp.Comment);
+        var kssSelectorTxt = cursor.txt;
+        this.expectToken(cursor, kukit.kssp.KssSelector);
+        this.selectors.push(cursor.token);
+        if (cursor.next == this.result.length-1) break;
+        this.expectToken(cursor, kukit.kssp.comma);
+    };
+    this.result = [];
+    this.txt = '';
+};
+
+/*
 * class KssSelector
 *
 * embedded parser to parse the selector
@@ -552,16 +588,16 @@
     var name;
     var namespace = null;
     var id = null;
-    var tokenindex = this.result.length - 1;
+    var tokenIndex = this.result.length - 1;
     // Find the method parms and calculate the end of css parms. (RL)
     var cycle = true;
-    while (cycle && tokenindex >= 0) {
-        var token = this.result[tokenindex];
+    while (cycle && tokenIndex >= 0) {
+        var token = this.result[tokenIndex];
         switch (token.symbol) {
             case kukit.tk.Fraction.prototype.symbol: {
                 // if all spaces, go to previous one
                 if (token.txt.match(/^[\r\n\t ]*$/) != null) {
-                    tokenindex -= 1;
+                    tokenIndex -= 1;
                 } else {
 ;;;                 kukit.E = 'Wrong event selector : missing event ';
 ;;;                 kukit.E += 'qualifier :<EVENTNAME> ';
@@ -570,7 +606,7 @@
                 }
             } break;
             case kukit.kssp.Comment.prototype.symbol: {
-                tokenindex -= 1;
+                tokenIndex -= 1;
             } break;
             default: {
                 cycle = false;
@@ -578,22 +614,22 @@
         }
     }
     // Now we found the token that must be <fraction> <colon> <propvalue>.
-    tokenindex -= 2;
-    if (tokenindex < 0
-         || (this.result[tokenindex+2].symbol !=
+    tokenIndex -= 2;
+    if (tokenIndex < 0
+         || (this.result[tokenIndex+2].symbol !=
                 kukit.kssp.EventValue.prototype.symbol)
-         || (this.result[tokenindex+1].symbol != 
+         || (this.result[tokenIndex+1].symbol != 
                 kukit.kssp.colon.prototype.symbol)
-         || (this.result[tokenindex].symbol !=
+         || (this.result[tokenIndex].symbol !=
                 kukit.tk.Fraction.prototype.symbol)) {
 ;;;     kukit.E = 'Wrong event selector : missing event qualifier ';
 ;;;     kukit.E += ':<EVENTNAME> or :<EVENTNAME>(<ID>).';
         this.emitError(kukit.E);
     }
     // See that the last fraction does not end with space.
-    var lasttoken = this.result[tokenindex];
-    var commatoken = this.result[tokenindex+1];
-    var pseudotoken = this.result[tokenindex+2];
+    var lasttoken = this.result[tokenIndex];
+    var commatoken = this.result[tokenIndex+1];
+    var pseudotoken = this.result[tokenIndex+2];
     var txt = lasttoken.txt;
     if (txt.match(/[\r\n\t ]$/) != null) {
 ;;;     kukit.E = 'Wrong event selector :';

Modified: kukit/kukit.js/branch/commas-in-selectors/kukit/tokenizer.js
==============================================================================
--- kukit/kukit.js/branch/commas-in-selectors/kukit/tokenizer.js	(original)
+++ kukit/kukit.js/branch/commas-in-selectors/kukit/tokenizer.js	Mon Aug 27 16:59:51 2007
@@ -130,7 +130,7 @@
     return (!token || currentValue.symbol != token.prototype.symbol);
 };
 
-kukit.tk._ParserBase.prototype.isToken = 
+kukit.tk._ParserBase.prototype.notInTokens = 
     function(cursor, token1, token2, token3, token4) {
     var i = cursor.next;
     var currentValue = this.result[i];
@@ -148,7 +148,7 @@
     // digests the txt from the tokens, ignores given token
     // plus whitespace removal
     this.digestExactTxt(cursor, token1, token2, token3, token4);
-    cursor.txt = this.dewhitespaceAndTrim(cursor.txt);
+    cursor.txt = this.removeWhitespacesAndTrim(cursor.txt);
 };
 
 kukit.tk._ParserBase.prototype.digestExactTxt =
@@ -156,7 +156,7 @@
     // digests the txt from the tokens, ignores given token
     // exact value: no whitespace removal
     var result = '';
-    while (this.isToken(cursor, token1, token2, token3, token4)) {
+    while (this.notInTokens(cursor, token1, token2, token3, token4)) {
         result += this.result[cursor.next].txt;
         cursor.next ++;
         }
@@ -164,7 +164,7 @@
 };
 
 
-kukit.tk._ParserBase.prototype.dewhitespace = function(txt) {
+kukit.tk._ParserBase.prototype.removeWhitespaces = function(txt) {
     // removes ws but leaves leading and trailing one
     if (txt != ' ') { //speedup only
         txt = txt.replace(/[\r\n\t ]+/g, ' ');
@@ -172,8 +172,8 @@
     return txt;
 };
     
-kukit.tk._ParserBase.prototype.dewhitespaceAndTrim = function(txt) {
-    txt = this.dewhitespace(txt);
+kukit.tk._ParserBase.prototype.removeWhitespacesAndTrim = function(txt) {
+    txt = this.removeWhitespaces(txt);
     // XXX Strange thing is: following replace works from
     // tests and the original demo, but with kukitportlet demo
     // it breaks. Someone stinks!

Modified: kukit/kukit.js/branch/commas-in-selectors/tests/test_kssparser.js
==============================================================================
--- kukit/kukit.js/branch/commas-in-selectors/tests/test_kssparser.js	(original)
+++ kukit/kukit.js/branch/commas-in-selectors/tests/test_kssparser.js	Mon Aug 27 16:59:51 2007
@@ -651,7 +651,7 @@
             +'#button_3:click {\n'
             +'action-client: setStyle;\n'
             +'setStyle-kssSelector: "#button_4";\n'
-            +'setStyle-name: backgroundColor;\n'
+            +'setStyle-name: /* comment blabla */ backgroundColor;\n'
             +'setStyle-value: #FFa0a0;\n'
             +"}\n";
 


More information about the Kukit-checkins mailing list