mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Implement OnigRegExp.getCaptureTree natively
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
(function() {
|
||||
native function buildOnigRegExp(source);
|
||||
native function search(string, index);
|
||||
native function getCaptureTree(source, index);
|
||||
native function getCaptureCount();
|
||||
|
||||
function OnigRegExp(source) {
|
||||
@@ -12,6 +13,7 @@
|
||||
}
|
||||
|
||||
OnigRegExp.prototype.search = search;
|
||||
OnigRegExp.prototype.getCaptureTree = getCaptureTree;
|
||||
OnigRegExp.prototype.getCaptureCount = getCaptureCount;
|
||||
|
||||
this.OnigRegExp = OnigRegExp;
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
OnigRegExp.prototype.getCaptureTree = (string, startPosition) ->
|
||||
buildCaptureTree = (captures, startPositions, totalCaptures=captures.length) ->
|
||||
index = totalCaptures - captures.length
|
||||
text = captures.shift()
|
||||
startPosition = startPositions.shift()
|
||||
endPosition = startPosition + text.length
|
||||
|
||||
tree = { index, text, position: startPosition }
|
||||
|
||||
childCaptures = []
|
||||
while startPositions[0] < endPosition
|
||||
subtree = buildCaptureTree(captures, startPositions, totalCaptures)
|
||||
childCaptures.push(subtree) if subtree.text.length
|
||||
|
||||
tree.captures = childCaptures if childCaptures.length
|
||||
tree
|
||||
|
||||
if match = @search(string, startPosition)
|
||||
buildCaptureTree(match, match.indices)
|
||||
Reference in New Issue
Block a user