regexp-tree
Advanced tools
Comparing version 0.0.86 to 0.1.0
@@ -271,4 +271,3 @@ /** | ||
capturingGroupsCount++; | ||
namedGroups[_1] = capturingGroupsCount; | ||
namedGroups[_1] = currentCapturingGroup; | ||
@@ -279,14 +278,17 @@ __ = Node({ | ||
name: _1, | ||
number: capturingGroupsCount, | ||
number: currentCapturingGroup, | ||
expression: _2 | ||
}, __loc); | ||
updateCapturingGroupTracking(); | ||
}], [15, 3, function (_1, _2, _3, _1loc, _2loc, _3loc) { | ||
__loc = yyloc(_1loc, _3loc); | ||
capturingGroupsCount++; | ||
__ = Node({ | ||
type: 'Group', | ||
capturing: true, | ||
number: capturingGroupsCount, | ||
number: currentCapturingGroup, | ||
expression: _2 | ||
}, __loc); | ||
updateCapturingGroupTracking(); | ||
}], [16, 3, function (_1, _2, _3, _1loc, _2loc, _3loc) { | ||
@@ -553,7 +555,7 @@ __loc = yyloc(_1loc, _3loc); | ||
if (this._tokensQueue.length > 0) { | ||
return this._toToken(this._tokensQueue.shift()); | ||
return this.onToken(this._toToken(this._tokensQueue.shift())); | ||
} | ||
if (!this.hasMoreTokens()) { | ||
return EOF_TOKEN; | ||
return this.onToken(EOF_TOKEN); | ||
} | ||
@@ -598,3 +600,3 @@ | ||
return this._toToken(token, yytext); | ||
return this.onToken(this._toToken(token, yytext)); | ||
} | ||
@@ -692,2 +694,11 @@ } | ||
return null; | ||
}, | ||
/** | ||
* Allows analyzing, and transforming token. Default implementation | ||
* just passes the token through. | ||
*/ | ||
onToken: function onToken(token) { | ||
return token; | ||
} | ||
@@ -797,4 +808,6 @@ }; | ||
stack.push({ symbol: tokens[token.type], semanticValue: token.value, loc: _loc2 }, Number(entry.slice(1))); | ||
shiftedToken = token; | ||
shiftedToken = this.onShift(token); | ||
stack.push({ symbol: tokens[shiftedToken.type], semanticValue: shiftedToken.value, loc: _loc2 }, Number(entry.slice(1))); | ||
token = tokenizer.getNextToken(); | ||
@@ -884,6 +897,30 @@ } | ||
onParseBegin: function onParseBegin(string, tokenizer, options) {}, | ||
onParseEnd: function onParseEnd(parsed) {} | ||
onParseEnd: function onParseEnd(parsed) {}, | ||
/** | ||
* Allows analyzing, and transforming shifted token. Default implementation | ||
* just passes the token through. | ||
*/ | ||
onShift: function onShift(token) { | ||
return token; | ||
} | ||
}; | ||
/** | ||
* Lower group boundary: | ||
* | ||
* /(((a)b)c)(d)(e)/ | ||
* | ||
* The first paren in (((a)b)c) has lower bound 0, but when | ||
* we reach the (d), it already 4. | ||
*/ | ||
var capturingGroupsCurrentLower = 0; | ||
/** | ||
* Group number to assign to a group. | ||
*/ | ||
var currentCapturingGroup = 0; | ||
/** | ||
* Tracks capturing groups. | ||
@@ -905,2 +942,4 @@ */ | ||
parsingString = string; | ||
capturingGroupsCurrentLower = 0; | ||
currentCapturingGroup = 0; | ||
capturingGroupsCount = 0; | ||
@@ -924,3 +963,25 @@ namedGroups = {}; | ||
yyparse.onShift = function (token) { | ||
if (token.type === 'L_PAREN' || token.type === 'NAMED_CAPTURE_GROUP') { | ||
currentCapturingGroup++; | ||
capturingGroupsCount++; | ||
} | ||
return token; | ||
}; | ||
/** | ||
* Updates the capturing groups counts. | ||
*/ | ||
function updateCapturingGroupTracking() { | ||
// Go up. | ||
currentCapturingGroup--; | ||
// We reached the top level, reset the current group: | ||
if (currentCapturingGroup === capturingGroupsCurrentLower) { | ||
currentCapturingGroup = capturingGroupsCount; | ||
capturingGroupsCurrentLower = capturingGroupsCount; | ||
} | ||
} | ||
/** | ||
* Extracts ranges from the range string. | ||
@@ -927,0 +988,0 @@ */ |
{ | ||
"name": "regexp-tree", | ||
"version": "0.0.86", | ||
"version": "0.1.0", | ||
"license": "MIT", | ||
@@ -41,4 +41,4 @@ "description": "Regular Expressions parser in JavaScript", | ||
"shelljs": "^0.7.8", | ||
"syntax-cli": "^0.1.1" | ||
"syntax-cli": "^0.1.11" | ||
} | ||
} |
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
256732
5870