-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds a Regex language that adds itself to a few languages which have regex literals.
- Loading branch information
1 parent
5712770
commit 571704c
Showing
13 changed files
with
433 additions
and
1 deletion.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
(function (Prism) { | ||
|
||
var specialEscape = { | ||
pattern: /\\[\\(){}[\]^$+*?|.]/, | ||
alias: 'escape' | ||
}; | ||
var escape = /\\(?:x[\da-fA-F]{2}|u[\da-fA-F]{4}|u\{[\da-fA-F]+\}|c[a-zA-Z]|0[0-7]{0,2}|[123][0-7]{2}|.)/ | ||
var charClass = /\\[wsd]|\.|\\p{[^{}]+}/i | ||
|
||
var rangeChar = '(?:[^\\\\-]|' + escape.source + ')'; | ||
var range = RegExp(rangeChar + '-' + rangeChar); | ||
|
||
// the name of a capturing group | ||
var groupName = { | ||
pattern: /(<|')[^<>']+(?=[>']$)/, | ||
lookbehind: true, | ||
alias: 'variable' | ||
}; | ||
|
||
var backreference = [ | ||
/\\(?![123][0-7]{2})[1-9]/, // a backreference which is not an octal escape | ||
{ | ||
pattern: /\\k<[^<>']+>/, | ||
inside: { | ||
'group-name': groupName | ||
} | ||
} | ||
]; | ||
|
||
Prism.languages.regex = { | ||
'charset': { | ||
pattern: /((?:^|[^\\])(?:\\\\)*)\[(?:[^\\\]]|\\[\s\S])*\]/, | ||
lookbehind: true, | ||
inside: { | ||
'charset-negation': { | ||
pattern: /(^\[)\^/, | ||
lookbehind: true, | ||
}, | ||
'charset-punctuation': /^\[|\]$/, | ||
'range': { | ||
pattern: range, | ||
inside: { | ||
'escape': escape, | ||
'range-punctuation': /-/ | ||
} | ||
}, | ||
'special-escape': specialEscape, | ||
'charclass': charClass, | ||
'backreference': backreference, | ||
'escape': escape | ||
} | ||
}, | ||
'special-escape': specialEscape, | ||
'charclass': charClass, | ||
'backreference': backreference, | ||
'anchor': /[$^]|\\[ABbGZz]/, | ||
'escape': escape, | ||
'group': [ | ||
{ | ||
// https://docs.oracle.com/javase/10/docs/api/java/util/regex/Pattern.html | ||
// https://docs.microsoft.com/en-us/dotnet/standard/base-types/regular-expression-language-quick-reference?view=netframework-4.7.2#grouping-constructs | ||
|
||
// (), (?<name>), (?'name'), (?>), (?:), (?=), (?!), (?<=), (?<!), (?is-m), (?i-m:) | ||
pattern: /\((?:\?(?:<[^<>']+>|'[^<>']+'|[>:]|<?[=!]|[idmnsuxU]+(?:-[idmnsuxU]+)?:?))?/, | ||
inside: { | ||
'group-name': groupName | ||
} | ||
}, | ||
/\)/ | ||
], | ||
'quantifier': /[+*?]|\{(?:\d+,?\d*)\}/, | ||
'alternation': /\|/ | ||
}; | ||
|
||
|
||
[ | ||
'actionscript', | ||
'coffescript', | ||
'flow', | ||
'javascript', | ||
'typescript', | ||
'vala' | ||
].forEach(function (lang) { | ||
var grammar = Prism.languages[lang]; | ||
if (grammar) { | ||
grammar['regex'].inside = { | ||
'regex-flags': /[a-z]+$/, | ||
'regex-delimiter': /^\/|\/$/, | ||
'language-regex': { | ||
pattern: /[\s\S]+/, | ||
inside: Prism.languages.regex | ||
} | ||
}; | ||
} | ||
}); | ||
|
||
}(Prism)) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/a+(?:[a-z]|\d)?/im; | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["regex", [ | ||
["regex-delimiter", "/"], | ||
["language-regex", [ | ||
"a", | ||
["quantifier", "+"], | ||
["group", ["(?:"]], | ||
["charset", [ | ||
["charset-punctuation", "["], | ||
["range", [ | ||
"a", | ||
["range-punctuation", "-"], | ||
"z" | ||
]], | ||
["charset-punctuation", "]"] | ||
]], | ||
["alternation", "|"], | ||
["charclass", "\\d"], | ||
["group", ")"], | ||
["quantifier", "?"] | ||
]], | ||
["regex-delimiter", "/"], | ||
["regex-flags", "im"] | ||
]], | ||
["punctuation", ";"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for regex inclusion in JavaScript. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
^ | ||
$ | ||
\A | ||
\G | ||
\Z | ||
\z | ||
\b | ||
\B | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["anchor", "^"], | ||
["anchor", "$"], | ||
["anchor", "\\A"], | ||
["anchor", "\\G"], | ||
["anchor", "\\Z"], | ||
["anchor", "\\z"], | ||
["anchor", "\\b"], | ||
["anchor", "\\B"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for anchors. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
\1 \2 \3 \4 \5 \6 \7 \8 \9 | ||
\k<name> | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["backreference", "\\1"], | ||
["backreference", "\\2"], | ||
["backreference", "\\3"], | ||
["backreference", "\\4"], | ||
["backreference", "\\5"], | ||
["backreference", "\\6"], | ||
["backreference", "\\7"], | ||
["backreference", "\\8"], | ||
["backreference", "\\9"], | ||
|
||
["backreference", [ | ||
"\\k<", | ||
["group-name", "name"], | ||
">" | ||
]] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for backreferences. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
. | ||
\w \W | ||
\s \S | ||
\d \D | ||
\p{ASCII} | ||
\P{ASCII} | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["charclass", "."], | ||
["charclass", "\\w"], | ||
["charclass", "\\W"], | ||
["charclass", "\\s"], | ||
["charclass", "\\S"], | ||
["charclass", "\\d"], | ||
["charclass", "\\D"], | ||
|
||
["charclass", "\\p{ASCII}"], | ||
["charclass", "\\P{ASCII}"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for character classes. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
[] | ||
[^] | ||
[foo] | ||
[\]\b] | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["charset", [ | ||
["charset-punctuation", "["], | ||
["charset-punctuation", "]"] | ||
]], | ||
|
||
["charset", [ | ||
["charset-punctuation", "["], | ||
["charset-negation", "^"], | ||
["charset-punctuation", "]"] | ||
]], | ||
|
||
["charset", [ | ||
["charset-punctuation", "["], | ||
"foo", | ||
["charset-punctuation", "]"] | ||
]], | ||
|
||
["charset", [ | ||
["charset-punctuation", "["], | ||
["special-escape", "\\]"], | ||
["escape", "\\b"], | ||
["charset-punctuation", "]"] | ||
]] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for character sets. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
\0 \\ \. \+ | ||
\xFF | ||
\uFFFF \u{10FFFF} | ||
\cA \cZ | ||
\01 \077 \377 | ||
\n \r \t \f \a | ||
|
||
\[ \] | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["escape", "\\0"], | ||
["special-escape", "\\\\"], | ||
["special-escape", "\\."], | ||
["special-escape", "\\+"], | ||
|
||
["escape", "\\xFF"], | ||
|
||
["escape", "\\uFFFF"], | ||
["escape", "\\u{10FFFF}"], | ||
|
||
["escape", "\\cA"], | ||
["escape", "\\cZ"], | ||
|
||
["escape", "\\01"], | ||
["escape", "\\077"], | ||
["escape", "\\377"], | ||
|
||
["escape", "\\n"], | ||
["escape", "\\r"], | ||
["escape", "\\t"], | ||
["escape", "\\f"], | ||
["escape", "\\a"], | ||
|
||
["special-escape", "\\["], | ||
["special-escape", "\\]"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for escapes. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
() | ||
(?:) | ||
(?>) | ||
(?=) (?!) | ||
(?<=) (?<!) | ||
|
||
(?<name>) | ||
(?'name') | ||
|
||
(?i) | ||
(?i:) | ||
(?idmsuxU-idmsuxU) | ||
(?idmsux-idmsux:X) | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["group", ["("]], | ||
["group", ")"], | ||
|
||
["group", ["(?:"]], | ||
["group", ")"], | ||
|
||
["group", ["(?>"]], | ||
["group", ")"], | ||
|
||
["group", ["(?="]], | ||
["group", ")"], | ||
["group", ["(?!"]], | ||
["group", ")"], | ||
|
||
["group", ["(?<="]], | ||
["group", ")"], | ||
["group", ["(?<!"]], | ||
["group", ")"], | ||
|
||
["group", [ | ||
"(?<", | ||
["group-name", "name"], | ||
">"] | ||
], | ||
["group", ")"], | ||
|
||
["group", [ | ||
"(?'", | ||
["group-name", "name"], | ||
"'"] | ||
], | ||
["group", ")"], | ||
|
||
["group", ["(?i"]], | ||
["group", ")"], | ||
["group", ["(?i:"]], | ||
["group", ")"], | ||
["group", ["(?idmsuxU-idmsuxU"]], | ||
["group", ")"], | ||
["group", ["(?idmsux-idmsux:"]], | ||
"X", | ||
["group", ")"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for groups. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
* + ? | ||
{2} {2,} {0,1} | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["quantifier", "*"], | ||
["quantifier", "+"], | ||
["quantifier", "?"], | ||
["quantifier", "{2}"], | ||
["quantifier", "{2,}"], | ||
["quantifier", "{0,1}"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for quantifiers. |
Oops, something went wrong.