mirror of
https://github.com/atom/atom.git
synced 2026-04-06 03:02:13 -04:00
Replace includes with the patterns to which they refer
This commit is contained in:
@@ -48,8 +48,16 @@ class Rule
|
||||
|
||||
constructor: (@grammar, {@parentRule, @scopeName, patterns, @endPattern}) ->
|
||||
patterns ?= []
|
||||
@patterns = patterns.map (pattern) => new Pattern(this, pattern)
|
||||
@patterns = []
|
||||
@patterns.push(@endPattern) if @endPattern
|
||||
for pattern in patterns
|
||||
if pattern.include
|
||||
repoName = pattern.include.replace(/^#/, "")
|
||||
includedPatterns = @grammar.repository[repoName]?.patterns ? []
|
||||
for includedPattern in includedPatterns
|
||||
@patterns.push(new Pattern(this, includedPattern))
|
||||
else
|
||||
@patterns.push(new Pattern(this, pattern))
|
||||
|
||||
getNextTokens: (line, position) ->
|
||||
{ match, pattern } = @getNextMatch(line, position)
|
||||
@@ -74,9 +82,7 @@ class Rule
|
||||
{ match: nextMatch, pattern: matchedPattern }
|
||||
|
||||
getScopes: ->
|
||||
scopes = @parentRule?.getScopes() ? []
|
||||
scopes = scopes.concat(@scopeName) if @scopeName
|
||||
scopes
|
||||
(@parentRule?.getScopes() ? []).concat(@scopeName)
|
||||
|
||||
class Pattern
|
||||
parentRule: null
|
||||
@@ -86,26 +92,19 @@ class Pattern
|
||||
captures: null
|
||||
|
||||
constructor: (@parentRule, { name, match, begin, end, captures, beginCaptures, endCaptures, patterns, include}) ->
|
||||
if include
|
||||
patterns = @parentRule.grammar.repository[include.replace(/^#/, '')]?.patterns
|
||||
@includeRule = new Rule @parentRule.grammar, {@parentRule, patterns}
|
||||
else
|
||||
@scopeName = name
|
||||
if match
|
||||
@regex = new OnigRegExp(match)
|
||||
@captures = captures
|
||||
@nextRule = @parentRule
|
||||
else if begin
|
||||
@regex = new OnigRegExp(begin)
|
||||
@captures = beginCaptures ? captures
|
||||
endPattern = new Pattern(@parentRule, { name: @scopeName, match: end, captures: endCaptures ? captures })
|
||||
@nextRule = new Rule(@parentRule.grammar, {@parentRule, @scopeName, patterns, endPattern})
|
||||
@scopeName = name
|
||||
if match
|
||||
@regex = new OnigRegExp(match)
|
||||
@captures = captures
|
||||
@nextRule = @parentRule
|
||||
else if begin
|
||||
@regex = new OnigRegExp(begin)
|
||||
@captures = beginCaptures ? captures
|
||||
endPattern = new Pattern(@parentRule, { name: @scopeName, match: end, captures: endCaptures ? captures })
|
||||
@nextRule = new Rule(@parentRule.grammar, {@parentRule, @scopeName, patterns, endPattern})
|
||||
|
||||
getNextMatch: (line, position) ->
|
||||
if @includeRule
|
||||
@includeRule.getNextMatch(line, position)
|
||||
else
|
||||
{pattern: this, match: @regex?.search(line, position)}
|
||||
{pattern: this, match: @regex?.search(line, position)}
|
||||
|
||||
getTokensForMatch: (match) ->
|
||||
tokens = []
|
||||
|
||||
Reference in New Issue
Block a user