better handling of token types in bracket_match.js
This commit is contained in:
parent
7edd5724ef
commit
a80828bab5
1 changed files with 24 additions and 18 deletions
|
|
@ -96,21 +96,24 @@ function BracketMatch() {
|
|||
"}": "{"
|
||||
};
|
||||
|
||||
this.$findOpeningBracket = function(bracket, position) {
|
||||
this.$findOpeningBracket = function(bracket, position, typeRe) {
|
||||
var openBracket = this.$brackets[bracket];
|
||||
var depth = 1;
|
||||
|
||||
var iterator = new TokenIterator(this, position.row, position.column);
|
||||
var token = iterator.getCurrentToken();
|
||||
if (!token) return null;
|
||||
if (!token)
|
||||
token = iterator.stepForward();
|
||||
if (!token)
|
||||
return
|
||||
|
||||
// token.type contains a period-delimited list of token identifiers
|
||||
// (e.g.: "constant.numeric" or "paren.lparen"). Create a pattern that
|
||||
// matches any token containing the same identifiers or a subset. In
|
||||
// addition, if token.type includes "rparen", then also match "lparen".
|
||||
// So if type.token is "paren.rparen", then typeRe will match "lparen.paren".
|
||||
var typeRe = new RegExp("(\\.?" +
|
||||
token.type.replace(".", "|").replace("rparen", "lparen|rparen") + ")+");
|
||||
if (!typeRe){
|
||||
typeRe = new RegExp(
|
||||
"(\\.?" +
|
||||
token.type.replace(".", "\\.").replace("rparen", ".paren")
|
||||
+ ")+"
|
||||
);
|
||||
}
|
||||
|
||||
// Start searching in token, just before the character at position.column
|
||||
var valueIndex = position.column - iterator.getCurrentTokenColumn() - 2;
|
||||
|
|
@ -149,21 +152,24 @@ function BracketMatch() {
|
|||
return null;
|
||||
};
|
||||
|
||||
this.$findClosingBracket = function(bracket, position) {
|
||||
this.$findClosingBracket = function(bracket, position, typeRe) {
|
||||
var closingBracket = this.$brackets[bracket];
|
||||
var depth = 1;
|
||||
|
||||
var iterator = new TokenIterator(this, position.row, position.column);
|
||||
var token = iterator.getCurrentToken();
|
||||
if (!token) return null;
|
||||
if (!token)
|
||||
token = iterator.stepForward();
|
||||
if (!token)
|
||||
return
|
||||
|
||||
// token.type contains a period-delimited list of token identifiers
|
||||
// (e.g.: "constant.numeric" or "paren.lparen"). Create a pattern that
|
||||
// matches any token containing the same identifiers or a subset. In
|
||||
// addition, if token.type includes "lparen", then also match "rparen".
|
||||
// So if type.token is "lparen.paren", then typeRe will match "paren.rparen".
|
||||
var typeRe = new RegExp("(\\.?" +
|
||||
token.type.replace(".", "|").replace("lparen", "lparen|rparen") + ")+");
|
||||
if (!typeRe){
|
||||
typeRe = new RegExp(
|
||||
"(\\.?" +
|
||||
token.type.replace(".", "\\.").replace("lparen", ".paren")
|
||||
+ ")+"
|
||||
);
|
||||
}
|
||||
|
||||
// Start searching in token, after the character at position.column
|
||||
var valueIndex = position.column - iterator.getCurrentTokenColumn();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue