-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgrammar_json.ts
More file actions
38 lines (36 loc) · 877 Bytes
/
grammar_json.ts
File metadata and controls
38 lines (36 loc) · 877 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import type {AddSyntaxGrammar, SyntaxGrammarRaw} from './syntax_styler.js';
/**
* Based on Prism (https://github.com/PrismJS/prism)
* by Lea Verou (https://lea.verou.me/)
*
* MIT license
*
* @see LICENSE
*/
export const add_grammar_json: AddSyntaxGrammar = (syntax_styler) => {
const grammar_json = {
property: {
pattern: /(^|[^\\])"(?:\\.|[^\\"\r\n])*"(?=\s*:)/,
lookbehind: true,
greedy: true,
},
string: {
pattern: /(^|[^\\])"(?:\\.|[^\\"\r\n])*"(?!\s*:)/,
lookbehind: true,
greedy: true,
},
comment: {
pattern: /\/\/.*|\/\*[\s\S]*?(?:\*\/|$)/,
greedy: true,
},
number: /-?\b\d+(?:\.\d+)?(?:e[+-]?\d+)?\b/i,
punctuation: /[{}[\],]/,
operator: /:/,
boolean: /\b(?:false|true)\b/,
null: {
pattern: /\bnull\b/,
alias: 'keyword',
},
} satisfies SyntaxGrammarRaw;
syntax_styler.add_lang('json', grammar_json);
};