Skip to content
Browse files

bugfix

  • Loading branch information...
1 parent 15845c7 commit 9495c944de460f491cded0e08ee819c8330da7ef @elmerbulthuis committed Dec 28, 2011
Showing with 17 additions and 25 deletions.
  1. +16 −24 index.js
  2. +1 −1 package.json
View
40 index.js
@@ -153,13 +153,22 @@ module.exports = function(tokenCallback, expressionSet, options) {
*/
if(!token) {
if(expression) {
- var type = typeof expression;
- switch(type) {
- /*
- if expression is a string we try
- to find for that string.
- */
- case 'string':
+ if(expression.exec){
+ /*
+ when there is an exec method on the expression, assume it is
+ a regular expression and execute it!
+ */
+ var match = expression.exec(buffer);
+ if(match) {
+ token = extend(match, {
+ category: category
+ });
+ }
+ }
+ else{
+ /*
+ maybe it's a string!
+ */
var index = buffer.indexOf(expression);
/*
if we found the string (remember, ~-1 == 0) then
@@ -171,23 +180,6 @@ module.exports = function(tokenCallback, expressionSet, options) {
, category: category
});
}
- break;
-
- /*
- if it's a function, assume it to be a RegExp. Execute it
- and make it a token
- */
- case 'function':
- var match = expression.exec(buffer);
- if(match) {
- token = extend(match, {
- category: category
- });
- }
- break;
-
- default:
- throw "expression '" + category + "' is '" + type + "', expecting 'string' or a RegExp ('function').";
}
/*
if there is a match, cache it!
View
2 package.json
@@ -1,7 +1,7 @@
{
"name": "2kenizer"
, "description": "efficient tokenizer"
- , "version": "0.0.5"
+ , "version": "0.0.6"
, "author": "Elmer Bulthuis <elmerbulthuis@gmail.com>"
, "repositories": [{
"type": "git",

0 comments on commit 9495c94

Please sign in to comment.
Something went wrong with that request. Please try again.