Skip to content

Commit 4dde2e2

Browse files
authoredOct 5, 2021
Regex: Fixed char-class/char-set confusion (#3124)
1 parent 09a0e2b commit 4dde2e2

File tree

8 files changed

+91
-93
lines changed

8 files changed

+91
-93
lines changed
 

‎components/prism-regex.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
alias: 'escape'
66
};
77
var escape = /\\(?:x[\da-fA-F]{2}|u[\da-fA-F]{4}|u\{[\da-fA-F]+\}|0[0-7]{0,2}|[123][0-7]{2}|c[a-zA-Z]|.)/;
8-
var charClass = {
8+
var charSet = {
99
pattern: /\.|\\[wsd]|\\p\{[^{}]+\}/i,
1010
alias: 'class-name'
1111
};
12-
var charClassWithoutDot = {
12+
var charSetWithoutDot = {
1313
pattern: /\\[wsd]|\\p\{[^{}]+\}/i,
1414
alias: 'class-name'
1515
};
@@ -25,16 +25,16 @@
2525
};
2626

2727
Prism.languages.regex = {
28-
'charset': {
28+
'char-class': {
2929
pattern: /((?:^|[^\\])(?:\\\\)*)\[(?:[^\\\]]|\\[\s\S])*\]/,
3030
lookbehind: true,
3131
inside: {
32-
'charset-negation': {
32+
'char-class-negation': {
3333
pattern: /(^\[)\^/,
3434
lookbehind: true,
3535
alias: 'operator'
3636
},
37-
'charset-punctuation': {
37+
'char-class-punctuation': {
3838
pattern: /^\[|\]$/,
3939
alias: 'punctuation'
4040
},
@@ -49,12 +49,12 @@
4949
}
5050
},
5151
'special-escape': specialEscape,
52-
'charclass': charClassWithoutDot,
52+
'char-set': charSetWithoutDot,
5353
'escape': escape
5454
}
5555
},
5656
'special-escape': specialEscape,
57-
'charclass': charClass,
57+
'char-set': charSet,
5858
'backreference': [
5959
{
6060
// a backreference which is not an octal escape

‎components/prism-regex.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎tests/languages/javascript!+regex/regex_inclusion.test

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@
99
"a",
1010
["quantifier", "+"],
1111
["group", ["(?:"]],
12-
["charset", [
13-
["charset-punctuation", "["],
12+
["char-class", [
13+
["char-class-punctuation", "["],
1414
["range", [
1515
"a",
1616
["range-punctuation", "-"],
1717
"z"
1818
]],
19-
["charset-punctuation", "]"]
19+
["char-class-punctuation", "]"]
2020
]],
2121
["alternation", "|"],
22-
["charclass", "\\d"],
22+
["char-set", "\\d"],
2323
["group", ")"],
2424
["quantifier", "?"]
2525
]],
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
[]
2+
[^]
3+
[foo]
4+
[\]\b]
5+
[.^$\1]
6+
[\d\D\p{L}]
7+
8+
----------------------------------------------------
9+
10+
[
11+
["char-class", [
12+
["char-class-punctuation", "["],
13+
["char-class-punctuation", "]"]
14+
]],
15+
["char-class", [
16+
["char-class-punctuation", "["],
17+
["char-class-negation", "^"],
18+
["char-class-punctuation", "]"]
19+
]],
20+
["char-class", [
21+
["char-class-punctuation", "["],
22+
"foo",
23+
["char-class-punctuation", "]"]
24+
]],
25+
["char-class", [
26+
["char-class-punctuation", "["],
27+
["special-escape", "\\]"],
28+
["escape", "\\b"],
29+
["char-class-punctuation", "]"]
30+
]],
31+
["char-class", [
32+
["char-class-punctuation", "["],
33+
".^$",
34+
["escape", "\\1"],
35+
["char-class-punctuation", "]"]
36+
]],
37+
["char-class", [
38+
["char-class-punctuation", "["],
39+
["char-set", "\\d"],
40+
["char-set", "\\D"],
41+
["char-set", "\\p{L}"],
42+
["char-class-punctuation", "]"]
43+
]]
44+
]
45+
46+
----------------------------------------------------
47+
48+
Checks for character sets.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
.
2+
\w \W
3+
\s \S
4+
\d \D
5+
\p{ASCII}
6+
\P{ASCII}
7+
8+
----------------------------------------------------
9+
10+
[
11+
["char-set", "."],
12+
["char-set", "\\w"], ["char-set", "\\W"],
13+
["char-set", "\\s"], ["char-set", "\\S"],
14+
["char-set", "\\d"], ["char-set", "\\D"],
15+
["char-set", "\\p{ASCII}"],
16+
["char-set", "\\P{ASCII}"]
17+
]
18+
19+
----------------------------------------------------
20+
21+
Checks for character classes.

‎tests/languages/regex/charclass_feature.test

-25
This file was deleted.

‎tests/languages/regex/charset_feature.test

-44
This file was deleted.

‎tests/languages/regex/range_feature.test

+10-12
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
----------------------------------------------------
66

77
[
8-
["charset", [
9-
["charset-punctuation", "["],
8+
["char-class", [
9+
["char-class-punctuation", "["],
1010
["range", [
1111
"a",
1212
["range-punctuation", "-"],
@@ -22,11 +22,10 @@
2222
["range-punctuation", "-"],
2323
"9"
2424
]],
25-
["charset-punctuation", "]"]
25+
["char-class-punctuation", "]"]
2626
]],
27-
28-
["charset", [
29-
["charset-punctuation", "["],
27+
["char-class", [
28+
["char-class-punctuation", "["],
3029
["range", [
3130
["escape", "\\xa1"],
3231
["range-punctuation", "-"],
@@ -37,14 +36,13 @@
3736
["range-punctuation", "-"],
3837
["escape", "\\u{256}"]
3938
]],
40-
["charset-punctuation", "]"]
39+
["char-class-punctuation", "]"]
4140
]],
42-
43-
["charset", [
44-
["charset-punctuation", "["],
45-
["charset-negation", "^"],
41+
["char-class", [
42+
["char-class-punctuation", "["],
43+
["char-class-negation", "^"],
4644
"-aaa-",
47-
["charset-punctuation", "]"]
45+
["char-class-punctuation", "]"]
4846
]]
4947
]
5048

0 commit comments

Comments
 (0)
Please sign in to comment.