Skip to content
Permalink
Browse files
Regex: Fixed char-class/char-set confusion (#3124)
  • Loading branch information
RunDevelopment committed Oct 5, 2021
1 parent 09a0e2b commit 4dde2e20e68b8d91a1cfb01020954e473522696c
@@ -5,11 +5,11 @@
alias: 'escape'
};
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]|.)/;
var charClass = {
var charSet = {
pattern: /\.|\\[wsd]|\\p\{[^{}]+\}/i,
alias: 'class-name'
};
var charClassWithoutDot = {
var charSetWithoutDot = {
pattern: /\\[wsd]|\\p\{[^{}]+\}/i,
alias: 'class-name'
};
@@ -25,16 +25,16 @@
};

Prism.languages.regex = {
'charset': {
'char-class': {
pattern: /((?:^|[^\\])(?:\\\\)*)\[(?:[^\\\]]|\\[\s\S])*\]/,
lookbehind: true,
inside: {
'charset-negation': {
'char-class-negation': {
pattern: /(^\[)\^/,
lookbehind: true,
alias: 'operator'
},
'charset-punctuation': {
'char-class-punctuation': {
pattern: /^\[|\]$/,
alias: 'punctuation'
},
@@ -49,12 +49,12 @@
}
},
'special-escape': specialEscape,
'charclass': charClassWithoutDot,
'char-set': charSetWithoutDot,
'escape': escape
}
},
'special-escape': specialEscape,
'charclass': charClass,
'char-set': charSet,
'backreference': [
{
// a backreference which is not an octal escape

Some generated files are not rendered by default. Learn more.

@@ -9,17 +9,17 @@
"a",
["quantifier", "+"],
["group", ["(?:"]],
["charset", [
["charset-punctuation", "["],
["char-class", [
["char-class-punctuation", "["],
["range", [
"a",
["range-punctuation", "-"],
"z"
]],
["charset-punctuation", "]"]
["char-class-punctuation", "]"]
]],
["alternation", "|"],
["charclass", "\\d"],
["char-set", "\\d"],
["group", ")"],
["quantifier", "?"]
]],
@@ -0,0 +1,48 @@
[]
[^]
[foo]
[\]\b]
[.^$\1]
[\d\D\p{L}]

----------------------------------------------------

[
["char-class", [
["char-class-punctuation", "["],
["char-class-punctuation", "]"]
]],
["char-class", [
["char-class-punctuation", "["],
["char-class-negation", "^"],
["char-class-punctuation", "]"]
]],
["char-class", [
["char-class-punctuation", "["],
"foo",
["char-class-punctuation", "]"]
]],
["char-class", [
["char-class-punctuation", "["],
["special-escape", "\\]"],
["escape", "\\b"],
["char-class-punctuation", "]"]
]],
["char-class", [
["char-class-punctuation", "["],
".^$",
["escape", "\\1"],
["char-class-punctuation", "]"]
]],
["char-class", [
["char-class-punctuation", "["],
["char-set", "\\d"],
["char-set", "\\D"],
["char-set", "\\p{L}"],
["char-class-punctuation", "]"]
]]
]

----------------------------------------------------

Checks for character sets.
@@ -0,0 +1,21 @@
.
\w \W
\s \S
\d \D
\p{ASCII}
\P{ASCII}

----------------------------------------------------

[
["char-set", "."],
["char-set", "\\w"], ["char-set", "\\W"],
["char-set", "\\s"], ["char-set", "\\S"],
["char-set", "\\d"], ["char-set", "\\D"],
["char-set", "\\p{ASCII}"],
["char-set", "\\P{ASCII}"]
]

----------------------------------------------------

Checks for character classes.

This file was deleted.

This file was deleted.

@@ -5,8 +5,8 @@
----------------------------------------------------

[
["charset", [
["charset-punctuation", "["],
["char-class", [
["char-class-punctuation", "["],
["range", [
"a",
["range-punctuation", "-"],
@@ -22,11 +22,10 @@
["range-punctuation", "-"],
"9"
]],
["charset-punctuation", "]"]
["char-class-punctuation", "]"]
]],

["charset", [
["charset-punctuation", "["],
["char-class", [
["char-class-punctuation", "["],
["range", [
["escape", "\\xa1"],
["range-punctuation", "-"],
@@ -37,14 +36,13 @@
["range-punctuation", "-"],
["escape", "\\u{256}"]
]],
["charset-punctuation", "]"]
["char-class-punctuation", "]"]
]],

["charset", [
["charset-punctuation", "["],
["charset-negation", "^"],
["char-class", [
["char-class-punctuation", "["],
["char-class-negation", "^"],
"-aaa-",
["charset-punctuation", "]"]
["char-class-punctuation", "]"]
]]
]

0 comments on commit 4dde2e2

Please sign in to comment.