wip: fixing capture group problems

This commit is contained in:
Corey Johnson & Nathan Sobo
2012-08-03 11:38:45 -07:00
parent 1a243adfcf
commit 0e1d3fe3a9
3 changed files with 22 additions and 1 deletions

View File

@@ -68,6 +68,20 @@ describe "TextMateGrammar", ->
expect(secondTokens[0]).toEqual value: "heredoc", scopes: ['source.coffee', 'string.quoted.heredoc.coffee']
expect(secondTokens[1]).toEqual value: "'''", scopes: ['source.coffee', 'string.quoted.heredoc.coffee', 'punctuation.definition.string.end.coffee']
describe "when the line matches a pattern with optional capture groups", ->
it "only returns tokens for capture groups that matched", ->
{tokens} = grammar.getLineTokens("class Quicksort")
expect(tokens.length).toBe 3
expect(token[0].value).toBe "class"
expect(token[1].value).toBe " "
expect(token[2].value).toBe "Quicksort"
describe "something", ->
fit "works", ->
{tokens} = grammar.getLineTokens(" destroy: ->")
expect(tokens.length).toBe 5
describe "when the line matches a begin/end pattern that contains sub-patterns", ->
it "returns tokens within the begin/end scope based on the sub-patterns", ->
{tokens} = grammar.getLineTokens('"""heredoc with character escape \\t"""')

View File

@@ -137,8 +137,10 @@ class Pattern
previousCaptureEndPosition = 0
for captureIndex in _.keys(@captures)
currentCaptureStartPosition = match.indices[captureIndex] - match.index
currentCaptureText = match[captureIndex]
continue unless currentCaptureText.length
currentCaptureStartPosition = match.indices[captureIndex] - match.index
currentCaptureScopeName = @captures[captureIndex].name
if previousCaptureEndPosition < currentCaptureStartPosition

View File

@@ -145,4 +145,9 @@ class TokenizedBuffer
stop()
position
logLines: (start=0, end=@buffer.getLastRow()) ->
for row in [start..end]
line = @lineForScreenRow(row).text
console.log row, line, line.length
_.extend(TokenizedBuffer.prototype, EventEmitter)