Skip to content
This repository was archived by the owner on Dec 17, 2018. It is now read-only.

Commit 6bbcd4d

Browse files
nkovacsSlexAxton
authored andcommitted
ICU compatible definition of whitespace and id (#6)
Fixes #5
1 parent 92aea80 commit 6bbcd4d

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

parser.pegjs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{
22
var inPlural = false;
3+
var whitespaceChars = "[\u0009-\u000d \u0085\u200e\u200f\u2028\u2029]*";
4+
var whitespaceTrimRE = new RegExp("^" + whitespaceChars + "|" + whitespaceChars + "$", "g");
35
}
46

57
start = token*
@@ -51,7 +53,8 @@ function = '{' _ arg:id _ ',' _ key:(m:id { if (options.strictNumberSign) { inPl
5153
};
5254
}
5355

54-
id = $([0-9a-zA-Z$_][^ \t\n\r,.+={}]*)
56+
// not Pattern_Syntax or Pattern_White_Space
57+
id = $([^\u0009-\u000d \u0085\u200e\u200f\u2028\u2029\u0021-\u002f\u003a-\u0040\u005b-\u005e\u0060\u007b-\u007e\u00a1-\u00a7\u00a9\u00ab\u00ac\u00ae\u00b0\u00b1\u00b6\u00bb\u00bf\u00d7\u00f7\u2010-\u2027\u2030-\u203e\u2041-\u2053\u2055-\u205e\u2190-\u245f\u2500-\u2775\u2794-\u2bff\u2e00-\u2e7f\u3001-\u3003\u3008-\u3020\u3030\ufd3e\ufd3f\ufe45\ufe46]+)
5558

5659
paramDefault = str:paramcharsDefault+ { return str.join(''); }
5760

@@ -75,7 +78,7 @@ functionParams
7578

7679
functionParamsStrict = _ ',' p:paramStrict { return p; }
7780

78-
functionParamsDefault = _ ',' _ p:paramDefault _ { return p.replace(/^[ \t\n\r]*|[ \t\n\r]*$/g, ''); }
81+
functionParamsDefault = _ ',' _ p:paramDefault _ { return p.replace(whitespaceTrimRE, ''); }
7982

8083
doubleapos = "''" { return "'"; }
8184

@@ -123,4 +126,5 @@ digits = $([0-9]+)
123126

124127
hexDigit = [0-9a-fA-F]
125128

126-
_ = $([ \t\n\r]*)
129+
// Pattern_White_Space
130+
_ = $([\u0009-\u000d \u0085\u200e\u200f\u2028\u2029]*)

test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,11 @@ describe("Errors", function() {
469469

470470
it("shouldn't allow characters in variables that aren't valid JavaScript identifiers", function() {
471471
expect(function(){ parse('{☺}'); }).to.throwError();
472+
expect(function(){ parse('{a☺}'); }).to.throwError();
473+
});
474+
475+
it("should allow characters in variables that are valid ICU identifiers", function() {
476+
expect(function(){ parse('{ű\u3000á}'); }).to.not.throwError();
472477
});
473478

474479
it("should allow positional variables", function() {

0 commit comments

Comments
 (0)