mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Move TextMateGrammar.buildCaptureTree to .getCaptureTree method on OnigRegExp
This commit is contained in:
18
src/stdlib/onig-reg-exp.coffee
Normal file
18
src/stdlib/onig-reg-exp.coffee
Normal 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)
|
||||
Reference in New Issue
Block a user