@robot-inventor/regex-syntax 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 ろぼいん
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # regex-syntax
2
+
3
+ Grammar files for syntax highlight of regex. The grammar files are automatically generated from [Linguist](https://github.com/github-linguist/linguist/)'s regex grammars.
4
+
5
+ > [!NOTE]
6
+ > You may also be interested in [shell-session-syntax](https://github.com/Robot-Inventor/shell-session-syntax/) for syntax highlight of shell sessions.
7
+
8
+ |Before|After|
9
+ |:---:|:---:|
10
+ |![before](docs/without-regex-syntax.png)|![after](docs/regex-syntax.png)|
11
+
12
+ ## Usage
13
+
14
+ To use regex-syntax in [Shiki.js](https://shiki.style/), please download ``./syntaxes/regex.tmLanguage.json`` and load it as a custom language grammar. Language name is ``regex`` and ``regexp``.
15
+
16
+ ```javascript
17
+ import { getHighlighter } from "shiki";
18
+ import regex from "./regex.tmLanguage.json" assert { type: "json" };
19
+
20
+ const code = `
21
+ ^[a-zA-Z0-9.!#$%&'*+/=?^_\`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$
22
+ `.trim();
23
+
24
+ const highlighter = await getHighlighter({
25
+ langs: [regex],
26
+ themes: ["vitesse-dark"]
27
+ });
28
+
29
+ const html = highlighter.codeToHtml(code, {
30
+ lang: "regex",
31
+ theme: "vitesse-dark"
32
+ });
33
+
34
+ console.log(html);
35
+ ```
36
+
37
+ ## Update Grammar
38
+
39
+ To update the grammar file, run the following command. It automatically downloads the latest upstream grammar files and applies patches.
40
+
41
+ ```bash
42
+ npm run build
43
+ ```
44
+
45
+ ## Grammar Sources
46
+
47
+ regex-syntax is generated by automatically applying patches to the following grammar file.
48
+
49
+ - [Linguist](https://github.com/github-linguist/linguist/) ([MIT License](https://github.com/github-linguist/linguist/blob/master/LICENSE))
@@ -0,0 +1,3 @@
1
+ import type { LanguageRegistration } from "shiki";
2
+ declare const _default: LanguageRegistration;
3
+ export default _default;
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ import grammar from "../syntaxes/regex.tmLanguage.json" assert { type: "json" };
2
+ export default grammar;
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@robot-inventor/regex-syntax",
3
+ "version": "1.0.3",
4
+ "description": "Grammar files for syntax highlight of regex.",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "type": "module",
8
+ "files": [
9
+ "dist",
10
+ "syntaxes"
11
+ ],
12
+ "scripts": {
13
+ "test": "echo \"Error: no test specified\" && exit 1",
14
+ "build": "ts-node ./scripts/generate.ts && tsc"
15
+ },
16
+ "publishConfig": {
17
+ "access": "public"
18
+ },
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/Robot-Inventor/regex-syntax.git"
22
+ },
23
+ "author": "Robot-Inventor",
24
+ "license": "MIT",
25
+ "bugs": {
26
+ "url": "https://github.com/Robot-Inventor/regex-syntax/issues"
27
+ },
28
+ "homepage": "https://github.com/Robot-Inventor/regex-syntax#readme",
29
+ "devDependencies": {
30
+ "rss-parser": "^3.13.0",
31
+ "tar": "^7.0.0",
32
+ "ts-node": "^10.9.2",
33
+ "typescript": "^5.4.2"
34
+ },
35
+ "dependencies": {
36
+ "shiki": "^1.3.0"
37
+ }
38
+ }
@@ -0,0 +1,167 @@
1
+ {
2
+ "information_for_contributors": [
3
+ "This file is autogenerated. Do not edit it manually. Instead, edit the `generate.ts` script and run it.",
4
+ "Sources for this file are:",
5
+ "https://github.com/github-linguist/linguist/"
6
+ ],
7
+ "lastUpdated": "2024-04-29T00:57:43.416Z",
8
+ "regexGrammarVersion": "v7.29.0",
9
+ "name": "regex",
10
+ "aliases": [
11
+ "regexp"
12
+ ],
13
+ "scopeName": "text.regex",
14
+ "patterns": [
15
+ {
16
+ "include": "#regexp"
17
+ }
18
+ ],
19
+ "repository": {
20
+ "regex-character-class": {
21
+ "patterns": [
22
+ {
23
+ "name": "constant.character.character-class.regexp",
24
+ "match": "\\\\[wWsSdDtrnvf]|\\."
25
+ },
26
+ {
27
+ "name": "constant.character.numeric.regexp",
28
+ "match": "\\\\([0-7]{3}|x[0-9A-Fa-f]{2}|u[0-9A-Fa-f]{4})"
29
+ },
30
+ {
31
+ "name": "constant.character.control.regexp",
32
+ "match": "\\\\c[A-Z]"
33
+ },
34
+ {
35
+ "name": "constant.character.escape.backslash.regexp",
36
+ "match": "\\\\."
37
+ }
38
+ ]
39
+ },
40
+ "regexp": {
41
+ "patterns": [
42
+ {
43
+ "name": "keyword.control.anchor.regexp",
44
+ "match": "\\\\[bB]|\\^|\\$"
45
+ },
46
+ {
47
+ "name": "keyword.other.back-reference.regexp",
48
+ "match": "\\\\[1-9]\\d*|\\\\k<[a-zA-Z_$][\\w$]*>"
49
+ },
50
+ {
51
+ "name": "keyword.operator.quantifier.regexp",
52
+ "match": "[?+*]|\\{(\\d+,\\d+|\\d+,|,\\d+|\\d+)\\}\\??"
53
+ },
54
+ {
55
+ "name": "keyword.operator.or.regexp",
56
+ "match": "\\|"
57
+ },
58
+ {
59
+ "name": "meta.group.assertion.regexp",
60
+ "begin": "(\\()(?:(\\?=)|(\\?!)|(\\?<=)|(\\?<!))",
61
+ "end": "(\\))",
62
+ "patterns": [
63
+ {
64
+ "include": "#regexp"
65
+ }
66
+ ],
67
+ "beginCaptures": {
68
+ "1": {
69
+ "name": "punctuation.definition.group.regexp"
70
+ },
71
+ "2": {
72
+ "name": "meta.assertion.look-ahead.regexp"
73
+ },
74
+ "3": {
75
+ "name": "meta.assertion.negative-look-ahead.regexp"
76
+ },
77
+ "4": {
78
+ "name": "meta.assertion.look-behind.regexp"
79
+ },
80
+ "5": {
81
+ "name": "meta.assertion.negative-look-behind.regexp"
82
+ }
83
+ },
84
+ "endCaptures": {
85
+ "1": {
86
+ "name": "punctuation.definition.group.regexp"
87
+ }
88
+ }
89
+ },
90
+ {
91
+ "name": "meta.group.regexp",
92
+ "begin": "\\(((\\?:)|(\\?<[a-zA-Z_$][\\w$]*>))?",
93
+ "end": "\\)",
94
+ "patterns": [
95
+ {
96
+ "include": "#regexp"
97
+ }
98
+ ],
99
+ "beginCaptures": {
100
+ "0": {
101
+ "name": "punctuation.definition.group.regexp"
102
+ }
103
+ },
104
+ "endCaptures": {
105
+ "0": {
106
+ "name": "punctuation.definition.group.regexp"
107
+ }
108
+ }
109
+ },
110
+ {
111
+ "name": "constant.other.character-class.set.regexp",
112
+ "begin": "(\\[)(\\^)?",
113
+ "end": "(\\])",
114
+ "patterns": [
115
+ {
116
+ "name": "constant.other.character-class.range.regexp",
117
+ "match": "(?:.|(\\\\(?:[0-7]{3}|x[0-9A-Fa-f]{2}|u[0-9A-Fa-f]{4}))|(\\\\c[A-Z])|(\\\\.))\\-(?:[^\\]\\\\]|(\\\\(?:[0-7]{3}|x[0-9A-Fa-f]{2}|u[0-9A-Fa-f]{4}))|(\\\\c[A-Z])|(\\\\.))",
118
+ "captures": {
119
+ "1": {
120
+ "name": "constant.character.numeric.regexp"
121
+ },
122
+ "2": {
123
+ "name": "constant.character.control.regexp"
124
+ },
125
+ "3": {
126
+ "name": "constant.character.escape.backslash.regexp"
127
+ },
128
+ "4": {
129
+ "name": "constant.character.numeric.regexp"
130
+ },
131
+ "5": {
132
+ "name": "constant.character.control.regexp"
133
+ },
134
+ "6": {
135
+ "name": "constant.character.escape.backslash.regexp"
136
+ }
137
+ }
138
+ },
139
+ {
140
+ "include": "#regex-character-class"
141
+ }
142
+ ],
143
+ "beginCaptures": {
144
+ "1": {
145
+ "name": "punctuation.definition.character-class.regexp"
146
+ },
147
+ "2": {
148
+ "name": "keyword.operator.negation.regexp"
149
+ }
150
+ },
151
+ "endCaptures": {
152
+ "1": {
153
+ "name": "punctuation.definition.character-class.regexp"
154
+ }
155
+ }
156
+ },
157
+ {
158
+ "include": "#regex-character-class"
159
+ },
160
+ {
161
+ "match": ".",
162
+ "name": "string.regexp"
163
+ }
164
+ ]
165
+ }
166
+ }
167
+ }