forked from highlightjs/highlight.js
-
Notifications
You must be signed in to change notification settings - Fork 14
/
bicep.js
159 lines (158 loc) · 4.26 KB
/
bicep.js
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/*
Language: Bicep
Contributors: Anthony Martin (anthony.ct.martin@gmail.com)
Category: common
Origin: https://github.com/Azure/bicep/blob/73e9b16ada824e39bbbfce025979d8def9d4ede3/src/highlightjs/src/bicep.ts
*/
function bicep(hljs) {
var bounded = function (text) { return "\\b" + text + "\\b"; };
var after = function (regex) { return "(?<=" + regex + ")"; };
var notAfter = function (regex) { return "(?<!" + regex + ")"; };
var before = function (regex) { return "(?=" + regex + ")"; };
var notBefore = function (regex) { return "(?!" + regex + ")"; };
var identifierStart = "[_a-zA-Z]";
var identifierContinue = "[_a-zA-Z0-9]";
var identifier = bounded("" + identifierStart + identifierContinue + "*");
// whitespace. ideally we'd tokenize in-line block comments, but that's a lot of work. For now, ignore them.
var ws = "(?:[ \\t\\r\\n]|\\/\\*(?:\\*(?!\\/)|[^*])*\\*\\/)*";
var KEYWORDS = {
$pattern: '[A-Za-z$_][0-9A-Za-z$_]*',
keyword: [
'targetScope',
'resource',
'module',
'param',
'var',
'output',
'for',
'in',
'if',
'existing',
].join(' '),
literal: [
"true",
"false",
"null",
].join(' '),
built_in: [
'az',
'sys',
].join(' ')
};
var lineComment = {
className: 'comment',
begin: "//",
end: "$",
relevance: 0,
};
var blockComment = {
className: 'comment',
begin: "/\\*",
end: "\\*/",
relevance: 0,
};
var comments = {
variants: [lineComment, blockComment],
};
function withComments(input) {
return input.concat(comments);
}
var expression = {
keywords: KEYWORDS,
variants: [
/* placeholder filled later due to cycle*/
],
};
var escapeChar = {
begin: "\\\\(u{[0-9A-Fa-f]+}|n|r|t|\\\\|'|\\${)",
};
var stringVerbatim = {
className: 'string',
begin: "'''",
end: "'''",
};
var stringSubstitution = {
className: 'subst',
begin: "(\\${)",
end: "(})",
contains: withComments([expression]),
};
var stringLiteral = {
className: 'string',
begin: "'" + notBefore("''"),
end: "'",
contains: [
escapeChar,
stringSubstitution
],
};
var numericLiteral = {
className: "number",
begin: "[0-9]+",
};
var namedLiteral = {
className: 'literal',
begin: bounded("(true|false|null)"),
relevance: 0,
};
var identifierExpression = {
className: "variable",
begin: "" + identifier + notBefore(ws + "\\("),
};
var objectPropertyKeyIdentifier = {
className: "property",
begin: "(" + identifier + ")",
};
var objectProperty = {
variants: [
objectPropertyKeyIdentifier,
stringLiteral,
{
begin: ":" + ws,
excludeBegin: true,
end: ws + "$",
excludeEnd: true,
contains: withComments([expression]),
},
],
};
var objectLiteral = {
begin: "{",
end: "}",
contains: withComments([objectProperty]),
};
var arrayLiteral = {
begin: "\\[" + notBefore("" + ws + bounded("for")),
end: "]",
contains: withComments([expression]),
};
var functionCall = {
className: 'function',
begin: "(" + identifier + ")" + ws + "\\(",
end: "\\)",
contains: withComments([expression]),
};
var decorator = {
className: 'meta',
begin: "@" + ws + before(identifier),
end: "",
contains: withComments([functionCall]),
};
expression.variants = [
stringLiteral,
stringVerbatim,
numericLiteral,
namedLiteral,
objectLiteral,
arrayLiteral,
identifierExpression,
functionCall,
decorator,
];
return {
aliases: ['bicep'],
case_insensitive: true,
keywords: KEYWORDS,
contains: withComments([expression]),
};
}