Author: reebalazs
Date: Tue Dec 25 12:58:35 2007
New Revision: 50076
Modified:
kukit/kukit.js/branch/ree-service-layer-and-refactoring/ (props changed)
kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/errors.js
kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/eventreg.js
kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/kssparser.js
kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/resourcedata.js
kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/tokenizer.js
kukit/kukit.js/branch/ree-service-layer-and-refactoring/tests/test_kssparser.js
kukit/kukit.js/branch/ree-service-layer-and-refactoring/tests/test_tokenizer.js
Log:
Continue with the events registry.
- meanwhile, errors slightly fixed and errors can check for parsing errors
more consistently.
Also improve kssSelector: it holds the interface itself, so further
operations should be based on that registry.
Modified:
kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/errors.js
==============================================================================
--- kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/errors.js
(original)
+++ kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/errors.js
Tue Dec 25 12:58:35 2007
@@ -62,21 +62,26 @@
;;; kw = {};
;;; }
this.kw = kw;
-;;; this.message = name + ': ' + message;
+;;; this.message = message;
+;;; this.fullMessage = name + ': ' + message;
;;; var addMessage = true;
- if (!e) {
-;;; e = new Error(message);
+ if (! e) {
+;;; e = new Error(this.fullMessage);
;;; addMessage = false;
;;; } else if (typeof(e) == "string") {
-;;; kukit.E = 'Do not raise string exceptions, as we cannot ';
+;;; kukit.E = 'Failed to preserve traceback information for error.'
+;;; kukit.E += 'Do not raise string exceptions, as we cannot ';
;;; kukit.E += 'annotate them properly. Use: throw new Error(msg);';
- e = new Error(kukit.E);
+;;; kukit.logWarning(kukit.E);
+ // We bundle the string-error into a real error, consequently,
+ // the original traceback will be lost.
+ e = new Error(e);
}
;;; this.previous_info = e.info;
e.name = name;
e.info = this;
;;; if (addMessage) {
-;;; var fullMessage = message + ' [' + e.message + ']';
+;;; var fullMessage = this.fullMessage + ' [' + e.message + ']';
;;; // for FF, and Safari:
;;; e.message = fullMessage;
;;; // for IE, message is ignored, description is used.
@@ -143,7 +148,9 @@
;;; };
-;;; err.parsingError = function(message, cursor){
+// this is raised by the parser in case of errors
+// it contains row/column information
+;;; err.parsingError = function(message, cursor, err){
;;; var kw = {}
;;; if (cursor) {
;;; kw.errpos = cursor.pos;
@@ -155,11 +162,20 @@
;;; kw.errrow = null;
;;; kw.errcol = null;
;;; }
-;;; return setErrorInfo(null, 'ParsingError', message, kw);
+;;; return setErrorInfo(err, 'ParsingError', message, kw);
;;; };
-/* Exceptions that re-throw (annotate) an already caught error */
+/*
+ * Exceptions that re-throw (annotate) an already thrown error
+ *
+ * These have purpose of adding some more generic explanation to the
+ * error, as well as adding more information.
+ * They only should get active in development mode.
+ *
+ * e.g. a ParsingError will become, after re-throwing:
+ * "Error parsing Kss at http://blah [ParsingError: ...]"
+ */
;;; err.commandExecutionError = function(e, command){
;;; var message = 'Command [' + command.name + '] failed';
@@ -177,11 +193,8 @@
;;; };
-;;; err.undefinedEventError = function(e, message){
-;;; return setErrorInfo(e, 'UndefinedEventError', message);
-;;; };
-
-
+;;; // this error protects and annotates all errors that
+;;; // happen during KssRuleProcessor.parse.
;;; err.kssParsingError = function(e, url){
;;; var kw = {url: url}
;;; var message = 'Error parsing KSS at ' + url;
@@ -194,5 +207,14 @@
;;; return setErrorInfo(e, 'EventSetupError', message);
;;; };
+
+// any error that happens because the required information
+// cannot be found in the plugin
+err.pluginRegistryError = function(err, message) {
+ return setErrorInfo(null, 'PluginRegistryError', message);
+};
+
+
+
}(); /// MODULE END
Modified:
kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/eventreg.js
==============================================================================
--- kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/eventreg.js
(original)
+++ kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/eventreg.js
Tue Dec 25 12:58:35 2007
@@ -21,8 +21,6 @@
var er = this;
-var _eventClassCounter = 0;
-
/*
*
* class _EventRegistry
@@ -365,19 +363,26 @@
method.call(this, name, oper);
};
+var _eventClassCounter = 0;
+
this.decorateEventBinderClass = function(cls) {
// See if we are set up already?
- if (cls.__decorated_for_kss__) {
+ var p = cls.prototype;
+ if (p.__decorated_for_kss__) {
return;
}
- cls.prototype.__continueEvent__ = _EventBinder__continueEvent__;
- cls.prototype.__continueEvent_allNodes__ =
+ // Put inherited methods on it
+ p.__continueEvent__ = _EventBinder__continueEvent__;
+ p.__continueEvent_allNodes__ =
_EventBinder__continueEvent_allNodes__;
- cls.prototype._EventBinder_triggerEvent = _EventBinder_triggerEvent;
- cls.prototype._EventBinder_callMethod = _EventBinder_callMethod;
- cls.prototype.__makeFuncToBind__ = _EventBinder_makeFuncToBind;
+ p._EventBinder_triggerEvent = _EventBinder_triggerEvent;
+ p._EventBinder_callMethod = _EventBinder_callMethod;
+ p.__makeFuncToBind__ = _EventBinder_makeFuncToBind;
+ // Generate a unique class name
+ p.__className__ = '' + _eventClassCounter;
+ _eventClassCounter ++;
// mark decorated
- cls.prototype.__decorated_for_kss__ = true;
+ p.__decorated_for_kss__ = true;
};
/* Event instance registry
@@ -393,9 +398,9 @@
};
er.BinderInfoRegistry.prototype.getOrCreateBinderInfo =
- function (kssSelector) {
+ function (kssSelector, node) {
// We use the key as the selector's merge id.
- var key = kssSelector.thisMergeId();
+ var key = kssSelector.getMergeId();
// Get or create the event.
var binderInfo = this.info[key];
if (typeof(binderInfo) == 'undefined') {
@@ -407,13 +412,11 @@
//
// The creation of binder instances happens from here.
//
-
- // XXX XXX
- var binderClass = kukit.eventsGlobalRegistry.getBinderClass(className);
+ var binderClass = kssSelector.getBindIteration().binderClass;
// Create the binder instance and the binder info
var binder = new binderClass();
- binderInfo = this.info[id] = new _BinderInfo(binder);
+ binderInfo = this.info[key] = new _BinderInfo(binder);
// store the bound rules
//binder.__bound_rules__ = [];
@@ -806,11 +809,4 @@
}
};
-er.makeMergeId = function(id, name) {
- // name cannot contain a @
- // id can be any string
- // so the merge id will be unique
- return name + '@' + id;
-};
-
}(); /// MODULE END
Modified:
kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/kssparser.js
==============================================================================
--- kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/kssparser.js
(original)
+++ kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/kssparser.js
Tue Dec 25 12:58:35 2007
@@ -807,14 +807,20 @@
name = splitname[1];
namespace = splitname[0];
}
+ // XXX The interfaces for the selector can be taken from a given interface
+ // registry. We use kukit.interfaces now which will make it operate on
+ // the global registry.
+ var interfaces = kukit.interfaces._interfaces;
// Protect the error for better logging
;;; try {
this.kssSelector = new kukit.rd.KssSelector(isEvent, css, origName,
- id, ppid);
+ id, ppid, interfaces);
;;; } catch(e) {
-;;; if (e.name == 'KssSelectorError') {
+;;; if (e.name == 'KssSelectorError' || e.name == 'PluginRegistryError') {
;;; // Log the message
-;;; this.emitError(e.toString());
+;;; // This will add line and column information to these errors.
+;;; kukit.E = 'Error during parsing KSS';
+;;; this.emitWrappedError(e, kukit.E);
;;; } else {
;;; throw e;
;;; }
Modified:
kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/resourcedata.js
==============================================================================
---
kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/resourcedata.js
(original)
+++
kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/resourcedata.js
Tue Dec 25 12:58:35 2007
@@ -24,7 +24,7 @@
/*
* class KssSelector
*/
-kukit.rd.KssSelector = function(isEvent, css, name, id, ppid) {
+kukit.rd.KssSelector = function(isEvent, css, name, id, ppid, interfaces) {
this.isEventSelector = isEvent;
this.isMethodSelector = ! isEvent;
// XXX GC row and column are wrong...
@@ -53,32 +53,34 @@
;;; }
this.css = css;
this.name = name;
- this.className = null;
this.id = id;
this.ppid = ppid;
- this.prepareId();
+ this.mergeId = null;
+ this.bindIteration = null;
// finish up the KSS on it
// XXX We should not have this here, because this disables testing the
parser
// standalone, without a plugin registry. Original behaviour
// should be reverted instead.
- this.checkRegistry();
+ //
+ // Perform checking based on the registry
+ this.checkRegistry(interfaces);
};
-kukit.rd.KssSelector.prototype.checkRegistry = function() {
+kukit.rd.KssSelector.prototype.checkRegistry = function(interfaces) {
// Sets up id and class on the selector, based on registration info
- // XXX GC instead of relying on exceptions, test if key exists
- try {
- kukit.eventsGlobalRegistry.get(
- null, this.name);
- } catch(e) {
- throw kukit.err.parsingError(e.message);
- }
-};
-
-kukit.rd.KssSelector.prototype.prepareId = function() {
+ // This will throw errors if the event is not in the registry.
+ //
+ // It will also bind the selector to operate on this registry
+ // ie. lookups are used from there.
+ //
+ // Store theinterfaces.
+ this.interfaces = interfaces;
// We prepare the id a bit. If there is no ppid specified,
// we can already produce the mergeId here.
+ // This is called from init.
if (this.ppid == null) {
+ // We have no value provider. All we have is a static string,
+ // or nothing which means a singleton binder instance (id = '').
if (this.id == null) {
// singleton for class
// singleton will have an id ''
@@ -86,13 +88,42 @@
}
// Also set the merge id. The rules with the same merge
// id should be merged on the same node.
- this.mergeId = kukit.er.makeMergeId(this.id, this.name);
+ // Statically setting it here means we never have to look
+ // at it depending on nodes.
+ // This step will access the interfaces already
+ // by calling getBindIteration.
+ this.mergeId = this.getMergeId();
+ } else {
+ // We have a value provider for the id. We cannot set the
+ // merge id for this selector, but we can make sure the bind
+ // iteration info is fetched and cached. It will also
+ // signal error when the event does not take of any binding
+ // iteration.
+ this.getBindIteration();
}
+ //
+ // Now we check the plugin part of the registry: this may not be
+ // necessary but this way we reject an event which has the binder
+ // set up, but has no actual event information.
+;;; // We wrap all errors as pluginRegistryError.
+;;; try {
+ // XXX TODO cicrumvent the get
+ kukit.eventsGlobalRegistry.get(
+ null, this.name);
+;;; } catch(e) {
+;;; if (! e.name != 'PluginRegistryError') {
+;;; kukit.E = 'undefined event [' + this.name + '].';
+;;; throw kukit.err.pluginRegistryError(e, kukit.E);
+;;; }
+;;; }
+};
+
+kukit.rd.KssSelector.prototype.prepareId = function() {
};
kukit.rd.KssSelector.prototype.getId = function(node) {
// Gives the id depending on a node.
- if (this.id) {
+ if (this.ppid == null) {
// Statically set.
return this.id;
} else {
@@ -110,15 +141,41 @@
}
};
+kukit.rd.KssSelector.prototype.getBindIteration = function() {
+ // Returns the bind iteration set up for this kss selector. This
+ // depends on the event name only, but it needs access to the
+ // registry, so we cache this result.
+ if (! this.bindIteration) {
+ // Look up the binder class from the registry.
+ var events = this.interfaces.get('binditerations',
kukit.interfaces.BindIterationDescriptor);
+ var entry = events.getMethodDescriptor(this.name);
+ if (! entry.config) {
+;;; kukit.E = 'undefined or unbindable event (no iteration found) [' +
this.name + '].';
+ throw kukit.err.pluginRegistryError(null, kukit.E);
+ }
+ // cache the binder class
+ this.bindIteration = entry.config;
+ }
+ return this.bindIteration;
+};
+
kukit.rd.KssSelector.prototype.getMergeId = function(node) {
// Gives the merge id depending on a node.
+ // In case the mergeId is statically set, it dies not
+ // depend on the node.
if (this.mergeId) {
// Statically set.
return this.mergeId;
} else {
- // Evaluate it.
+ // Evaluate the id depending on the node.
var id = this.getId(node);
- return kukit.er.makeMergeId(id, this.name);
+ // Get the binder class name
+ var className =
this.getBindIteration().binderClass.prototype.__className__;
+ // finally compile the actual id:
+ // name cannot contain a @
+ // id can be any string
+ // so the merge id will be unique
+ return className + '@' + name + '@' + id;
}
};
@@ -295,14 +352,6 @@
}
};
-kukit.rd.EventRule.prototype.getBinderInfo = function(node) {
- // Figure out what will be the "state id" for the kss event rule.
- var id = this.kssSelector.getId(node);
- // Gets the event instance for the rule.
- return kukit.engine.binderInfoRegistry.getOrCreateBinderInfo(
- this.kssSelector);
-};
-
/*
* bind(node) : calls binder hook on event instance.
* These hooks are tried in order, if succeeds it must return true:
@@ -318,9 +367,11 @@
this.store(node);
// Creation of the binding oper
var oper = new kukit.op.Oper();
- var binderInfo = this.getBinderInfo(node);
+ var binderInfo = kukit.engine.binderInfoRegistry.getOrCreateBinderInfo(
+ this.kssSelector, node);
oper.node = node;
oper.eventRule = this;
+ // Gets the event instance for the rule.
oper.binder = binderInfo.binder;
oper.parms = this.parms;
// mark on the instance as bound
@@ -794,6 +845,7 @@
;;; }
// Merge into the corresponding category
// mergeId must be set on kss selector already.
+ // XXX we pass no node to getMergedId
eventRule.mergeIntoDict(dict, eventRule.kssSelector.getMergeId());
};
Modified:
kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/tokenizer.js
==============================================================================
--- kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/tokenizer.js
(original)
+++ kukit/kukit.js/branch/ree-service-layer-and-refactoring/kukit/tokenizer.js
Tue Dec 25 12:58:35 2007
@@ -29,11 +29,16 @@
kukit.tk._TokenBase.prototype.emitError = function(msg) {
// Use the start position of the token for the error report.
-;;; var marker = this.cursor.makeMarker(this.startpos);
-;;; throw kukit.err.parsingError(msg, marker);
+;;; this.emitWrappedError(null, msg);
throw new Error(kukit.E);
};
+;;; kukit.tk._TokenBase.prototype.emitWrappedError = function(e, msg) {
+;;; // Use the start position of the token for the error report.
+;;; var marker = this.cursor.makeMarker(this.startpos);
+;;; throw kukit.err.parsingError(msg, marker, e);
+;;; };
+
kukit.tk._TokenBase.prototype.updateFinished = function() {
if (! this.finished && this.cursor.text.length == this.cursor.pos) {
if (this.isTopLevelParser) {
Modified:
kukit/kukit.js/branch/ree-service-layer-and-refactoring/tests/test_kssparser.js
==============================================================================
---
kukit/kukit.js/branch/ree-service-layer-and-refactoring/tests/test_kssparser.js
(original)
+++
kukit/kukit.js/branch/ree-service-layer-and-refactoring/tests/test_kssparser.js
Tue Dec 25 12:58:35 2007
@@ -143,7 +143,7 @@
txt= " /* comments; */ apples and /* more comments and*/ oranges ;";
cursor = new kukit.tk.Cursor(txt);
this.assertParsingError(kukit.kssp.PropValueInMethod, cursor, null,
true,
- //'Wrong value : [/* comments; */ apples and /* more comments
and*/ oranges ;] cannot have spaces.', 62);
+ //'Wrong value : [/* comments; */ apples and /* more comments
and*/ oranges ;].', 62);
'Wrong value : [apples and oranges] cannot have spaces.', 62);
// in string, multiword ok even in method
@@ -158,7 +158,7 @@
txt= "a'b c'";
cursor = new kukit.tk.Cursor(txt);
this.assertParsingError(kukit.kssp.PropValueInMethod, cursor, null,
true,
- 'Wrong value : unallowed characters [a] before a string', 6);
+ 'Wrong value : unallowed characters [a] before a string.', 6);
// Not ok
txt= "'a''b c'";
@@ -235,12 +235,12 @@
txt= " 'formVar'(x, y)";
cursor = new kukit.tk.Cursor(txt);
this.assertParsingError(kukit.kssp.PropValue, cursor, null, true,
- 'Wrong value : unallowed characters after the property', 16);
+ 'Wrong value : unallowed characters after the property.', 16);
txt= "formVar(x, y) xxx";
cursor = new kukit.tk.Cursor(txt);
this.assertParsingError(kukit.kssp.PropValue, cursor, null, true,
- 'Wrong value : unallowed characters after the property', 17);
+ 'Wrong value : unallowed characters after the property.', 17);
};
this.testEventValueSimple = function() {
@@ -360,7 +360,7 @@
txt= "(a, b c )";
cursor = new kukit.tk.Cursor(txt);
this.assertParsingError(kukit.kssp.MethodArgs, cursor,
kukit.kssp.openParent, true,
- 'Wrong method argument [b c] : value cannot have spaces', 9);
+ 'Wrong method argument [b c] : value cannot have spaces (if
needed, quote it as a string).', 9);
txt= "(a, b 'x' )";
cursor = new kukit.tk.Cursor(txt);
@@ -841,7 +841,7 @@
var txt= "a:dnd-drag-toomuch(hello)";
var cursor = new kukit.tk.Cursor(txt);
this.assertParsingError(kukit.kssp.KssSelector, cursor, null, true,
- 'Wrong event selector [dnd-drag-toomuch] : qualifier should be
:<EVENTNAME> or :<NAMESPACE>'
+ 'Wrong event selector [dnd-drag-toomuch] : qualifier should be
:<EVENTNAME> or :<NAMESPACE>-<EVENTNAME>.'
, 25);
// maybe in std css space is not allowed in the parents,
@@ -1060,48 +1060,48 @@
txt= " document:clack ";
cursor = new kukit.tk.Cursor(txt);
this.assertParsingError(kukit.kssp.KssSelector, cursor, null, true,
- 'Error : undefined event [clack].');
+ 'undefined or unbindable event (no iteration found) [clack].');
txt= " div#x:clack(hello) ";
cursor = new kukit.tk.Cursor(txt);
this.assertParsingError(kukit.kssp.KssSelector, cursor, null, true,
- 'Error : undefined event [clack].');
+ 'undefined or unbindable event (no iteration found) [clack].');
txt= " document:clack(hello) ";
cursor = new kukit.tk.Cursor(txt);
this.assertParsingError(kukit.kssp.KssSelector, cursor, null, true,
- 'Error : undefined event [clack].');
+ 'undefined or unbindable event (no iteration found) [clack].');
}
this.testKssSelectorWithRightEventAndMissingNamespace = function() {
txt= " document:drag ";
cursor = new kukit.tk.Cursor(txt);
this.assertParsingError(kukit.kssp.KssSelector, cursor, null, true,
- 'Error : undefined event [drag].');
+ 'undefined or unbindable event (no iteration found) [drag].');
txt= " document:drag(hello) ";
cursor = new kukit.tk.Cursor(txt);
this.assertParsingError(kukit.kssp.KssSelector, cursor, null, true,
- 'Error : undefined event [drag].');
+ 'undefined or unbindable event (no iteration found) [drag].');
}
this.testKssSelectorWithUndefinedNamespaceWhenNamespace = function() {
txt= " document:dad-drag ";
cursor = new kukit.tk.Cursor(txt);
this.assertParsingError(kukit.kssp.KssSelector, cursor, null, true,
- 'Error : undefined event [dad-drag].');
+ 'undefined or unbindable event (no iteration found) [dad-drag].');
txt= " document:dad-drag(hello) ";
cursor = new kukit.tk.Cursor(txt);
this.assertParsingError(kukit.kssp.KssSelector, cursor, null, true,
- 'Error : undefined event [dad-drag].');
+ 'undefined or unbindable event (no iteration found) [dad-drag].');
}
this.testKssSelectorWithUndefinedEventNameWhenNameSpace = function() {
txt= " document:dnd-drog ";
cursor = new kukit.tk.Cursor(txt);
this.assertParsingError(kukit.kssp.KssSelector, cursor, null, true,
- 'Error : undefined event [dnd-drog].');
+ 'undefined or unbindable event (no iteration found) [dnd-drog].');
txt= " document:dnd-drog(hello) ";
cursor = new kukit.tk.Cursor(txt);
this.assertParsingError(kukit.kssp.KssSelector, cursor, null, true,
- 'Error : undefined event [dnd-drog].');
+ 'undefined or unbindable event (no iteration found) [dnd-drog].');
}
};
@@ -1255,17 +1255,15 @@
this.testSingleSelectorWithFirstComma = function() {
var txt= ",a:dnd-drag(hello),";
var cursor = new kukit.tk.Cursor(txt);
- var msg = 'Wrong event selector : missing event';
this.assertParsingError(kukit.kssp.KssSelectors, cursor, null, true,
- msg, 1);
+ 'Wrong event selector : missing event qualifier :<EVENTNAME> or
:<EVENTNAME>(<ID>).');
}
this.testSingleSelectorWithMiddleComma = function() {
var txt= "a:dnd-drag(hello),,p:click";
var cursor = new kukit.tk.Cursor(txt);
- var msg = 'Wrong event selector : missing event';
this.assertParsingError(kukit.kssp.KssSelectors, cursor, null, true,
- msg, 1);
+ 'Wrong event selector : missing event qualifier :<EVENTNAME> or
:<EVENTNAME>(<ID>).');
}
this.testSingleSelectorWithAdditionalComma = function() {
@@ -1279,9 +1277,8 @@
this.testSingleSelectorWithAdditionalCommas = function() {
var txt= "a:dnd-drag(hello),,";
var cursor = new kukit.tk.Cursor(txt);
- var msg = 'Wrong event selector : missing event';
this.assertParsingError(kukit.kssp.KssSelectors, cursor, null, true,
- msg, 1);
+ 'Wrong event selector : missing event qualifier :<EVENTNAME> or
:<EVENTNAME>(<ID>).');
}
this.testEventRulesWithMultipleSelectors = function() {
@@ -1440,11 +1437,11 @@
txt= " document:clack(kssAttr(hello)) ";
cursor = new kukit.tk.Cursor(txt);
this.assertParsingError(kukit.kssp.KssSelector, cursor, null, true,
- 'KssSelectorError: KssSpecialSelector [document] must not stand
with an event id acquired by value provider [kssAttr]');
+ 'KssSpecialSelector [document] must not stand with an event id
acquired by value provider [kssAttr]');
txt= " behaviour:clack(kssAttr(hello)) ";
cursor = new kukit.tk.Cursor(txt);
this.assertParsingError(kukit.kssp.KssSelector, cursor, null, true,
- 'KssSelectorError: KssSpecialSelector [behaviour] must not stand
with an event id acquired by value provider [kssAttr]');
+ 'KssSpecialSelector [behaviour] must not stand with an event id
acquired by value provider [kssAttr]');
};
};
Modified:
kukit/kukit.js/branch/ree-service-layer-and-refactoring/tests/test_tokenizer.js
==============================================================================
---
kukit/kukit.js/branch/ree-service-layer-and-refactoring/tests/test_tokenizer.js
(original)
+++
kukit/kukit.js/branch/ree-service-layer-and-refactoring/tests/test_tokenizer.js
Tue Dec 25 12:58:35 2007
@@ -53,14 +53,31 @@
new pclass(cursor, tokenClass, eofOk);
} catch(e) {
exc = e;
+ // We have two errors we have to look for. ParsingError is raised
+ // by the parser and contains row/column information.
if (e.name != 'ParsingError') {
throw e;
}
}
this.assertNotEquals(exc, null, 'Should have thrown a ParsingError
exception.');
- //this.assertEquals(exc.name, 'ParsingError');
+ //
+ var info = exc.info;
+ // Assert the text of the error.
if (typeof(errtxt) != 'undefined') {
- this.assertEquals(exc.message.substr(0, errtxt.length), errtxt);
+ // We are only interested for the ultimate error message
+ // thas is, here we ignore the annotations we might have put on
the message
+ while (info.previous_info) {
+ // go through the chain of error annotations
+ info = info.previous_info;
+ }
+ var exc_message = info.message;
+ // Take off possible row column message from the end - we check
that differently
+ var match = exc_message.match(RegExp(/^(.*), at row \d+, column
\d+$/));
+ if (match) {
+ exc_message = match[1];
+ }
+ // assert it now
+ this.assertEquals(exc_message, errtxt);
}
if (typeof(errpos) != 'undefined') {
// XXX Do not check the error position now. This should be fixed
however
@@ -95,7 +112,8 @@
// it does not work at least for IE 6.0.2800.1106
if (typeof(exc.number) == 'number') {
// IE
- this.assertEquals(exc.description, 'Error happened');
+ this.assertEquals(exc.description, 'ParsingError: Error happened');
+ this.assertEquals(exc.info.message, 'Error happened');
} else {
// toString result is browser dependent.
// colon in FF
@@ -104,7 +122,8 @@
var toString = exc.toString();
this.assertTrue(toString.indexOf('ParsingError') != -1,
'"ParsingError" not in toString() : ' + toString);
this.assertTrue(toString.indexOf('Error happened') != -1, '"Error
happened" not in toString() : ' + toString);
- this.assertEquals(exc.message, 'Error happened');
+ this.assertEquals(exc.message, 'ParsingError: Error happened');
+ this.assertEquals(exc.info.message, 'Error happened');
};
this.assertEquals(exc.errpos, null);
this.assertEquals(exc.errrow, null);
@@ -129,7 +148,8 @@
// it does not work at least for IE 6.0.2800.1106
if (typeof(exc.number) == 'number') {
// IE
- this.assertEquals(exc.description, 'Error happened, at row 3,
column 4');
+ this.assertEquals(exc.description, 'ParsingError: Error happened,
at row 3, column 4');
+ this.assertEquals(exc.info.message, 'Error happened, at row 3,
column 4');
} else {
// toString result is browser dependent.
// colon in FF
@@ -138,7 +158,8 @@
var toString = exc.toString();
this.assertTrue(toString.indexOf('ParsingError') != -1,
'"ParsingError" not in toString() : ' + toString);
this.assertTrue(toString.indexOf('Error happened, at row 3, column
4') != -1, '"Error happened, at row 3, column 4" not in toString() : ' +
toString);
- this.assertEquals(exc.message, 'Error happened, at row 3, column
4');
+ this.assertEquals(exc.message, 'ParsingError: Error happened, at
row 3, column 4');
+ this.assertEquals(exc.info.message, 'Error happened, at row 3,
column 4');
};
this.assertEquals(exc.info.kw.errpos, 13);
this.assertEquals(exc.info.kw.errrow, 3);
@@ -164,7 +185,7 @@
this.assertEquals(parser.result[0].symbol, 'fraction');
this.assertEquals(parser.result[0].txt, 'abc def');
- this.assertParsingError(pf, cursor, null, false, 'Unexpected EOF');
+ this.assertParsingError(pf, cursor, null, false, 'Unexpected EOF.');
var txt="abc{def";
var cursor = new kukit.tk.Cursor(txt);
_______________________________________________
Kukit-checkins mailing list
[email protected]
http://codespeak.net/mailman/listinfo/kukit-checkins