Move TextMateGrammar.buildCaptureTree to .getCaptureTree method on OnigRegExp

This commit is contained in:
Nathan Sobo
2012-08-06 11:43:44 -06:00
parent 32fc042929
commit 0d6d16a438
5 changed files with 49 additions and 48 deletions

View File

@@ -0,0 +1,18 @@
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
childCaptures.push(buildCaptureTree(captures, startPositions, totalCaptures))
tree.captures = childCaptures if childCaptures.length
tree
if match = @search(string, startPosition)
buildCaptureTree(match, match.indices)