mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-11-10 18:24:09 +03:00
Resolve ${group:/command} style pattern names
These are used by the todo package to include the lower cased version of the matched capture index in the pattern scope name.
This commit is contained in:
parent
42d70f888e
commit
7313407d04
@ -511,6 +511,20 @@ describe "TextMateGrammar", ->
|
||||
expect(tokens[0].value).toBe "forever and ever"
|
||||
expect(tokens[0].scopes).toEqual ["source", "text"]
|
||||
|
||||
describe "${capture:/command} style pattern names", ->
|
||||
lines = null
|
||||
|
||||
beforeEach ->
|
||||
atom.activatePackage('ruby-tmbundle', sync: true)
|
||||
atom.activatePackage('todo-tmbundle', sync: true)
|
||||
grammar = syntax.selectGrammar('main.rb')
|
||||
lines = grammar.tokenizeLines "# TODO be nicer"
|
||||
|
||||
it "replaces the number with the capture group and translates the text", ->
|
||||
tokens = lines[0]
|
||||
expect(tokens[2].value).toEqual "TODO"
|
||||
expect(tokens[2].scopes).toEqual ["source.ruby", "comment.line.number-sign.ruby", "storage.type.class.todo"]
|
||||
|
||||
describe "language-specific integration tests", ->
|
||||
lines = null
|
||||
|
||||
|
@ -422,16 +422,29 @@ class Pattern
|
||||
else
|
||||
[this]
|
||||
|
||||
resolveScopeName: (line, captureIndices) ->
|
||||
resolvedScopeName = @scopeName.replace /\${(\d+):\/(downcase|upcase)}/, (match, index, command) ->
|
||||
capture = captureIndices[parseInt(index)]
|
||||
if capture?
|
||||
replacement = line.substring(capture.start, capture.end)
|
||||
switch command
|
||||
when 'downcase' then replacement.toLowerCase()
|
||||
when 'upcase' then replacement.toUpperCase()
|
||||
else replacement
|
||||
else
|
||||
match
|
||||
|
||||
resolvedScopeName.replace /\$(\d+)/, (match, index) ->
|
||||
capture = captureIndices[parseInt(index)]
|
||||
if capture?
|
||||
line.substring(capture.start, capture.end)
|
||||
else
|
||||
match
|
||||
|
||||
handleMatch: (stack, line, captureIndices) ->
|
||||
scopes = scopesFromStack(stack)
|
||||
if @scopeName and not @popRule
|
||||
patternScope = @scopeName.replace /\$\d+/, (match) ->
|
||||
capture = captureIndices[parseInt(match.substring(1))]
|
||||
if capture?
|
||||
line.substring(capture.start, capture.end)
|
||||
else
|
||||
match
|
||||
scopes.push(patternScope)
|
||||
scopes.push(@resolveScopeName(line, captureIndices))
|
||||
|
||||
if @captures
|
||||
tokens = @getTokensForCaptureIndices(line, _.clone(captureIndices), scopes, stack)
|
||||
|
Loading…
Reference in New Issue
Block a user