Author: gotcha
Date: Wed Dec 26 20:17:49 2007
New Revision: 50127

Modified:
   kukit/kukit.js/branch/finish-closures/kukit/kssparser.js
   kukit/kukit.js/branch/finish-closures/kukit/tokenizer.js
Log:
death to eval

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    Wed Dec 26 
20:17:49 2007
@@ -43,6 +43,45 @@
 
 /* Parsers */
 
+/* Helpers */
+
+var _emitAndReturn = function(parser) {
+    return parser.emitAndReturn();
+};
+
+var _mkEmitAndReturnToken = function(klass) {
+    return function(parser) {
+        var token = new klass(parser.cursor);
+        return parser.emitAndReturn(token);
+    };
+};
+
+var _mkReturnToken = function(klass) {
+    return function(parser) {
+        return new klass(parser.cursor);
+    };
+};
+
+var _returnComment = function(parser) {
+    return new kssp.Comment(parser.cursor, kssp.openComment)
+};
+
+var _returnString = function(parser) {
+    return new kssp.String(parser.cursor, kssp.quote)
+};
+
+var _returnString2 = function(parser) {
+    return new kssp.String2(parser.cursor, kssp.dquote)
+};
+
+var _returnMethodArgs = function(parser) {
+    return new kssp.MethodArgs(parser.cursor, kssp.openParent)
+};
+
+var _returnBackslashed = function(parser) {
+    return new kssp.Backslashed(parser.cursor, kssp.backslash)
+};
+
 /*
 * class Document 
 */
@@ -53,12 +92,12 @@
     // 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);
+        this.digestTxt(context, kukit.tk.Fraction, kssp.Comment);
         var key = context.txt;
         if (! key) {
             break;
         }
-        this.expectToken(context, kukit.kssp.Block);
+        this.expectToken(context, kssp.Block);
         var block = context.token;
         var rules = block.parseSelectors(key);
         this.addRules(rules);
@@ -76,8 +115,10 @@
 
 };
 kssp.Document = kukit.tk.mkParser('document', {
-    "\/\*": 'new kukit.kssp.Comment(this.cursor, kukit.kssp.openComment)',
-    "{": 'new kukit.kssp.Block(this.cursor, kukit.kssp.openBrace)'
+    "\/\*": _returnComment,
+    "{": function(parser) {
+             return new kssp.Block(parser.cursor, kssp.openBrace)
+             }
     },
     _Document
     );
@@ -95,7 +136,7 @@
 };
 kssp.Comment = kukit.tk.mkParser('comment', {
     // it's not 100% good, but will do
-    "\*\/": 'this.emitAndReturn(new kukit.kssp.closeComment(this.cursor))'
+    "\*\/": _mkEmitAndReturnToken(kssp.closeComment)
     },
     _Comment
     );
@@ -112,17 +153,17 @@
     // 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);
+        this.digestTxt(context, kukit.tk.Fraction, kssp.Comment);
         var key = context.txt;
         if (! key) {
             break;
         }
-        this.expectToken(context, kukit.kssp.colon);
-        this.expectToken(context, kukit.kssp.PropValue);
+        this.expectToken(context, kssp.colon);
+        this.expectToken(context, 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.expectToken(context, kssp.semicolon);
     }
     this.result = [];
     this.txt = '';
@@ -131,7 +172,7 @@
 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 parser = new kssp.KssSelectors(cursor, null, true);
     var results = [];
     var hasFullNames = false;
     for(var eventFullName in this.eventFullNames) {
@@ -378,9 +419,12 @@
 
 };
 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))'
+    ";": _mkReturnToken(kssp.semicolon),
+    ":": function(parser) {
+             return [new kssp.colon(parser.cursor), 
+                 new kssp.PropValue(parser.cursor)]
+             },
+    "}": _mkEmitAndReturnToken(kssp.closeBrace)
     },
     _Block
     );
