Skip to content

Commit

Permalink
now all dependancies are simplified and should allow to text-plot the…
Browse files Browse the repository at this point in the history
… structure of the parsed tree
  • Loading branch information
Vladimir committed Oct 17, 2012
1 parent acf4c54 commit 338b8ed
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 49 deletions.
2 changes: 2 additions & 0 deletions lib/Group.js
Expand Up @@ -19,4 +19,6 @@ Group.prototype.explain = function explain ( shift ) {
content.push(shift + '->Group(' + this.isCapturing + ')');
content.push(this.regex.explain(shift + ' ');
content.push(shift + '<-Group');

return content.join('\n');
}
20 changes: 6 additions & 14 deletions lib/Position.js
@@ -1,25 +1,17 @@
/**
* Copyright (c) 2012 Vladimir's Software. All rights reserved.
*
* @fileoverview Position of an element in regular expression
* @fileoverview Position zero-width element
* @author vladimir.darmin@gmail.com
*
* @created Fri, Oct 12 2012 - 17:45:54 -0700
* @updated Fri, Oct 12 2012 - 17:45:54 -0700
*/

var Stream = require('./Stream');

var Position = module.exports = function Position ( stream ) {
var regex = /\^|\$|\\b|\\B/;

if ( !(this instanceof Position) ) {
var match = stream.check(regex);

return match instanceof Error ? match : new Position(match);
}

var match = stream instanceof Stream ? stream.match(regex) : stream;
var Position = module.exports = function Position ( value ) {
this.value = value
}

this.value = match[0].slice(-1);
Position.prototype.explain = function explain ( shift ) {
return shift + 'Position(' + this.value + ')';
}
27 changes: 6 additions & 21 deletions lib/Quantifier.js
Expand Up @@ -8,26 +8,11 @@
* @updated Fri, Oct 12 2012 - 23:36:02 -0700
*/

var Stream = require('./Stream');

var Quantifier = module.exports = function Quantifier ( stream ) {
var regex = /(\?)|(\*)|(\+)|{(\d+)(?:,(\d+)?)}/;

if ( !(this instanceof Quantifier) ) {
var match = stream.check(regex);

return match instanceof Error ? match : new Quantifier(match);
}

var match = stream instanceof Stream ? stream.match(regex) : stream;

if ( match[1] ) this.from = 0;
else if ( match[2] ) this.from = 0;
else if ( match[3] ) this.from = 1;
else this.from = +match[4];
var Quantifier = module.exports = function Quantifier ( from, to ) {
this.from = from;
this.to = to;
}

if ( match[1] this.to = 1;
else if ( match[2] ) this.to = Infinity;
else if ( match[3] ) this.to = Infinity;
else this.to = +(match[5] || Infinity);
Quantifier.prototype.explain = function explain ( shift ) {
return shift + 'Quantifier(' + this.from + ', ' + this.to + ')';
}
2 changes: 1 addition & 1 deletion lib/Range.js
Expand Up @@ -164,5 +164,5 @@ Range.prototype.toString = function toString ( ) {
}

Range.prototype.explain = function explain ( shift ) {
return shift + String(this);
return shift + 'Range(' + String(this) + ')';
}
18 changes: 5 additions & 13 deletions lib/Reference.js
Expand Up @@ -8,18 +8,10 @@
* @updated Sat, Oct 13 2012 - 23:35:50 -0700
*/

var Stream = require('./Stream');

var Reference = module.exports = function Reference ( Stream ) {
var regex = /\\\(d+)/;

if ( !(this instanceof Reference) ) {
var match = stream.check(regex);

return match instanceof Error ? match : new Reference(match);
}

var match = stream instanceof Stream ? stream.match(regex) : stream;
var Reference = module.exports = function Reference ( number ) {
this.number = number;
}

this.value = match[1];
Reference.prototype.explain = function explain ( shift ) {
return shift + 'Reference(' + this.number + ')';
}

0 comments on commit 338b8ed

Please sign in to comment.