From 3291c70d97de9f521263eb1f566ed0a5d561730e Mon Sep 17 00:00:00 2001 From: David Majda Date: Sun, 11 Apr 2010 11:24:36 +0200 Subject: [PATCH] Added \uFEFF (BOM) to the definition of whitespace in the metagrammar. The Rhino bug that prevented inclusion of \uFEFF among the whitespace characters is no longer relevant here because we compile character classes into regexps now, which avoids the infinite recursion. --- lib/metagrammar.js | 4 ++-- lib/metagrammar.pegjs | 7 ++----- test/metagrammar-test.js | 1 + 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/metagrammar.js b/lib/metagrammar.js index a66b79e..fe4a680 100644 --- a/lib/metagrammar.js +++ b/lib/metagrammar.js @@ -3212,13 +3212,13 @@ PEG.grammarParser = (function(){ var savedReportMatchFailures = context.reportMatchFailures; context.reportMatchFailures = false; - if (this._input.substr(this._pos).match(/^[   ᠎ -    ]/) !== null) { + if (this._input.substr(this._pos).match(/^[   ᠎ -    ]/) !== null) { var result301 = this._input[this._pos]; this._pos++; } else { var result301 = null; if (context.reportMatchFailures) { - this._matchFailed('[' + "   ᠎ -    " + ']'); + this._matchFailed('[' + "   ᠎ -    " + ']'); } } context.reportMatchFailures = savedReportMatchFailures; diff --git a/lib/metagrammar.pegjs b/lib/metagrammar.pegjs index 61baf42..547076c 100644 --- a/lib/metagrammar.pegjs +++ b/lib/metagrammar.pegjs @@ -205,8 +205,5 @@ eol "end of line": "\n" / "\r\n" / "\r" / "\u2028" / "\u2029" eolChar: [\n\r\u2028\u2029] -/* - * Modelled after ECMA-262, 5th ed., 7.2. \uFEFF should be between the - * characters too, but it causes infinite loop in Rhino. - */ -whitespace "whitespace": [ \t\v\f\u00A0\u1680\u180E\u2000-\u200A\u202F\u205F\u3000] +/* Modelled after ECMA-262, 5th ed., 7.2. */ +whitespace "whitespace": [ \t\v\f\u00A0\uFEFF\u1680\u180E\u2000-\u200A\u202F\u205F\u3000] diff --git a/test/metagrammar-test.js b/test/metagrammar-test.js index 4f31ea6..1664eec 100644 --- a/test/metagrammar-test.js +++ b/test/metagrammar-test.js @@ -434,6 +434,7 @@ with (PEG.Grammar) { grammarParserParses('start:\f"abcd"', simpleGrammar); grammarParserParses('start: "abcd"', simpleGrammar); grammarParserParses('start:\u00A0"abcd"', simpleGrammar); + grammarParserParses('start:\uFEFF"abcd"', simpleGrammar); grammarParserParses('start:\u1680"abcd"', simpleGrammar); grammarParserParses('start:\u180E"abcd"', simpleGrammar); grammarParserParses('start:\u2000"abcd"', simpleGrammar);