@@ -393,10 +437,10 @@
 this.process = function() {
     // Parse all tokens (including first and last)
     var context = {'nextTokenIndex': 0};
-    this.digestTxt(context, kukit.tk.Fraction, kukit.kssp.Comment);
+    this.digestTxt(context, kukit.tk.Fraction, kssp.Comment);
     this.txt = '';
     var txt = context.txt;
-    if (this.notInTokens(context, kukit.kssp.String)) {
+    if (this.notInTokens(context, kssp.String)) {
         // The previous txt must be all whitespace.
         if (txt) {
 ;;;         kukit.E = 'Wrong value : unallowed characters [' + txt + ']';
@@ -404,9 +448,9 @@
             this.emitError(kukit.E);
         }
         // the next one must be a string.
-        this.expectToken(context, kukit.kssp.String);
+        this.expectToken(context, kssp.String);
         this.produceTxt(context.token.txt);
-    } else if (this.notInTokens(context, kukit.kssp.MethodArgs)) {
+    } else if (this.notInTokens(context, 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 ';
@@ -414,7 +458,7 @@
             this.emitError(kukit.E);
         }
         // the next one must be the rules
-        this.expectToken(context, kukit.kssp.MethodArgs);
+        this.expectToken(context, kssp.MethodArgs);
         this.value = new this.valueClass(txt, context.token.args);
     } else {
         // not a string or method: check if we allowed multiword.
@@ -426,7 +470,7 @@
     }
     // see what's after
     if (context.nextTokenIndex < this.result.length) {
-        this.digestTxt(context, kukit.tk.Fraction, kukit.kssp.Comment);
+        this.digestTxt(context, kukit.tk.Fraction, 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 ';
@@ -449,14 +493,14 @@
 this.initialize.apply(this, arguments);
 };
 kssp.PropValue = kukit.tk.mkParser('propValue', {
-    ";": 'this.emitAndReturn()',
-    "}": 'this.emitAndReturn()',
-    ")": 'this.emitAndReturn()',
-    ",": 'this.emitAndReturn()',
-    "'": '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)',
-    "(": 'new kukit.kssp.MethodArgs(this.cursor, kukit.kssp.openParent)'
+    ";": _emitAndReturn,
+    "}": _emitAndReturn,
+    ")": _emitAndReturn,
+    ",": _emitAndReturn,
+    "'": _returnString,
+    '"': _returnString2,
+    "\/\*": _returnComment,
+    "(": _returnMethodArgs
     },
     _PropValue
     );
@@ -480,14 +524,14 @@
 };
 // this assignment needs to remain after initialization of _PropValue
 kssp.PropValueInMethod = kukit.tk.mkParser('propValue', {
-    ";": 'this.emitAndReturn()',
-    "}": 'this.emitAndReturn()',
-    ")": 'this.emitAndReturn()',
-    "]": 'this.emitAndReturn()',
-    ",": 'this.emitAndReturn()',
-    "'": '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)'
+    ";": _emitAndReturn,
+    "}": _emitAndReturn,
+    ")": _emitAndReturn,
+    "]": _emitAndReturn,
+    ",": _emitAndReturn,
+    "'": _returnString,
+    '"': _returnString2,
+    "\/\*": _returnComment
     },
     _PropValueInMethod
     );
@@ -506,10 +550,10 @@
 this.process = function() {
     // Parse all tokens (including first and last)
     var context = {'nextTokenIndex': 0};
-    this.digestTxt(context, kukit.tk.Fraction, kukit.kssp.Comment);
+    this.digestTxt(context, kukit.tk.Fraction, kssp.Comment);
     this.txt = '';
     var txt = context.txt;
-    if (this.notInTokens(context, kukit.kssp.String)) {
+    if (this.notInTokens(context, kssp.String)) {
         // The previous txt must be all whitespace.
         if (txt) {
 ;;;         kukit.E = 'Wrong value : unallowed characters [' + txt + ']';
@@ -517,13 +561,13 @@
             this.emitError(kukit.E);
         }
         // the next one must be a string.
-        this.expectToken(context, kukit.kssp.String);
+        this.expectToken(context, 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);
+    } else if (this.notInTokens(context, kssp.openParent)) {
+        this.expectToken(context, kssp.openParent);
+        this.expectToken(context, kssp.PropValue);
         this.value = new kukit.rd.KssEventValue(txt, context.token.value);
-        this.digestTxt(context, kukit.tk.Fraction, kukit.kssp.Comment);
+        this.digestTxt(context, kukit.tk.Fraction, kssp.Comment);
         // we have to be at the end and have no text after
         if (context.txt) {
 ;;;         kukit.E = 'Wrong event selector : [' + context.txt; 
@@ -533,7 +577,7 @@
             this.emitError(kukit.E);
         }
         // eat up everything before the closing parent
-        this.expectToken(context, kukit.kssp.closeParent);
+        this.expectToken(context, kssp.closeParent);
     } else {
         // not a string or method: check if we allowed multiword.
         if (! this.multiword_allowed && txt.indexOf(' ') != -1) {
@@ -544,7 +588,7 @@
     }
     // see what's after
     if (context.nextTokenIndex < this.result.length) {
-        this.digestTxt(context, kukit.tk.Fraction, kukit.kssp.Comment);
+        this.digestTxt(context, kukit.tk.Fraction, 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';
@@ -561,15 +605,18 @@
 this.initialize.apply(this, arguments);
 };
 kssp.EventValue = kukit.tk.mkParser('propValue', {
-    "{": 'this.emitAndReturn()',
-    " ": 'this.emitAndReturn()',
-    "\t": 'this.emitAndReturn()',
-    "\n": 'this.emitAndReturn()',
-    "\r": 'this.emitAndReturn()',
-    "\/\*": 'this.emitAndReturn()',
-    ":": 'this.emitAndReturn()',
-    "(": '[new kukit.kssp.openParent(this.cursor), new 
kukit.kssp.PropValue(this.cursor)]',
-    ")": 'this.emitAndReturn(new kukit.kssp.closeParent(this.cursor))'
+    "{": _emitAndReturn,
+    " ": _emitAndReturn,
+    "\t": _emitAndReturn,
+    "\n": _emitAndReturn,
+    "\r": _emitAndReturn,
+    "\/\*": _emitAndReturn,
+    ":": _emitAndReturn,
+    "(": function(parser) {
+             return [new kssp.openParent(parser.cursor),
+                 new kssp.PropValue(parser.cursor)]
+             },
+    ")": _mkEmitAndReturnToken(kssp.closeParent)
     },
     _EventValue
     );
@@ -589,8 +636,8 @@
 
 };
 kssp.String = kukit.tk.mkParser('string', {
-    "'": 'this.emitAndReturn(new kukit.kssp.quote(this.cursor))',
-    '\x5c': 'new kukit.kssp.Backslashed(this.cursor, kukit.kssp.backslash)'
+    "'": _mkEmitAndReturnToken(kssp.quote),
+    '\x5c': _returnBackslashed
     },
     _String
     );
@@ -599,8 +646,8 @@
 * class String2
 */
 kssp.String2 = kukit.tk.mkParser('string', {
-    '"': 'this.emitAndReturn(new kukit.kssp.dquote(this.cursor))',
-    '\x5c': 'new kukit.kssp.Backslashed(this.cursor, kukit.kssp.backslash)'
+    '"': _mkEmitAndReturnToken(kssp.dquote),
+    '\x5c': _returnBackslashed
     },
     _String
     );
@@ -620,8 +667,8 @@
 
 };
 kssp.StringInSelector = kukit.tk.mkParser('string', {
-    "'": 'this.emitAndReturn(new kukit.kssp.quote(this.cursor))',
-    '\x5c': 'new kukit.kssp.Backslashed(this.cursor, kukit.kssp.backslash)'
+    "'": _mkEmitAndReturnToken(kssp.quote),
+    '\x5c': _returnBackslashed
     },
     _StringInSelector
     );
@@ -630,8 +677,8 @@
 * class String2InSelector
 */
 kssp.String2InSelector = kukit.tk.mkParser('string', {
-    '"': 'this.emitAndReturn(new kukit.kssp.dquote(this.cursor))',
-    '\x5c': 'new kukit.kssp.Backslashed(this.cursor, kukit.kssp.backslash)'
+    '"': _mkEmitAndReturnToken(kssp.dquote),
+    '\x5c': _returnBackslashed
     },
     _StringInSelector
     );
@@ -677,13 +724,13 @@
     // 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);
+        this.digestTxt(context, kukit.tk.Fraction, kssp.Comment);
         var value = context.txt;
         if (! value) {
             // allow to bail out after widow ,
             if (context.nextTokenIndex == this.result.length-1) break;
             // here be a string then.
-            this.expectToken(context, kukit.kssp.String);
+            this.expectToken(context, kssp.String);
             value = context.token.txt;
         } else {
             // Just a value, must be one word then.
@@ -697,8 +744,8 @@
         var valueClass;
         var args;
         var providedValue;
-        if (this.notInTokens(context, kukit.kssp.MethodArgs)){
-            this.expectToken(context, kukit.kssp.MethodArgs);
+        if (this.notInTokens(context, kssp.MethodArgs)){
+            this.expectToken(context, kssp.MethodArgs);
              valueClass = kukit.rd.KssMethodValue;
              args = context.token.args;
              providedValue = new valueClass(value, args);
@@ -710,7 +757,7 @@
         }
         this.args.push(providedValue);
         if (context.nextTokenIndex == this.result.length-1) break;
-        this.expectToken(context, kukit.kssp.comma);
+        this.expectToken(context, kssp.comma);
     }
     this.result = [];
     this.txt = '';
@@ -718,17 +765,16 @@
 
 };
 kssp.MethodArgs = kukit.tk.mkParser('methodargs', {
-    "'": 'new kukit.kssp.String(this.cursor, kukit.kssp.quote)',
-    '"': 'new kukit.kssp.String2(this.cursor, kukit.kssp.dquote)',
-    ",": 'new kukit.kssp.comma(this.cursor)',
-    ")": 'this.emitAndReturn(new kukit.kssp.closeParent(this.cursor))',
-    "(": 'new kukit.kssp.MethodArgs(this.cursor, kukit.kssp.openParent)',
-    "\/\*": 'new kukit.kssp.Comment(this.cursor, kukit.kssp.openComment)'
+    "'": _returnString,
+    '"': _returnString2,
+    ",": _mkReturnToken(kssp.comma),
+    ")": _mkEmitAndReturnToken(kssp.closeParent),
+    "(": _returnMethodArgs,
+    "\/\*": _returnComment
     },
     _MethodArgs
     );
 
-
 /*
 * class KssSelectors
 *
@@ -745,13 +791,13 @@
     // 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,
-            kukit.kssp.String, kukit.kssp.String2);
+        this.digestTxt(context, kukit.tk.Fraction, kssp.Comment,
+            kssp.String, kssp.String2);
         var cursor = new kukit.tk.Cursor(context.txt + ' ')
-        var parser = new kukit.kssp.KssSelector(cursor, null, true);
+        var parser = new kssp.KssSelector(cursor, null, true);
         this.selectors.push(parser.kssSelector);
         if (context.nextTokenIndex == this.result.length) break;
-        this.expectToken(context, kukit.kssp.comma);
+        this.expectToken(context, kssp.comma);
         if (context.nextTokenIndex == this.result.length) {
 ;;;        kukit.E = 'Wrong event selector : trailing comma';
            this.emitError(kukit.E); 
@@ -763,11 +809,15 @@
 
 };
 kssp.KssSelectors = kukit.tk.mkParser('kssselectors', {
-    "'": 'new kukit.kssp.StringInSelector(this.cursor, kukit.kssp.quote)',
-    '"': 'new kukit.kssp.String2InSelector(this.cursor, kukit.kssp.dquote)',
-    ",": 'new kukit.kssp.comma(this.cursor)',
-    "{": 'this.emitAndReturn()',
-    "\/\*": 'new kukit.kssp.Comment(this.cursor, kukit.kssp.openComment)'
+    "'": function(parser) {
+             return new kssp.StringInSelector(parser.cursor, kssp.quote)
+             },
+    '"': function(parser) {
+             return new kssp.String2InSelector(parser.cursor, kssp.dquote)
+             },
+    ",": _mkReturnToken(kssp.comma),
+    "{": _emitAndReturn,
+    "\/\*": _returnComment
     },
     _KssSelectors 
     );
@@ -806,7 +856,7 @@
                     this.emitError(kukit.E);
                 }
             } break;
-            case kukit.kssp.Comment.prototype.symbol: {
+            case kssp.Comment.prototype.symbol: {
                 tokenIndex -= 1;
             } break;
             default: {
@@ -818,9 +868,9 @@
     tokenIndex -= 2;
     if (tokenIndex < 0
          || (this.result[tokenIndex+2].symbol !=
-                kukit.kssp.EventValue.prototype.symbol)
+                kssp.EventValue.prototype.symbol)
          || (this.result[tokenIndex+1].symbol != 
-                kukit.kssp.colon.prototype.symbol)
+                kssp.colon.prototype.symbol)
          || (this.result[tokenIndex].symbol !=
                 kukit.tk.Fraction.prototype.symbol)) {
 ;;;     kukit.E = 'Wrong event selector : missing event qualifier ';
@@ -899,10 +949,12 @@
 
 };
 kssp.KssSelector = kukit.tk.mkParser('kssselector', {
-    ":": '[new kukit.kssp.colon(this.cursor), new ' + 
-        'kukit.kssp.EventValue(this.cursor)]',
-    "{": 'this.emitAndReturn()',
-    "\/\*": 'new kukit.kssp.Comment(this.cursor, kukit.kssp.openComment)'
+    ":": function(parser) {
+             return [new kssp.colon(parser.cursor),
+                     new kssp.EventValue(parser.cursor)]
+             },
+    "{": _emitAndReturn,
+    "\/\*": _returnComment
     },
     _KssSelector 
     );
@@ -933,7 +985,7 @@
 ;;; try {
         //Build a parser and parse the text into it
         var cursor = new kukit.tk.Cursor(this.txt);
-        var parser = new kukit.kssp.Document(cursor, null, true);
+        var parser = new kssp.Document(cursor, null, true);
         // Store event rules in the common list
         for (var i=0; i<parser.eventRules.length; i++) {
             var rule = parser.eventRules[i];

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    Wed Dec 26 
20:17:49 2007
@@ -82,7 +82,7 @@
     if (best_symbol) {
         // found a symbol, handle that
         // make the token and push it
-        var tokens = eval(table[best_symbol]);
+        var tokens = table[best_symbol](this);
         if (typeof(tokens) != 'undefined') {
             if (typeof(tokens.length) == 'undefined') {
                 tokens = [tokens];
_______________________________________________
Kukit-checkins mailing list
[email protected]
http://codespeak.net/mailman/listinfo/kukit-checkins

Reply via email to