better handling of token types in bracket_match.js

This commit is contained in:
nightwing 2012-04-22 11:26:10 +04:00
commit a80828bab5

View file

@ -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();