[KSS-checkins] r49856 - kukit/kukit.js/branch/finish-closures/kukit

gotcha at codespeak.net gotcha at codespeak.net
Sun Dec 16 23:42:28 CET 2007


Author: gotcha
Date: Sun Dec 16 23:42:27 2007
New Revision: 49856

Modified:
   kukit/kukit.js/branch/finish-closures/kukit/kssparser.js
   kukit/kukit.js/branch/finish-closures/kukit/tokenizer.js
Log:
class closures - step 2

Modified: kukit/kukit.js/branch/finish-closures/kukit/kssparser.js
==============================================================================
--- kukit/kukit.js/branch/finish-closures/kukit/kssparser.js	(original)
+++ kukit/kukit.js/branch/finish-closures/kukit/kssparser.js	Sun Dec 16 23:42:27 2007
@@ -46,331 +46,400 @@
 /*
 * class Document 
 */
-kssp.Document = kukit.tk.mkParser('document', {
-    "\/\*": 'new kukit.kssp.Comment(this.cursor, kukit.kssp.openComment)',
-    "{": 'new kukit.kssp.Block(this.cursor, kukit.kssp.openBrace)'
-    });
-kssp.Document.prototype.process = function() {
-    this.eventRules = [];
-    // Parse all tokens (including first and last)
-    var context = {'nextTokenIndex': 0};
-    while (context.nextTokenIndex < this.result.length) {
-        this.digestTxt(context, kukit.tk.Fraction, kukit.kssp.Comment);
-        var key = context.txt;
-        if (! key) {
-            break;
-        }
-        this.expectToken(context, kukit.kssp.Block);
-        var block = context.token;
-        var rules = block.parseSelectors(key);
-        this.addRules(rules);
-    }
-    this.result = [];
-    this.txt = '';
-};
+var _Document = function() {
+    this.process = function() {
+        this.eventRules = [];
+        // Parse all tokens (including first and last)
+        var context = {'nextTokenIndex': 0};
+        while (context.nextTokenIndex < this.result.length) {
+            this.digestTxt(context, kukit.tk.Fraction, kukit.kssp.Comment);
+            var key = context.txt;
+            if (! key) {
+                break;
+            }
+            this.expectToken(context, kukit.kssp.Block);
+            var block = context.token;
+            var rules = block.parseSelectors(key);
+            this.addRules(rules);
+        }
+        this.result = [];
+        this.txt = '';
+    };
 
-kssp.Document.prototype.addRules = function(rules) {
-    // Create the event rules.
-    for(var i=0; i<rules.length; i++) {
-        this.eventRules.push(rules[i]);
+    this.addRules = function(rules) {
+        // Create the event rules.
+        for(var i=0; i<rules.length; i++) {
+            this.eventRules.push(rules[i]);
+        };
     };
 };
 
+kssp.Document = kukit.tk.mkParserBis('document', {
+    "\/\*": 'new kukit.kssp.Comment(this.cursor, kukit.kssp.openComment)',
+    "{": 'new kukit.kssp.Block(this.cursor, kukit.kssp.openBrace)'
+    },
+    _Document
+    );
+
 /*
 * class Comment 
 */
-kssp.Comment = kukit.tk.mkParser('comment', {
+var _Comment = function() {
+    this.process = function() {
+        this.result = [];
+        this.txt = ' ';
+    };
+};
+kssp.Comment = kukit.tk.mkParserBis('comment', {
     // it's not 100% good, but will do
     "\*\/": 'this.emitAndReturn(new kukit.kssp.closeComment(this.cursor))'
-    });
-kssp.Comment.prototype.process = function() {
-    this.result = [];
-    this.txt = ' ';
-};
+    },
+    _Comment
+    );
 
 /*
 * class Block 
 */
-kssp.Block = kukit.tk.mkParser('block', {
-    ";": 'new kukit.kssp.semicolon(this.cursor)',
-    ":": '[new kukit.kssp.colon(this.cursor), new kukit.kssp.PropValue(this.cursor)]',
-    "}": 'this.emitAndReturn(new kukit.kssp.closeBrace(this.cursor))'
-    });
-kssp.Block.prototype.process = function() {
-    //this.parms = {};
-    this.eventFullNames = {};
-    this.actions = new kukit.rd.ActionSet();
-    // Parse all tokens (except first and last)
-    var context = {'nextTokenIndex': 1};
-    while (context.nextTokenIndex < this.result.length-1) {
-        this.digestTxt(context, kukit.tk.Fraction, kukit.kssp.Comment);
-        var key = context.txt;
-        if (! key) {
-            break;
-        }
-        this.expectToken(context, kukit.kssp.colon);
-        this.expectToken(context, kukit.kssp.PropValue);
-        // store the wrapped prop
-        this.addDeclaration(key, context.token.value);
-        if (context.nextTokenIndex == this.result.length-1) break;
-        this.expectToken(context, kukit.kssp.semicolon);
-    }
-    this.result = [];
-    this.txt = '';
-};
+var _Block = function() {
+    this.process = function() {
+        //this.parms = {};
+        this.eventFullNames = {};
+        this.actions = new kukit.rd.ActionSet();
+        // Parse all tokens (except first and last)
+        var context = {'nextTokenIndex': 1};
+        while (context.nextTokenIndex < this.result.length-1) {
+            this.digestTxt(context, kukit.tk.Fraction, kukit.kssp.Comment);
+            var key = context.txt;
+            if (! key) {
+                break;
+            }
+            this.expectToken(context, kukit.kssp.colon);
+            this.expectToken(context, kukit.kssp.PropValue);
+            // store the wrapped prop
+            this.addDeclaration(key, context.token.value);
+            if (context.nextTokenIndex == this.result.length-1) break;
+            this.expectToken(context, kukit.kssp.semicolon);
+        }
+        this.result = [];
+        this.txt = '';
+    };
 
-kssp.Block.prototype.parseSelectors = function(key) {
-    // Parse the part in an embedded parser
-    var cursor = new kukit.tk.Cursor(key + ' ');
-    var parser = new kukit.kssp.KssSelectors(cursor, null, true);
-    var results = [];
-    var hasFullNames = false;
-    for(var eventFullName in this.eventFullNames) {
-        var hasFullNames = true;
-        var found = false;
-        for(var i=0; i< parser.selectors.length; ++i) {
-            var fullName = '';
-            var kssSelector = parser.selectors[i];
-            if (kssSelector.namespace) {
-                fullName = kssSelector.namespace + '-';
-            }
-            fullName += kssSelector.name;
-            if (fullName == eventFullName) {
-                var eventParameters = this.eventFullNames[fullName];
-                var eventRule;
-                if (typeof(eventParameters)!='undefined') {
-                    eventRule = new kukit.rd.EventRule(kssSelector,
-                                                eventParameters, this.actions);
+    this.parseSelectors = function(key) {
+        // Parse the part in an embedded parser
+        var cursor = new kukit.tk.Cursor(key + ' ');
+        var parser = new kukit.kssp.KssSelectors(cursor, null, true);
+        var results = [];
+        var hasFullNames = false;
+        for(var eventFullName in this.eventFullNames) {
+            var hasFullNames = true;
+            var found = false;
+            for(var i=0; i< parser.selectors.length; ++i) {
+                var fullName = '';
+                var kssSelector = parser.selectors[i];
+                if (kssSelector.namespace) {
+                    fullName = kssSelector.namespace + '-';
                 }
-                else{
-                    eventRule = new kukit.rd.EventRule(kssSelector,
-                                                {}, this.actions);
+                fullName += kssSelector.name;
+                if (fullName == eventFullName) {
+                    var eventParameters = this.eventFullNames[fullName];
+                    var eventRule;
+                    if (typeof(eventParameters)!='undefined') {
+                        eventRule = new kukit.rd.EventRule(kssSelector,
+                                                    eventParameters, this.actions);
+                    }
+                    else{
+                        eventRule = new kukit.rd.EventRule(kssSelector,
+                                                    {}, this.actions);
+                    }
+                    results.push(eventRule);
+                    found = true;
                 }
-                results.push(eventRule);
-                found = true;
+            }
+            if (! found){
+;;;             kukit.E = 'Wrong value for evt-[<NAMESPACE>-]<EVENTNAME> [' + eventFullName + '] : ';
+;;;             kukit.E += '<NAMESPACE>-<EVENTNAME> should exist in the event of the selectors.';
+                this.emitError(kukit.E);
             }
         }
-        if (! found){
-;;;         kukit.E = 'Wrong value for evt-[<NAMESPACE>-]<EVENTNAME> [' + eventFullName + '] : ';
-;;;         kukit.E += '<NAMESPACE>-<EVENTNAME> should exist in the event of the selectors.';
-            this.emitError(kukit.E);
+        if (! hasFullNames){
+            for(var i=0; i< parser.selectors.length; ++i) {
+                var kssSelector = parser.selectors[i];
+                eventRule = new kukit.rd.EventRule(kssSelector,
+                                                   {}, this.actions);
+                results.push(eventRule);
+            }
         }
-    }
-    if (! hasFullNames){
-        for(var i=0; i< parser.selectors.length; ++i) {
-            var kssSelector = parser.selectors[i];
-            eventRule = new kukit.rd.EventRule(kssSelector,
-                                               {}, this.actions);
-            results.push(eventRule);
-        }
-    }
-    return results;
-}
-
-kssp.Block.prototype.addEventDeclaration = function(key, splitkey, value) {
-
-    // evt-<EVTNAME>-<PARAMETER>: <VALUE>
-    // evt-<NAMESPACE>-<EVTNAME>-<PARAMETER>: <VALUE>
-;;; if (splitkey.length < 3) {
-;;;     kukit.E = 'Wrong rule key : "' + key + '". ';
-;;;     kukit.E += 'KSS rule key must be "<ACTIONNAME>-<PARAMETER>"';
-;;;     kukit.E += ' or "<NAMESPACE>-<ACTIONNAME>-<PARAMETER>" or ';
-;;;     kukit.E += '"evt-<EVENTNAME>-<PARAMETER>" or ';
-;;;     kukit.E += '"evt-<NAMESPACE>-<EVENTNAME>-<PARAMETER>".';
-;;;     this.emitError(kukit.E);
-;;; }
-    var eventNamespace;
-    var eventName;
-    var eventKey;
-    var eventFullName;
-    if (splitkey.length == 3) {
-        // evt-<EVENTNAME>-<PARAMETER>: <VALUE>
-        eventName =  splitkey[1];
-        eventKey = splitkey[2];
-        eventFullName = eventName;
-    } else {
-        // evt-<NAMESPACE>-<EVENTNAME>-<PARAMETER>: <VALUE>
-        eventNamespace = splitkey[1];
-        eventName = splitkey[2];
-        eventKey = splitkey[3];
-        eventFullName = eventNamespace + '-' + eventName;
-    }
-;;; if (value.isMethod != false) {
-;;;     kukit.E = 'Wrong value for key [' + key + '] : ';
-;;;     kukit.E += 'value providers are not ';
-;;;     kukit.E += 'allowed as value for ';
-;;;     kukit.E += 'evt-[<NAMESPACE>-]<EVENTNAME>-<PARAMETER> keys.';
-;;;     this.emitError(kukit.E);
-;;; }
-    var eventParameters = this.eventFullNames[eventFullName];
-    if (typeof(eventParameters) == 'undefined') {
-        this.eventFullNames[eventFullName] = {};
-        eventParameters = this.eventFullNames[eventFullName];
-    }
-    eventParameters[eventKey] = value.txt;
-}
-
-kssp.Block.prototype.addActionDeclaration = function(key, splitkey, value) {
-    // action-server: <ACTIONNAME>
-    // action-client: <ACTIONNAME>
-    // action-client: <NAMESPACE>-<ACTIONNAME>
-    // action-cancel: <ACTIONNAME>
-    // action-cancel: <NAMESPACE>-<ACTIONNAME>
-;;; if (splitkey.length != 2) {
-;;;     kukit.E = 'Wrong key [' + key + '] : ';
-;;;     kukit.E += 'action-<QUALIFIER> keys can have only one dash.';
-;;;     this.emitError(kukit.E);
+        return results;
+    };
+
+    this.addEventDeclaration = function(key, splitkey, value) {
+
+        // evt-<EVTNAME>-<PARAMETER>: <VALUE>
+        // evt-<NAMESPACE>-<EVTNAME>-<PARAMETER>: <VALUE>
+;;;     if (splitkey.length < 3) {
+;;;         kukit.E = 'Wrong rule key : "' + key + '". ';
+;;;         kukit.E += 'KSS rule key must be "<ACTIONNAME>-<PARAMETER>"';
+;;;         kukit.E += ' or "<NAMESPACE>-<ACTIONNAME>-<PARAMETER>" or ';
+;;;         kukit.E += '"evt-<EVENTNAME>-<PARAMETER>" or ';
+;;;         kukit.E += '"evt-<NAMESPACE>-<EVENTNAME>-<PARAMETER>".';
+;;;         this.emitError(kukit.E);
 ;;;     }
-;;; if (value.isMethod != false) {
-;;;     kukit.E = 'Wrong value for key [' + key + '] : ';
-;;;     kukit.E += 'value providers are not ';
-;;;     kukit.E += 'allowed for action-<QUALIFIER> keys.';
-;;;     this.emitError(kukit.E);
+        var eventNamespace;
+        var eventName;
+        var eventKey;
+        var eventFullName;
+        if (splitkey.length == 3) {
+            // evt-<EVENTNAME>-<PARAMETER>: <VALUE>
+            eventName =  splitkey[1];
+            eventKey = splitkey[2];
+            eventFullName = eventName;
+        } else {
+            // evt-<NAMESPACE>-<EVENTNAME>-<PARAMETER>: <VALUE>
+            eventNamespace = splitkey[1];
+            eventName = splitkey[2];
+            eventKey = splitkey[3];
+            eventFullName = eventNamespace + '-' + eventName;
+        }
+;;;     if (value.isMethod != false) {
+;;;         kukit.E = 'Wrong value for key [' + key + '] : ';
+;;;         kukit.E += 'value providers are not ';
+;;;         kukit.E += 'allowed as value for ';
+;;;         kukit.E += 'evt-[<NAMESPACE>-]<EVENTNAME>-<PARAMETER> keys.';
+;;;         this.emitError(kukit.E);
 ;;;     }
-    var atab = {'server': 'S', 'client': 'C', 'cancel': 'X'};
-    var actionType = atab[splitkey[1]];
-;;; if (! actionType) {
-;;;     kukit.E = 'Wrong key [' + key + '] : ';
-;;;     kukit.E += 'qualifier in action-<QUALIFIER> keys must be ';
-;;;     kukit.E += '"server" or "client" or "cancel".'; 
-;;;     this.emitError(kukit.E);
-;;;     }    
-;;; // force value to be <ACTIONNAME> or <NAMESPACE>-<ACTIONNAME>
-;;; var splitvalue = value.txt.split('-');
-;;; if (splitvalue.length > 2) {
-;;;     kukit.E = 'Wrong value for key [' + key + '] : ';
-;;;     kukit.E += 'value must be <ACTIONNAME> or <NAMESPACE>';
-;;;     kukit.E += '-<ACTIONNAME> for action-<QUALIFIER> keys.';
-;;;     this.emitError(kukit.E);
+        var eventParameters = this.eventFullNames[eventFullName];
+        if (typeof(eventParameters) == 'undefined') {
+            this.eventFullNames[eventFullName] = {};
+            eventParameters = this.eventFullNames[eventFullName];
+        }
+        eventParameters[eventKey] = value.txt;
+    };
+
+    this.addActionDeclaration = function(key, splitkey, value) {
+        // action-server: <ACTIONNAME>
+        // action-client: <ACTIONNAME>
+        // action-client: <NAMESPACE>-<ACTIONNAME>
+        // action-cancel: <ACTIONNAME>
+        // action-cancel: <NAMESPACE>-<ACTIONNAME>
+;;;     if (splitkey.length != 2) {
+;;;         kukit.E = 'Wrong key [' + key + '] : ';
+;;;         kukit.E += 'action-<QUALIFIER> keys can have only one dash.';
+;;;         this.emitError(kukit.E);
+;;;         }
+;;;     if (value.isMethod != false) {
+;;;         kukit.E = 'Wrong value for key [' + key + '] : ';
+;;;         kukit.E += 'value providers are not ';
+;;;         kukit.E += 'allowed for action-<QUALIFIER> keys.';
+;;;         this.emitError(kukit.E);
+;;;         }
+        var atab = {'server': 'S', 'client': 'C', 'cancel': 'X'};
+        var actionType = atab[splitkey[1]];
+;;;     if (! actionType) {
+;;;         kukit.E = 'Wrong key [' + key + '] : ';
+;;;         kukit.E += 'qualifier in action-<QUALIFIER> keys must be ';
+;;;         kukit.E += '"server" or "client" or "cancel".'; 
+;;;         this.emitError(kukit.E);
+;;;         }    
+;;;     // force value to be <ACTIONNAME> or <NAMESPACE>-<ACTIONNAME>
+;;;     var splitvalue = value.txt.split('-');
+;;;     if (splitvalue.length > 2) {
+;;;         kukit.E = 'Wrong value for key [' + key + '] : ';
+;;;         kukit.E += 'value must be <ACTIONNAME> or <NAMESPACE>';
+;;;         kukit.E += '-<ACTIONNAME> for action-<QUALIFIER> keys.';
+;;;         this.emitError(kukit.E);
+;;;         }
+        // set it
+        var action = this.actions.getOrCreateAction(value.txt);
+        if (actionType != 'X' || action.type == null) {
+            action.setType(actionType);
+        } else {
+            this.actions.deleteAction(value.txt);
+        }
+    };
+
+    this.addActionError = function(action, key, value) {
+        // <ACTIONNAME>-error: <VALUE>
+        // default-error: <VALUE>
+;;;     if (value.isMethod == true) {
+;;;         kukit.E = 'Wrong value for key [' + key + '] : ';
+;;;         kukit.E += 'value providers are not ';
+;;;         kukit.E += 'allowed for <ACTIONNAME>-error keys.';
+;;;         this.emitError(kukit.E);
 ;;;     }
-    // set it
-    var action = this.actions.getOrCreateAction(value.txt);
-    if (actionType != 'X' || action.type == null) {
-        action.setType(actionType);
-    } else {
-        this.actions.deleteAction(value.txt);
-    }
-}
-
-kssp.Block.prototype.addActionError = function(action, key, value) {
-    // <ACTIONNAME>-error: <VALUE>
-    // default-error: <VALUE>
-;;; if (value.isMethod == true) {
-;;;     kukit.E = 'Wrong value for key [' + key + '] : ';
-;;;     kukit.E += 'value providers are not ';
-;;;     kukit.E += 'allowed for <ACTIONNAME>-error keys.';
-;;;     this.emitError(kukit.E);
-;;; }
-    action.setError(value.txt);
-    // also create the action for the error itself.
-    var err_action = this.actions.getOrCreateAction(value.txt);
-    err_action.setType('E');
-}
-
-kssp.Block.prototype.addActionParameter = function(action, key, value) {
-    var ppRegistries = {
-        '': kukit.pprovidersGlobalRegistry,
-        'kssSelector': kukit.sr.pproviderSelRegistry,
-        'kssSubmitForm': kukit.fo.pproviderFormRegistry
-    };
-
-    // <ACTIONNAME>-<KEY>: <VALUE>
-    // default-<KEY>: <VALUE>
-    // 
-    // value may be either txt or method parms, 
-    // and they get stored with the wrapper.
-    // 
-    // Check the syntax of the value at this point.
-    // This will also set the value providers on the value
-    // (from check).
-    //
-    // Figure out which registry to use.
-    var registry = ppRegistries[key];
-    if (typeof(registry) == 'undefined') {
-        // use default pproviders
-        registry = ppRegistries[''];
-    }
-    //
-    try {
-        // Check also sets the value provider on the value.
-        value.check(registry);
-    } catch(e) {
-;;;     kukit.E = 'Error in value : ' + e + '.';
-        this.emitError(kukit.E);
-    }
-    action.parms[key] = value;
-}
+        action.setError(value.txt);
+        // also create the action for the error itself.
+        var err_action = this.actions.getOrCreateAction(value.txt);
+        err_action.setType('E');
+    };
+
+    this.addActionParameter = function(action, key, value) {
+        var ppRegistries = {
+            '': kukit.pprovidersGlobalRegistry,
+            'kssSelector': kukit.sr.pproviderSelRegistry,
+            'kssSubmitForm': kukit.fo.pproviderFormRegistry
+        };
 
-kssp.Block.prototype.addDeclaration = function(key, value) {
-    // p.s. value is here a KssXxParm. In most cases we check and unwrap it.
-    // 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 splitkey = key.split('-');
-;;; if (splitkey.length < 2 || splitkey.length > 4) {
-;;;     kukit.E = 'Wrong rule key : "' + key + '". ';
-;;;     kukit.E += 'KSS rule key must be "<ACTIONNAME>-<PARAMETER>" or ';
-;;;     kukit.E += '"<NAMESPACE>-<ACTIONNAME>-<PARAMETER>" or ';
-;;;     kukit.E += '"evt-<EVENTNAME>-<PARAMETER>" or ';
-;;;     kukit.E += '"evt-<NAMESPACE>-<EVENTNAME>-<PARAMETER>".';
-;;;     this.emitError(kukit.E);
-;;; }
-    var name = splitkey[0];
-    if (name == 'evt') {
-        this.addEventDeclaration(key, splitkey, value);
-    } else if (name == 'action') {
-        this.addActionDeclaration(key, splitkey, value);
-    } else {
+        // <ACTIONNAME>-<KEY>: <VALUE>
+        // default-<KEY>: <VALUE>
+        // 
+        // value may be either txt or method parms, 
+        // and they get stored with the wrapper.
+        // 
+        // Check the syntax of the value at this point.
+        // This will also set the value providers on the value
+        // (from check).
+        //
+        // Figure out which registry to use.
+        var registry = ppRegistries[key];
+        if (typeof(registry) == 'undefined') {
+            // use default pproviders
+            registry = ppRegistries[''];
+        }
+        //
+        try {
+            // Check also sets the value provider on the value.
+            value.check(registry);
+        } catch(e) {
+;;;         kukit.E = 'Error in value : ' + e + '.';
+            this.emitError(kukit.E);
+        }
+        action.parms[key] = value;
+    };
+
+    this.addDeclaration = function(key, value) {
+        // p.s. value is here a KssXxParm. In most cases we check and unwrap it.
+        // 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 actionName;
-        var actionKey;
-        if (splitkey.length == 2) {
+        //
+        var splitkey = key.split('-');
+;;;     if (splitkey.length < 2 || splitkey.length > 4) {
+;;;         kukit.E = 'Wrong rule key : "' + key + '". ';
+;;;         kukit.E += 'KSS rule key must be "<ACTIONNAME>-<PARAMETER>" or ';
+;;;         kukit.E += '"<NAMESPACE>-<ACTIONNAME>-<PARAMETER>" or ';
+;;;         kukit.E += '"evt-<EVENTNAME>-<PARAMETER>" or ';
+;;;         kukit.E += '"evt-<NAMESPACE>-<EVENTNAME>-<PARAMETER>".';
+;;;         this.emitError(kukit.E);
+;;;     }
+        var name = splitkey[0];
+        if (name == 'evt') {
+            this.addEventDeclaration(key, splitkey, value);
+        } else if (name == 'action') {
+            this.addActionDeclaration(key, splitkey, value);
+        } else {
             // <ACTIONNAME>-<KEY>: <VALUE>
+            // <NAMESPACE>-<ACTIONNAME>-<KEY>: <VALUE>
             // <ACTIONNAME>-error: <VALUE>
+            // <NAMESPACE>-<ACTIONNAME>-error: <VALUE>
             // default-<KEY>: <VALUE>
             // default-error: <VALUE>
-            actionName =  splitkey[0];
-            actionKey = splitkey[1];
-        } else {
-            // <NAMESPACE>-<ACTIONNAME>-<KEY>: <VALUE>
-            // <NAMESPACE>-<ACTIONNAME>-error: <VALUE>
-            actionName = splitkey[0] + '-' + splitkey[1];
-            actionKey = splitkey[2];
-        }
-        var action = this.actions.getOrCreateAction(actionName);
-        if (actionKey == 'error') {
-            this.addActionError(action, key, value);
-        } else {
-            this.addActionParameter(action, actionKey, value);
+            var actionName;
+            var actionKey;
+            if (splitkey.length == 2) {
+                // <ACTIONNAME>-<KEY>: <VALUE>
+                // <ACTIONNAME>-error: <VALUE>
+                // default-<KEY>: <VALUE>
+                // default-error: <VALUE>
+                actionName =  splitkey[0];
+                actionKey = splitkey[1];
+            } else {
+                // <NAMESPACE>-<ACTIONNAME>-<KEY>: <VALUE>
+                // <NAMESPACE>-<ACTIONNAME>-error: <VALUE>
+                actionName = splitkey[0] + '-' + splitkey[1];
+                actionKey = splitkey[2];
+            }
+            var action = this.actions.getOrCreateAction(actionName);
+            if (actionKey == 'error') {
+                this.addActionError(action, key, value);
+            } else {
+                this.addActionParameter(action, actionKey, value);
+            }
         }
-    }
+    };
 };
+kssp.Block = kukit.tk.mkParserBis('block', {
+    ";": 'new kukit.kssp.semicolon(this.cursor)',
+    ":": '[new kukit.kssp.colon(this.cursor), new kukit.kssp.PropValue(this.cursor)]',
+    "}": 'this.emitAndReturn(new kukit.kssp.closeBrace(this.cursor))'
+    },
+    _Block
+    );
 
 /*
 * class PropValue
 */
-kssp.PropValue = kukit.tk.mkParser('propValue', {
+var _PropValue = function() {
+
+    this.process = function() {
+        // Parse all tokens (including first and last)
+        var context = {'nextTokenIndex': 0};
+        this.digestTxt(context, kukit.tk.Fraction, kukit.kssp.Comment);
+        this.txt = '';
+        var txt = context.txt;
+        if (this.notInTokens(context, kukit.kssp.String)) {
+            // The previous txt must be all whitespace.
+            if (txt) {
+;;;             kukit.E = 'Wrong value : unallowed characters [' + txt + ']';
+;;;             kukit.E += ' before a string.';
+                this.emitError(kukit.E);
+            }
+            // the next one must be a string.
+            this.expectToken(context, kukit.kssp.String);
+            this.produceTxt(context.token.txt);
+        } else if (this.notInTokens(context, 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 ';
+;;;             kukit.E += 'have spaces.';
+                this.emitError(kukit.E);
+            }
+            // the next one must be the rules
+            this.expectToken(context, kukit.kssp.MethodArgs);
+            this.value = new this.valueClass(txt, context.token.args);
+        } else {
+            // not a string or method: check if we allowed multiword.
+            if (! this.multiword_allowed && txt.indexOf(' ') != -1) {
+;;;             kukit.E = 'Wrong value : [' + txt + '] cannot have spaces.';
+                this.emitError(kukit.E);
+            }
+            this.produceTxt(txt);
+        }
+        // see what's after
+        if (context.nextTokenIndex < this.result.length) {
+            this.digestTxt(context, kukit.tk.Fraction, kukit.kssp.Comment);
+            // we have to be at the end and have no text after
+            if (context.nextTokenIndex < this.result.length || context.txt) {
+;;;             kukit.E = 'Wrong value : unallowed characters after ';
+;;;             kukit.E += 'the property.';
+                this.emitError(kukit.E);
+            }
+        }
+        this.result = [];
+    };
+    this.multiword_allowed = true;
+    this.valueClass = kukit.rd.KssMethodValue;
+    this.produceTxt = function(txt) {
+        // txt parms are returned embedded
+        this.value = new kukit.rd.KssTextValue(txt);
+    };
+};
+
+kssp.PropValue = kukit.tk.mkParserBis('propValue', {
     ";": 'this.emitAndReturn()',
     "}": 'this.emitAndReturn()',
     ")": 'this.emitAndReturn()',
@@ -379,66 +448,24 @@
     '"': 'new kukit.kssp.String2(this.cursor, kukit.kssp.dquote)',
     "\/\*": 'new kukit.kssp.Comment(this.cursor, kukit.kssp.openComment)',
     "(": 'new kukit.kssp.MethodArgs(this.cursor, kukit.kssp.openParent)'
-    });
-kssp.PropValue.prototype.process = function() {
-    // Parse all tokens (including first and last)
-    var context = {'nextTokenIndex': 0};
-    this.digestTxt(context, kukit.tk.Fraction, kukit.kssp.Comment);
-    this.txt = '';
-    var txt = context.txt;
-    if (this.notInTokens(context, kukit.kssp.String)) {
-        // The previous txt must be all whitespace.
-        if (txt) {
-;;;         kukit.E = 'Wrong value : unallowed characters [' + txt + ']';
-;;;         kukit.E += ' before a string.';
-            this.emitError(kukit.E);
-        }
-        // the next one must be a string.
-        this.expectToken(context, kukit.kssp.String);
-        this.produceTxt(context.token.txt);
-    } else if (this.notInTokens(context, 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 ';
-;;;         kukit.E += 'have spaces.';
-            this.emitError(kukit.E);
-        }
-        // the next one must be the rules
-        this.expectToken(context, kukit.kssp.MethodArgs);
-        this.value = new this.valueClass(txt, context.token.args);
-    } else {
-        // not a string or method: check if we allowed multiword.
-        if (! this.multiword_allowed && txt.indexOf(' ') != -1) {
-;;;         kukit.E = 'Wrong value : [' + txt + '] cannot have spaces.';
-            this.emitError(kukit.E);
-        }
-        this.produceTxt(txt);
-    }
-    // see what's after
-    if (context.nextTokenIndex < this.result.length) {
-        this.digestTxt(context, kukit.tk.Fraction, kukit.kssp.Comment);
-        // we have to be at the end and have no text after
-        if (context.nextTokenIndex < this.result.length || context.txt) {
-;;;         kukit.E = 'Wrong value : unallowed characters after ';
-;;;         kukit.E += 'the property.';
-            this.emitError(kukit.E);
-        }
-    }
-    this.result = [];
-};
-kssp.PropValue.prototype.multiword_allowed = true;
-kssp.PropValue.prototype.valueClass = kukit.rd.KssMethodValue;
-kssp.PropValue.prototype.produceTxt = function(txt) {
-    // txt parms are returned embedded
-    this.value = new kukit.rd.KssTextValue(txt);
-};
+    },
+    _PropValue
+    );
 
 /*
 * class PropValueInMethod
 *
 * PropValue in method cannot have method-style vars.
 */
-kssp.PropValueInMethod = kukit.tk.mkParser('propValue', {
+var _PropValueInMethod = function() {
+    this.multiword_allowed = false;
+    this.produceTxt = function(txt) {
+        // txt parms are returned unwrapped
+        this.txt = txt;
+    };
+};
+_PropValueInMethod.prototype = new _PropValue();
+kssp.PropValueInMethod = kukit.tk.mkParserBis('propValue', {
     ";": 'this.emitAndReturn()',
     "}": 'this.emitAndReturn()',
     ")": 'this.emitAndReturn()',
@@ -447,21 +474,73 @@
     "'": 'new kukit.kssp.String(this.cursor, kukit.kssp.quote)',
     '"': 'new kukit.kssp.String2(this.cursor, kukit.kssp.dquote)',
     "\/\*": 'new kukit.kssp.Comment(this.cursor, kukit.kssp.openComment)'
-    });
-kssp.PropValueInMethod.prototype.multiword_allowed = false;
-kssp.PropValueInMethod.prototype.process =
-    kssp.PropValue.prototype.process;
-kssp.PropValueInMethod.prototype.produceTxt = function(txt) {
-    // txt parms are returned unwrapped
-    this.txt = txt;
-};
+    },
+    _PropValueInMethod
+    );
 
 /*
 * class EventValue
 *
-* PropValue in pseudo must be single word with no spaces around.
 */
-kssp.EventValue = kukit.tk.mkParser('propValue', {
+var _EventValue = function() {
+    this.multiword_allowed = false;
+    this.process = function() {
+        // Parse all tokens (including first and last)
+        var context = {'nextTokenIndex': 0};
+        this.digestTxt(context, kukit.tk.Fraction, kukit.kssp.Comment);
+        this.txt = '';
+        var txt = context.txt;
+        if (this.notInTokens(context, kukit.kssp.String)) {
+            // The previous txt must be all whitespace.
+            if (txt) {
+;;;             kukit.E = 'Wrong value : unallowed characters [' + txt + ']';
+;;;             kukit.E += ' before a string.';
+                this.emitError(kukit.E);
+            }
+            // the next one must be a string.
+            this.expectToken(context, kukit.kssp.String);
+            this.produceTxt(context.token.txt);
+        } else if (this.notInTokens(context, kukit.kssp.openParent)) {
+            this.expectToken(context, kukit.kssp.openParent);
+            this.expectToken(context, kukit.kssp.PropValue);
+            this.value = new kukit.rd.KssEventValue(txt, context.token.value);
+            this.digestTxt(context, kukit.tk.Fraction, kukit.kssp.Comment);
+            // we have to be at the end and have no text after
+            if (context.txt) {
+;;;             kukit.E = 'Wrong event selector : [' + context.txt; 
+;;;             kukit.E += '] is not expected before the closing';
+;;;             kukit.E += ' parenthesis. :<EVENTNAME>(<ID>) can have';
+;;;             kukit.E += ' only one parameter.';
+                this.emitError(kukit.E);
+            }
+            // eat up everything before the closing parent
+            this.expectToken(context, kukit.kssp.closeParent);
+        } else {
+            // not a string or method: check if we allowed multiword.
+            if (! this.multiword_allowed && txt.indexOf(' ') != -1) {
+;;;             kukit.E = 'Wrong value : [' + txt + '] cannot have spaces.';
+                this.emitError(kukit.E);
+            }
+            this.produceTxt(txt);
+        }
+        // see what's after
+        if (context.nextTokenIndex < this.result.length) {
+            this.digestTxt(context, kukit.tk.Fraction, kukit.kssp.Comment);
+            // we have to be at the end and have no text after
+            if (context.nextTokenIndex < this.result.length || context.txt) {
+;;;             kukit.E = 'Excess characters after the property value';
+                this.emitError(kukit.E);
+            }
+        }
+        this.result = [];
+    };
+
+    this.produceTxt = function(txt) {
+        // txt parms are returned embedded
+        this.value = new kukit.rd.KssEventValue(txt, null);
+    };
+};
+kssp.EventValue = kukit.tk.mkParserBis('propValue', {
     "{": 'this.emitAndReturn()',
     " ": 'this.emitAndReturn()',
     "\t": 'this.emitAndReturn()',
@@ -471,63 +550,9 @@
     ":": 'this.emitAndReturn()',
     "(": '[new kukit.kssp.openParent(this.cursor), new kukit.kssp.PropValue(this.cursor)]',
     ")": 'this.emitAndReturn(new kukit.kssp.closeParent(this.cursor))'
-    });
-kssp.EventValue.prototype.multiword_allowed = false;
-kssp.EventValue.prototype.process = function() {
-    // Parse all tokens (including first and last)
-    var context = {'nextTokenIndex': 0};
-    this.digestTxt(context, kukit.tk.Fraction, kukit.kssp.Comment);
-    this.txt = '';
-    var txt = context.txt;
-    if (this.notInTokens(context, kukit.kssp.String)) {
-        // The previous txt must be all whitespace.
-        if (txt) {
-;;;         kukit.E = 'Wrong value : unallowed characters [' + txt + ']';
-;;;         kukit.E += ' before a string.';
-            this.emitError(kukit.E);
-        }
-        // the next one must be a string.
-        this.expectToken(context, kukit.kssp.String);
-        this.produceTxt(context.token.txt);
-    } else if (this.notInTokens(context, kukit.kssp.openParent)) {
-        this.expectToken(context, kukit.kssp.openParent);
-        this.expectToken(context, kukit.kssp.PropValue);
-        this.value = new kukit.rd.KssEventValue(txt, context.token.value);
-        this.digestTxt(context, kukit.tk.Fraction, kukit.kssp.Comment);
-        // we have to be at the end and have no text after
-        if (context.txt) {
-;;;         kukit.E = 'Wrong event selector : [' + context.txt; 
-;;;         kukit.E += '] is not expected before the closing';
-;;;         kukit.E += ' parenthesis. :<EVENTNAME>(<ID>) can have';
-;;;         kukit.E += ' only one parameter.';
-            this.emitError(kukit.E);
-        }
-        // eat up everything before the closing parent
-        this.expectToken(context, kukit.kssp.closeParent);
-    } else {
-        // not a string or method: check if we allowed multiword.
-        if (! this.multiword_allowed && txt.indexOf(' ') != -1) {
-;;;         kukit.E = 'Wrong value : [' + txt + '] cannot have spaces.';
-            this.emitError(kukit.E);
-        }
-        this.produceTxt(txt);
-    }
-    // see what's after
-    if (context.nextTokenIndex < this.result.length) {
-        this.digestTxt(context, kukit.tk.Fraction, kukit.kssp.Comment);
-        // we have to be at the end and have no text after
-        if (context.nextTokenIndex < this.result.length || context.txt) {
-;;;         kukit.E = 'Excess characters after the property value';
-            this.emitError(kukit.E);
-        }
-    }
-    this.result = [];
-};
-
-kssp.EventValue.prototype.produceTxt = function(txt) {
-    // txt parms are returned embedded
-    this.value = new kukit.rd.KssEventValue(txt, null);
-};
+    },
+    _EventValue
+    );
 
 /*
 * class String

Modified: kukit/kukit.js/branch/finish-closures/kukit/tokenizer.js
==============================================================================
--- kukit/kukit.js/branch/finish-closures/kukit/tokenizer.js	(original)
+++ kukit/kukit.js/branch/finish-closures/kukit/tokenizer.js	Sun Dec 16 23:42:27 2007
@@ -254,6 +254,36 @@
     return f;
 };
 
+tk.mkParserBis = function(symbol, table, _class) {
+    // Poor man's subclassing.
+    f = function(cursor, tokenClass, isTopLevelParser) {
+        this.table = table
+        this.cursor = cursor;
+        this.startpos = cursor.pos;
+        this.finished = false;
+        this.isTopLevelParser = isTopLevelParser;
+        this.result = [];
+        if (tokenClass) {
+            // Reentry with starting token propagated.
+            this.result.push(new tokenClass(this.cursor));
+        }
+        this.updateFinished();
+        while (!this.finished) {
+            this.nextStep();
+            this.updateFinished();
+        }
+        this.endpos = cursor.pos;
+        // post processing
+        this.process();
+        
+        //this.cursor = null;
+    };
+    _class.prototype = new tk._ParserBase();
+    f.prototype = new _class(); 
+    f.prototype.symbol = symbol;
+    return f;
+};
+
 /*
 * class Cursor
 */


More information about the Kukit-checkins mailing list