Made regexps generated for empty character classes ("[]" and "[^]") work in IE.
This commit is contained in:
parent
e79e869993
commit
6abda95a99
|
@ -734,6 +734,18 @@ PEG.Grammar.Literal.prototype.compile = function(resultVar) {
|
||||||
};
|
};
|
||||||
|
|
||||||
PEG.Grammar.Class.prototype.compile = function(resultVar) {
|
PEG.Grammar.Class.prototype.compile = function(resultVar) {
|
||||||
|
/*
|
||||||
|
* Stupid IE considers regexps /[]/ and /[^]/ syntactically invalid, so we
|
||||||
|
* translate them into euqivalents it can handle.
|
||||||
|
*/
|
||||||
|
if (this._characters === "") {
|
||||||
|
var regexp = "/^(?!)/";
|
||||||
|
} else if (this._characters === "^") {
|
||||||
|
var regexp = "/^[\\S\\s]/";
|
||||||
|
} else {
|
||||||
|
var regexp = "/^[" + this._characters + "]/";
|
||||||
|
}
|
||||||
|
|
||||||
return PEG.Compiler.formatCode(
|
return PEG.Compiler.formatCode(
|
||||||
"if (this._input.substr(this._pos).match(${regexp}) !== null) {",
|
"if (this._input.substr(this._pos).match(${regexp}) !== null) {",
|
||||||
" var ${resultVar} = this._input[this._pos];",
|
" var ${resultVar} = this._input[this._pos];",
|
||||||
|
@ -746,7 +758,7 @@ PEG.Grammar.Class.prototype.compile = function(resultVar) {
|
||||||
"}",
|
"}",
|
||||||
{
|
{
|
||||||
characters: this._characters,
|
characters: this._characters,
|
||||||
regexp: "/^[" + this._characters + "]/",
|
regexp: regexp,
|
||||||
resultVar: resultVar
|
resultVar: resultVar
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue