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 openBracket = this.$brackets[bracket];
var depth = 1; var depth = 1;
var iterator = new TokenIterator(this, position.row, position.column); var iterator = new TokenIterator(this, position.row, position.column);
var token = iterator.getCurrentToken(); 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 if (!typeRe){
// (e.g.: "constant.numeric" or "paren.lparen"). Create a pattern that typeRe = new RegExp(
// matches any token containing the same identifiers or a subset. In "(\\.?" +
// addition, if token.type includes "rparen", then also match "lparen". token.type.replace(".", "\\.").replace("rparen", ".paren")
// So if type.token is "paren.rparen", then typeRe will match "lparen.paren". + ")+"
var typeRe = new RegExp("(\\.?" + );
token.type.replace(".", "|").replace("rparen", "lparen|rparen") + ")+"); }
// Start searching in token, just before the character at position.column // Start searching in token, just before the character at position.column
var valueIndex = position.column - iterator.getCurrentTokenColumn() - 2; var valueIndex = position.column - iterator.getCurrentTokenColumn() - 2;
@ -149,21 +152,24 @@ function BracketMatch() {
return null; return null;
}; };
this.$findClosingBracket = function(bracket, position) { this.$findClosingBracket = function(bracket, position, typeRe) {
var closingBracket = this.$brackets[bracket]; var closingBracket = this.$brackets[bracket];
var depth = 1; var depth = 1;
var iterator = new TokenIterator(this, position.row, position.column); var iterator = new TokenIterator(this, position.row, position.column);
var token = iterator.getCurrentToken(); 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 if (!typeRe){
// (e.g.: "constant.numeric" or "paren.lparen"). Create a pattern that typeRe = new RegExp(
// matches any token containing the same identifiers or a subset. In "(\\.?" +
// addition, if token.type includes "lparen", then also match "rparen". token.type.replace(".", "\\.").replace("lparen", ".paren")
// So if type.token is "lparen.paren", then typeRe will match "paren.rparen". + ")+"
var typeRe = new RegExp("(\\.?" + );
token.type.replace(".", "|").replace("lparen", "lparen|rparen") + ")+"); }
// Start searching in token, after the character at position.column // Start searching in token, after the character at position.column
var valueIndex = position.column - iterator.getCurrentTokenColumn(); var valueIndex = position.column - iterator.getCurrentTokenColumn();