mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
Made the parsing engine extensible.
This commit is contained in:
parent
f5f6cbc8c0
commit
98bd178cb0
61
jquery/jquery.js
vendored
61
jquery/jquery.js
vendored
@ -1406,50 +1406,53 @@ jQuery.extend({
|
|||||||
return "";
|
return "";
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// The regular expressions that power the parsing engine
|
||||||
|
parse: [
|
||||||
|
// Match: [@value='test'], [@foo]
|
||||||
|
"\\[ *(@)S *([!*$^=]*) *Q\\]",
|
||||||
|
|
||||||
|
// Match: [div], [div p]
|
||||||
|
"(\\[)Q\\]",
|
||||||
|
|
||||||
|
// Match: :contains('foo')
|
||||||
|
"(:)S\\(Q\\)",
|
||||||
|
|
||||||
|
// Match: :even, :last-chlid
|
||||||
|
"([:.#]*)S"
|
||||||
|
],
|
||||||
|
|
||||||
|
parseSwap: [ 1, 0, 0, 0 ],
|
||||||
|
|
||||||
filter: function(t,r,not) {
|
filter: function(t,r,not) {
|
||||||
// Figure out if we're doing regular, or inverse, filtering
|
// Figure out if we're doing regular, or inverse, filtering
|
||||||
var g = not !== false ? jQuery.grep :
|
var g = not !== false ? jQuery.grep :
|
||||||
function(a,f) {return jQuery.grep(a,f,true);};
|
function(a,f) {return jQuery.grep(a,f,true);};
|
||||||
|
|
||||||
|
while ( t && /^[a-z[({<*:.#]/i.test(t) ) {
|
||||||
|
|
||||||
|
for ( var i = 0; i < jQuery.parse.length; i++ ) {
|
||||||
|
var re = new RegExp( "^" + jQuery.parse[i]
|
||||||
|
|
||||||
// Look for a string-like sequence
|
// Look for a string-like sequence
|
||||||
var str = "([a-zA-Z*_-][a-zA-Z0-9_-]*)";
|
.replace( 'S', "([a-z*_-][a-z0-9_-]*)" )
|
||||||
|
|
||||||
// Look for something (optionally) enclosed with quotes
|
// Look for something (optionally) enclosed with quotes
|
||||||
var qstr = " *'?\"?([^'\"]*)'?\"? *";
|
.replace( 'Q', " *'?\"?([^'\"]*)'?\"? *" ), "i" );
|
||||||
|
|
||||||
while ( t && /^[a-zA-Z\[*:.#]/.test(t) ) {
|
var m = re.exec( t );
|
||||||
// Handles:
|
|
||||||
// [@foo], [@foo=bar], etc.
|
|
||||||
var re = new RegExp("^\\[ *@" + str + " *([!*$^=]*) *" + qstr + "\\]");
|
|
||||||
var m = re.exec(t);
|
|
||||||
|
|
||||||
|
if ( m ) {
|
||||||
// Re-organize the match
|
// Re-organize the match
|
||||||
if ( m ) m = ["", "@", m[2], m[1], m[3]];
|
if ( jQuery.parseSwap[i] )
|
||||||
|
m = ["", m[1], m[3], m[2], m[4]];
|
||||||
// Handles:
|
|
||||||
// [div], [.foo]
|
|
||||||
if ( !m ) {
|
|
||||||
re = new RegExp("^(\\[)" + qstr + "\\]");
|
|
||||||
m = re.exec(t);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handles:
|
|
||||||
// :contains(test), :not(.foo)
|
|
||||||
if ( !m ) {
|
|
||||||
re = new RegExp("^(:)" + str + "\\(" + qstr + "\\)");
|
|
||||||
m = re.exec(t);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handles:
|
|
||||||
// :foo, .foo, #foo, foo
|
|
||||||
if ( !m ) {
|
|
||||||
re = new RegExp("^([:.#]*)" + str);
|
|
||||||
m = re.exec(t);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove what we just matched
|
// Remove what we just matched
|
||||||
t = t.replace( re, "" );
|
t = t.replace( re, "" );
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// :not() is a special case that can be optomized by
|
// :not() is a special case that can be optomized by
|
||||||
// keeping it out of the expression list
|
// keeping it out of the expression list
|
||||||
if ( m[1] == ":" && m[2] == "not" )
|
if ( m[1] == ":" && m[2] == "not" )
|
||||||
|
Loading…
Reference in New Issue
Block a user