Comparing version 0.1.2 to 0.1.3
var util = require('./util') | ||
, types = require('./types') | ||
, classes = require('./classes') | ||
, sets = require('./sets') | ||
, positions = require('./positions') | ||
@@ -35,3 +35,3 @@ ; | ||
switch (c) { | ||
// handle escaped characters, inclues a few classes | ||
// handle escaped characters, inclues a few sets | ||
case '\\': | ||
@@ -50,23 +50,23 @@ c = str[i++]; | ||
case 'w': | ||
last.push(classes.words()); | ||
last.push(sets.words()); | ||
break; | ||
case 'W': | ||
last.push(classes.notWords()); | ||
last.push(sets.notWords()); | ||
break; | ||
case 'd': | ||
last.push(classes.ints()); | ||
last.push(sets.ints()); | ||
break; | ||
case 'D': | ||
last.push(classes.notInts()); | ||
last.push(sets.notInts()); | ||
break; | ||
case 's': | ||
last.push(classes.whitespace()); | ||
last.push(sets.whitespace()); | ||
break; | ||
case 'S': | ||
last.push(classes.notWhitespace()); | ||
last.push(sets.notWhitespace()); | ||
break; | ||
@@ -99,3 +99,3 @@ | ||
// handle classes | ||
// handle custom sets | ||
case '[': | ||
@@ -116,3 +116,3 @@ // check if this class is 'anti' i.e. [^abc] | ||
last.push({ | ||
type: types.CLASS | ||
type: types.SET | ||
, set: classTokens[0] | ||
@@ -127,3 +127,3 @@ , not: not | ||
case '.': | ||
last.push(classes.anyChar()); | ||
last.push(sets.anyChar()); | ||
break; | ||
@@ -130,0 +130,0 @@ |
@@ -5,3 +5,3 @@ module.exports = { | ||
, POSITION : 2 | ||
, CLASS : 3 | ||
, SET : 3 | ||
, RANGE : 4 | ||
@@ -8,0 +8,0 @@ , REPETITION : 5 |
var types = require('./types') | ||
, classes = require('./classes') | ||
, sets = require('./sets') | ||
; | ||
@@ -47,3 +47,3 @@ | ||
var tokens = [] | ||
, regexp = /\\(?:(w)|(d)|(s)|(.))|(.-[^\]])|(\])|(.)/g | ||
, regexp = /\\(?:(w)|(d)|(s)|(W)|(D)|(S)|(.))|(.-[^\]])|(\])|(.)/g | ||
, rs, c | ||
@@ -55,11 +55,20 @@ ; | ||
if (rs[1]) { | ||
tokens.push(classes.words()); | ||
tokens.push(sets.words()); | ||
} else if (rs[2]) { | ||
tokens.push(classes.ints()); | ||
tokens.push(sets.ints()); | ||
} else if (rs[3]) { | ||
tokens.push(classes.whitespace()); | ||
tokens.push(sets.whitespace()); | ||
} else if (c = rs[4] || rs[7]) { | ||
} else if (rs[4]) { | ||
tokens.push(sets.notWords()); | ||
} else if (rs[5]) { | ||
tokens.push(sets.notInts()); | ||
} else if (rs[6]) { | ||
tokens.push(sets.notWhitespace()); | ||
} else if (c = rs[7] || rs[10]) { | ||
tokens.push({ | ||
@@ -70,3 +79,3 @@ type: types.CHAR | ||
} else if (c = rs[5]) { | ||
} else if (c = rs[8]) { | ||
tokens.push({ | ||
@@ -73,0 +82,0 @@ type: types.RANGE |
@@ -5,3 +5,3 @@ { | ||
"keywords": ["regex", "regexp", "regular expression", "parser", "tokenizer"], | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"repository": { | ||
@@ -8,0 +8,0 @@ "type": "git", |
@@ -71,3 +71,3 @@ # Regular Expression Tokenizer [![Build Status](https://secure.travis-ci.org/fent/ret.js.png)](http://travis-ci.org/fent/ret.js) | ||
### CLASS | ||
### SET | ||
@@ -78,3 +78,3 @@ Contains a key `set` specifying what tokens are allowed and a key `not` specifying if the set should be negated. | ||
{ | ||
"type": ret.typs.CLASS | ||
"type": ret.types.SET | ||
, "set": [token] | ||
@@ -87,3 +87,3 @@ , "not": false | ||
Used in class tokens to specify a character range. `from` and `to` are character codes. | ||
Used in set tokens to specify a character range. `from` and `to` are character codes. | ||
@@ -90,0 +90,0 @@ ```js |
var vows = require('vows') | ||
, assert = require('assert') | ||
, classes = require('../lib/classes') | ||
, sets = require('../lib/sets') | ||
, ret = require('..') | ||
@@ -73,3 +73,3 @@ , types = ret.types | ||
'Predefined classes': { | ||
'Predefined sets': { | ||
'that represent a typical date format': { | ||
@@ -80,3 +80,3 @@ topic: ret('\\w \\d:\\d:\\d'), | ||
assert.isArray(t.stack); | ||
assert.deepEqual(t.stack[0], classes.words()); | ||
assert.deepEqual(t.stack[0], sets.words()); | ||
}, | ||
@@ -92,5 +92,5 @@ | ||
'Integer classes': function(t) { | ||
'Integer sets': function(t) { | ||
assert.isArray(t.stack); | ||
var ints = classes.ints(); | ||
var ints = sets.ints(); | ||
assert.deepEqual(t.stack[2], ints); | ||
@@ -114,3 +114,3 @@ assert.deepEqual(t.stack[4], ints); | ||
'Custom classes': { | ||
'Custom sets': { | ||
'topic': ret('[$!a-z123] thing [^0-9]'), | ||
@@ -123,3 +123,3 @@ | ||
{ | ||
type: types.CLASS | ||
type: types.SET | ||
, set: [ | ||
@@ -149,3 +149,3 @@ { type: types.CHAR, value: '$'.charCodeAt(0) } | ||
, { | ||
type: types.CLASS | ||
type: types.SET | ||
, set: [{ | ||
@@ -439,6 +439,6 @@ type: types.RANGE | ||
, stack: [{ type: types.REPETITION, min: 1, max: Infinity | ||
, value: classes.words()}] } | ||
, value: sets.words()}] } | ||
, { type: types.CHAR, value: '>'.charCodeAt(0) } | ||
, { type: types.REPETITION, min: 0, max: Infinity | ||
, value: classes.words() } | ||
, value: sets.words() } | ||
, { type: types.CHAR, value: '<'.charCodeAt(0) } | ||
@@ -445,0 +445,0 @@ , { type: types.REFERENCE, value: 1 } |
@@ -5,3 +5,3 @@ var vows = require('vows') | ||
, types = require('..').types | ||
, classes = require('../lib/classes') | ||
, sets = require('../lib/sets') | ||
; | ||
@@ -31,13 +31,13 @@ | ||
topic: function() { | ||
return util.tokenizeClass('\\w\\d$\\s\\]\\B.+-] will ignore'); | ||
return util.tokenizeClass('\\w\\d$\\s\\]\\B\\W\\D\\S.+-] will ignore'); | ||
}, | ||
'Get a words class token': function(t) { | ||
'Get a words set token': function(t) { | ||
assert.isArray(t[0]); | ||
assert.deepEqual(t[0][0], classes.words()); | ||
assert.deepEqual(t[0][0], sets.words()); | ||
}, | ||
'Get an integers class token': function(t) { | ||
'Get an integers set token': function(t) { | ||
assert.isArray(t[0]); | ||
assert.deepEqual(t[0][1], classes.ints()); | ||
assert.deepEqual(t[0][1], sets.ints()); | ||
}, | ||
@@ -52,17 +52,24 @@ | ||
'Get a whitespace class token': function(t) { | ||
'Get a whitespace set token': function(t) { | ||
assert.isArray(t[0]); | ||
assert.deepEqual(t[0][3], classes.whitespace()); | ||
assert.deepEqual(t[0][3], sets.whitespace()); | ||
}, | ||
'Get correct char tokens at end of class': function(t) { | ||
'Get negated sets': function(t) { | ||
assert.isArray(t[0]); | ||
assert.deepEqual(t[0][6], { type: types.CHAR, value: 46 }); | ||
assert.deepEqual(t[0][7], { type: types.CHAR, value: 43 }); | ||
assert.deepEqual(t[0][8], { type: types.CHAR, value: 45 }); | ||
assert.deepEqual(t[0][6], sets.notWords()); | ||
assert.deepEqual(t[0][7], sets.notInts()); | ||
assert.deepEqual(t[0][8], sets.notWhitespace()); | ||
}, | ||
'Get correct char tokens at end of set': function(t) { | ||
assert.isArray(t[0]); | ||
assert.deepEqual(t[0][9], { type: types.CHAR, value: 46 }); | ||
assert.deepEqual(t[0][10], { type: types.CHAR, value: 43 }); | ||
assert.deepEqual(t[0][11], { type: types.CHAR, value: 45 }); | ||
}, | ||
'Get correct position of closing brace': function(t) { | ||
assert.isNumber(t[1]); | ||
assert.equal(t[1], 15); | ||
assert.equal(t[1], 21); | ||
} | ||
@@ -69,0 +76,0 @@ }, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
34818
903