Skip to content

Commit 0054335

Browse files
committed
1 parent 754c614 commit 0054335

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

src/parser/__tests__/parser-basic-test.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,38 @@ describe('basic', () => {
135135
},
136136
flags: 'i',
137137
});
138+
139+
expect(re(/[a\-z]/u)).toEqual({
140+
type: 'RegExp',
141+
body: {
142+
type: 'CharacterClass',
143+
expressions: [
144+
{
145+
type: 'Char',
146+
value: 'a',
147+
symbol: 'a',
148+
kind: 'simple',
149+
codePoint: 'a'.codePointAt(0),
150+
},
151+
{
152+
type: 'Char',
153+
value: '-',
154+
symbol: '-',
155+
kind: 'simple',
156+
escaped: true,
157+
codePoint: '-'.codePointAt(0),
158+
},
159+
{
160+
type: 'Char',
161+
value: 'z',
162+
symbol: 'z',
163+
kind: 'simple',
164+
codePoint: 'z'.codePointAt(0),
165+
},
166+
],
167+
},
168+
flags: 'u',
169+
});
138170
});
139171

140172
it('empty class', () => {

src/parser/generated/regexp-tree.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,10 @@ const lexRules = [[/^#[^\n]+/, function() { /* skip comments */ }],
374374
[/^\\[\^\$\.\*\+\?\(\)\\\[\]\{\}\|\/]/, function() { return 'ESC_CHAR' }],
375375
[/^\\[^*?+\[()\\|]/, function() {
376376
const s = this.getCurrentState();
377-
if (s === 'u' || s === 'xu' || s === 'u_class') {
377+
if (s === 'u_class' && yytext === "\\-") {
378+
return 'ESC_CHAR';
379+
}
380+
else if (s === 'u' || s === 'xu' || s === 'u_class') {
378381
throw new SyntaxError(`invalid Unicode escape ${yytext}`);
379382
}
380383
return 'ESC_CHAR';

src/parser/regexp.bnf

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,10 @@ NAME \w+
128128

129129
{ESC}{CHAR} {
130130
const s = this.getCurrentState();
131-
if (s === 'u' || s === 'xu' || s === 'u_class') {
131+
if (s === 'u_class' && yytext === "\\-") {
132+
return 'ESC_CHAR';
133+
}
134+
else if (s === 'u' || s === 'xu' || s === 'u_class') {
132135
throw new SyntaxError(`invalid Unicode escape ${yytext}`);
133136
}
134137
return 'ESC_CHAR';

0 commit comments

Comments
 (0)