]> luflow.net public git repositories - flow-web.git/blob - static/highlight/es/languages/xquery.js
Initial commit.
[flow-web.git] / static / highlight / es / languages / xquery.js
1 /*! `xquery` grammar compiled for Highlight.js 11.11.1 */
2 var hljsGrammar = (function () {
3 'use strict';
4
5 /*
6 Language: XQuery
7 Author: Dirk Kirsten <dk@basex.org>
8 Contributor: Duncan Paterson
9 Description: Supports XQuery 3.1 including XQuery Update 3, so also XPath (as it is a superset)
10 Refactored to process xml constructor syntax and function-bodies. Added missing data-types, xpath operands, inbuilt functions, and query prologs
11 Website: https://www.w3.org/XML/Query/
12 Category: functional
13 Audit: 2020
14 */
15
16 /** @type LanguageFn */
17 function xquery(_hljs) {
18 // see https://www.w3.org/TR/xquery/#id-terminal-delimitation
19 const KEYWORDS = [
20 "module",
21 "schema",
22 "namespace",
23 "boundary-space",
24 "preserve",
25 "no-preserve",
26 "strip",
27 "default",
28 "collation",
29 "base-uri",
30 "ordering",
31 "context",
32 "decimal-format",
33 "decimal-separator",
34 "copy-namespaces",
35 "empty-sequence",
36 "except",
37 "exponent-separator",
38 "external",
39 "grouping-separator",
40 "inherit",
41 "no-inherit",
42 "lax",
43 "minus-sign",
44 "per-mille",
45 "percent",
46 "schema-attribute",
47 "schema-element",
48 "strict",
49 "unordered",
50 "zero-digit",
51 "declare",
52 "import",
53 "option",
54 "function",
55 "validate",
56 "variable",
57 "for",
58 "at",
59 "in",
60 "let",
61 "where",
62 "order",
63 "group",
64 "by",
65 "return",
66 "if",
67 "then",
68 "else",
69 "tumbling",
70 "sliding",
71 "window",
72 "start",
73 "when",
74 "only",
75 "end",
76 "previous",
77 "next",
78 "stable",
79 "ascending",
80 "descending",
81 "allowing",
82 "empty",
83 "greatest",
84 "least",
85 "some",
86 "every",
87 "satisfies",
88 "switch",
89 "case",
90 "typeswitch",
91 "try",
92 "catch",
93 "and",
94 "or",
95 "to",
96 "union",
97 "intersect",
98 "instance",
99 "of",
100 "treat",
101 "as",
102 "castable",
103 "cast",
104 "map",
105 "array",
106 "delete",
107 "insert",
108 "into",
109 "replace",
110 "value",
111 "rename",
112 "copy",
113 "modify",
114 "update"
115 ];
116
117 // Node Types (sorted by inheritance)
118 // atomic types (sorted by inheritance)
119 const TYPES = [
120 "item",
121 "document-node",
122 "node",
123 "attribute",
124 "document",
125 "element",
126 "comment",
127 "namespace",
128 "namespace-node",
129 "processing-instruction",
130 "text",
131 "construction",
132 "xs:anyAtomicType",
133 "xs:untypedAtomic",
134 "xs:duration",
135 "xs:time",
136 "xs:decimal",
137 "xs:float",
138 "xs:double",
139 "xs:gYearMonth",
140 "xs:gYear",
141 "xs:gMonthDay",
142 "xs:gMonth",
143 "xs:gDay",
144 "xs:boolean",
145 "xs:base64Binary",
146 "xs:hexBinary",
147 "xs:anyURI",
148 "xs:QName",
149 "xs:NOTATION",
150 "xs:dateTime",
151 "xs:dateTimeStamp",
152 "xs:date",
153 "xs:string",
154 "xs:normalizedString",
155 "xs:token",
156 "xs:language",
157 "xs:NMTOKEN",
158 "xs:Name",
159 "xs:NCName",
160 "xs:ID",
161 "xs:IDREF",
162 "xs:ENTITY",
163 "xs:integer",
164 "xs:nonPositiveInteger",
165 "xs:negativeInteger",
166 "xs:long",
167 "xs:int",
168 "xs:short",
169 "xs:byte",
170 "xs:nonNegativeInteger",
171 "xs:unisignedLong",
172 "xs:unsignedInt",
173 "xs:unsignedShort",
174 "xs:unsignedByte",
175 "xs:positiveInteger",
176 "xs:yearMonthDuration",
177 "xs:dayTimeDuration"
178 ];
179
180 const LITERALS = [
181 "eq",
182 "ne",
183 "lt",
184 "le",
185 "gt",
186 "ge",
187 "is",
188 "self::",
189 "child::",
190 "descendant::",
191 "descendant-or-self::",
192 "attribute::",
193 "following::",
194 "following-sibling::",
195 "parent::",
196 "ancestor::",
197 "ancestor-or-self::",
198 "preceding::",
199 "preceding-sibling::",
200 "NaN"
201 ];
202
203 // functions (TODO: find regex for op: without breaking build)
204 const BUILT_IN = {
205 className: 'built_in',
206 variants: [
207 {
208 begin: /\barray:/,
209 end: /(?:append|filter|flatten|fold-(?:left|right)|for-each(?:-pair)?|get|head|insert-before|join|put|remove|reverse|size|sort|subarray|tail)\b/
210 },
211 {
212 begin: /\bmap:/,
213 end: /(?:contains|entry|find|for-each|get|keys|merge|put|remove|size)\b/
214 },
215 {
216 begin: /\bmath:/,
217 end: /(?:a(?:cos|sin|tan[2]?)|cos|exp(?:10)?|log(?:10)?|pi|pow|sin|sqrt|tan)\b/
218 },
219 {
220 begin: /\bop:/,
221 end: /\(/,
222 excludeEnd: true
223 },
224 {
225 begin: /\bfn:/,
226 end: /\(/,
227 excludeEnd: true
228 },
229 // do not highlight inbuilt strings as variable or xml element names
230 { begin: /[^</$:'"-]\b(?:abs|accumulator-(?:after|before)|adjust-(?:date(?:Time)?|time)-to-timezone|analyze-string|apply|available-(?:environment-variables|system-properties)|avg|base-uri|boolean|ceiling|codepoints?-(?:equal|to-string)|collation-key|collection|compare|concat|contains(?:-token)?|copy-of|count|current(?:-)?(?:date(?:Time)?|time|group(?:ing-key)?|output-uri|merge-(?:group|key))?data|dateTime|days?-from-(?:date(?:Time)?|duration)|deep-equal|default-(?:collation|language)|distinct-values|document(?:-uri)?|doc(?:-available)?|element-(?:available|with-id)|empty|encode-for-uri|ends-with|environment-variable|error|escape-html-uri|exactly-one|exists|false|filter|floor|fold-(?:left|right)|for-each(?:-pair)?|format-(?:date(?:Time)?|time|integer|number)|function-(?:arity|available|lookup|name)|generate-id|has-children|head|hours-from-(?:dateTime|duration|time)|id(?:ref)?|implicit-timezone|in-scope-prefixes|index-of|innermost|insert-before|iri-to-uri|json-(?:doc|to-xml)|key|lang|last|load-xquery-module|local-name(?:-from-QName)?|(?:lower|upper)-case|matches|max|minutes-from-(?:dateTime|duration|time)|min|months?-from-(?:date(?:Time)?|duration)|name(?:space-uri-?(?:for-prefix|from-QName)?)?|nilled|node-name|normalize-(?:space|unicode)|not|number|one-or-more|outermost|parse-(?:ietf-date|json)|path|position|(?:prefix-from-)?QName|random-number-generator|regex-group|remove|replace|resolve-(?:QName|uri)|reverse|root|round(?:-half-to-even)?|seconds-from-(?:dateTime|duration|time)|snapshot|sort|starts-with|static-base-uri|stream-available|string-?(?:join|length|to-codepoints)?|subsequence|substring-?(?:after|before)?|sum|system-property|tail|timezone-from-(?:date(?:Time)?|time)|tokenize|trace|trans(?:form|late)|true|type-available|unordered|unparsed-(?:entity|text)?-?(?:public-id|uri|available|lines)?|uri-collection|xml-to-json|years?-from-(?:date(?:Time)?|duration)|zero-or-one)\b/ },
231 {
232 begin: /\blocal:/,
233 end: /\(/,
234 excludeEnd: true
235 },
236 {
237 begin: /\bzip:/,
238 end: /(?:zip-file|(?:xml|html|text|binary)-entry| (?:update-)?entries)\b/
239 },
240 {
241 begin: /\b(?:util|db|functx|app|xdmp|xmldb):/,
242 end: /\(/,
243 excludeEnd: true
244 }
245 ]
246 };
247
248 const TITLE = {
249 className: 'title',
250 begin: /\bxquery version "[13]\.[01]"\s?(?:encoding ".+")?/,
251 end: /;/
252 };
253
254 const VAR = {
255 className: 'variable',
256 begin: /[$][\w\-:]+/
257 };
258
259 const NUMBER = {
260 className: 'number',
261 begin: /(\b0[0-7_]+)|(\b0x[0-9a-fA-F_]+)|(\b[1-9][0-9_]*(\.[0-9_]+)?)|[0_]\b/,
262 relevance: 0
263 };
264
265 const STRING = {
266 className: 'string',
267 variants: [
268 {
269 begin: /"/,
270 end: /"/,
271 contains: [
272 {
273 begin: /""/,
274 relevance: 0
275 }
276 ]
277 },
278 {
279 begin: /'/,
280 end: /'/,
281 contains: [
282 {
283 begin: /''/,
284 relevance: 0
285 }
286 ]
287 }
288 ]
289 };
290
291 const ANNOTATION = {
292 className: 'meta',
293 begin: /%[\w\-:]+/
294 };
295
296 const COMMENT = {
297 className: 'comment',
298 begin: /\(:/,
299 end: /:\)/,
300 relevance: 10,
301 contains: [
302 {
303 className: 'doctag',
304 begin: /@\w+/
305 }
306 ]
307 };
308
309 // see https://www.w3.org/TR/xquery/#id-computedConstructors
310 // mocha: computed_inbuilt
311 // see https://www.regexpal.com/?fam=99749
312 const COMPUTED = {
313 beginKeywords: 'element attribute comment document processing-instruction',
314 end: /\{/,
315 excludeEnd: true
316 };
317
318 // mocha: direct_method
319 const DIRECT = {
320 begin: /<([\w._:-]+)(\s+\S*=('|").*('|"))?>/,
321 end: /(\/[\w._:-]+>)/,
322 subLanguage: 'xml',
323 contains: [
324 {
325 begin: /\{/,
326 end: /\}/,
327 subLanguage: 'xquery'
328 },
329 'self'
330 ]
331 };
332
333 const CONTAINS = [
334 VAR,
335 BUILT_IN,
336 STRING,
337 NUMBER,
338 COMMENT,
339 ANNOTATION,
340 TITLE,
341 COMPUTED,
342 DIRECT
343 ];
344
345 return {
346 name: 'XQuery',
347 aliases: [
348 'xpath',
349 'xq',
350 'xqm'
351 ],
352 case_insensitive: false,
353 illegal: /(proc)|(abstract)|(extends)|(until)|(#)/,
354 keywords: {
355 $pattern: /[a-zA-Z$][a-zA-Z0-9_:-]*/,
356 keyword: KEYWORDS,
357 type: TYPES,
358 literal: LITERALS
359 },
360 contains: CONTAINS
361 };
362 }
363
364 return xquery;
365
366 })();
367 ;
368 export default hljsGrammar;