1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | function ini(hljs) {
|
10 | const regex = hljs.regex;
|
11 | const NUMBERS = {
|
12 | className: 'number',
|
13 | relevance: 0,
|
14 | variants: [
|
15 | {
|
16 | begin: /([+-]+)?[\d]+_[\d_]+/
|
17 | },
|
18 | {
|
19 | begin: hljs.NUMBER_RE
|
20 | }
|
21 | ]
|
22 | };
|
23 | const COMMENTS = hljs.COMMENT();
|
24 | COMMENTS.variants = [
|
25 | {
|
26 | begin: /;/,
|
27 | end: /$/
|
28 | },
|
29 | {
|
30 | begin: /#/,
|
31 | end: /$/
|
32 | }
|
33 | ];
|
34 | const VARIABLES = {
|
35 | className: 'variable',
|
36 | variants: [
|
37 | {
|
38 | begin: /\$[\w\d"][\w\d_]*/
|
39 | },
|
40 | {
|
41 | begin: /\$\{(.*?)\}/
|
42 | }
|
43 | ]
|
44 | };
|
45 | const LITERALS = {
|
46 | className: 'literal',
|
47 | begin: /\bon|off|true|false|yes|no\b/
|
48 | };
|
49 | const STRINGS = {
|
50 | className: "string",
|
51 | contains: [hljs.BACKSLASH_ESCAPE],
|
52 | variants: [
|
53 | {
|
54 | begin: "'''",
|
55 | end: "'''",
|
56 | relevance: 10
|
57 | },
|
58 | {
|
59 | begin: '"""',
|
60 | end: '"""',
|
61 | relevance: 10
|
62 | },
|
63 | {
|
64 | begin: '"',
|
65 | end: '"'
|
66 | },
|
67 | {
|
68 | begin: "'",
|
69 | end: "'"
|
70 | }
|
71 | ]
|
72 | };
|
73 | const ARRAY = {
|
74 | begin: /\[/,
|
75 | end: /\]/,
|
76 | contains: [
|
77 | COMMENTS,
|
78 | LITERALS,
|
79 | VARIABLES,
|
80 | STRINGS,
|
81 | NUMBERS,
|
82 | 'self'
|
83 | ],
|
84 | relevance: 0
|
85 | };
|
86 |
|
87 | const BARE_KEY = /[A-Za-z0-9_-]+/;
|
88 | const QUOTED_KEY_DOUBLE_QUOTE = /"(\\"|[^"])*"/;
|
89 | const QUOTED_KEY_SINGLE_QUOTE = /'[^']*'/;
|
90 | const ANY_KEY = regex.either(
|
91 | BARE_KEY, QUOTED_KEY_DOUBLE_QUOTE, QUOTED_KEY_SINGLE_QUOTE
|
92 | );
|
93 | const DOTTED_KEY = regex.concat(
|
94 | ANY_KEY, '(\\s*\\.\\s*', ANY_KEY, ')*',
|
95 | regex.lookahead(/\s*=\s*[^#\s]/)
|
96 | );
|
97 |
|
98 | return {
|
99 | name: 'TOML, also INI',
|
100 | aliases: ['toml'],
|
101 | case_insensitive: true,
|
102 | illegal: /\S/,
|
103 | contains: [
|
104 | COMMENTS,
|
105 | {
|
106 | className: 'section',
|
107 | begin: /\[+/,
|
108 | end: /\]+/
|
109 | },
|
110 | {
|
111 | begin: DOTTED_KEY,
|
112 | className: 'attr',
|
113 | starts: {
|
114 | end: /$/,
|
115 | contains: [
|
116 | COMMENTS,
|
117 | ARRAY,
|
118 | LITERALS,
|
119 | VARIABLES,
|
120 | STRINGS,
|
121 | NUMBERS
|
122 | ]
|
123 | }
|
124 | }
|
125 | ]
|
126 | };
|
127 | }
|
128 |
|
129 | export { ini as default };
|