xquery.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. module.exports = function(hljs) {
  2. // see https://www.w3.org/TR/xquery/#id-terminal-delimitation
  3. var KEYWORDS = 'module schema namespace boundary-space preserve no-preserve strip default collation base-uri ordering context decimal-format decimal-separator copy-namespaces empty-sequence except exponent-separator external grouping-separator inherit no-inherit lax minus-sign per-mille percent schema-attribute schema-element strict unordered zero-digit ' +
  4. 'declare import option function validate variable ' +
  5. 'for at in let where order group by return if then else ' +
  6. 'tumbling sliding window start when only end previous next stable ' +
  7. 'ascending descending allowing empty greatest least some every satisfies switch case typeswitch try catch ' +
  8. 'and or to union intersect instance of treat as castable cast map array ' +
  9. 'delete insert into replace value rename copy modify update';
  10. // Node Types (sorted by inheritance)
  11. // atomic types (sorted by inheritance)
  12. var TYPE = 'item document-node node attribute document element comment namespace namespace-node processing-instruction text construction ' +
  13. 'xs:anyAtomicType xs:untypedAtomic xs:duration xs:time xs:decimal xs:float xs:double xs:gYearMonth xs:gYear xs:gMonthDay xs:gMonth xs:gDay xs:boolean xs:base64Binary xs:hexBinary xs:anyURI xs:QName xs:NOTATION xs:dateTime xs:dateTimeStamp xs:date xs:string xs:normalizedString xs:token xs:language xs:NMTOKEN xs:Name xs:NCName xs:ID xs:IDREF xs:ENTITY xs:integer xs:nonPositiveInteger xs:negativeInteger xs:long xs:int xs:short xs:byte xs:nonNegativeInteger xs:unisignedLong xs:unsignedInt xs:unsignedShort xs:unsignedByte xs:positiveInteger xs:yearMonthDuration xs:dayTimeDuration';
  14. var LITERAL = 'eq ne lt le gt ge is ' +
  15. 'self:: child:: descendant:: descendant-or-self:: attribute:: following:: following-sibling:: parent:: ancestor:: ancestor-or-self:: preceding:: preceding-sibling:: ' +
  16. 'NaN';
  17. // functions (TODO: find regex for op: without breaking build)
  18. var BUILT_IN = {
  19. className: 'built_in',
  20. variants: [{
  21. begin: /\barray\:/,
  22. end: /(?:append|filter|flatten|fold\-(?:left|right)|for-each(?:\-pair)?|get|head|insert\-before|join|put|remove|reverse|size|sort|subarray|tail)\b/
  23. }, {
  24. begin: /\bmap\:/,
  25. end: /(?:contains|entry|find|for\-each|get|keys|merge|put|remove|size)\b/
  26. }, {
  27. begin: /\bmath\:/,
  28. end: /(?:a(?:cos|sin|tan[2]?)|cos|exp(?:10)?|log(?:10)?|pi|pow|sin|sqrt|tan)\b/
  29. }, {
  30. begin: /\bop\:/,
  31. end: /\(/,
  32. excludeEnd: true
  33. }, {
  34. begin: /\bfn\:/,
  35. end: /\(/,
  36. excludeEnd: true
  37. },
  38. // do not highlight inbuilt strings as variable or xml element names
  39. {
  40. 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/,
  41. }, {
  42. begin: /\blocal\:/,
  43. end: /\(/,
  44. excludeEnd: true
  45. }, {
  46. begin: /\bzip\:/,
  47. end: /(?:zip\-file|(?:xml|html|text|binary)\-entry| (?:update\-)?entries)\b/
  48. }, {
  49. begin: /\b(?:util|db|functx|app|xdmp|xmldb)\:/,
  50. end: /\(/,
  51. excludeEnd: true
  52. }
  53. ]
  54. };
  55. var TITLE = {
  56. className: 'title',
  57. begin: /\bxquery version "[13]\.[01]"\s?(?:encoding ".+")?/,
  58. end: /;/
  59. };
  60. var VAR = {
  61. className: 'variable',
  62. begin: /[\$][\w-:]+/
  63. };
  64. var NUMBER = {
  65. className: 'number',
  66. begin: '(\\b0[0-7_]+)|(\\b0x[0-9a-fA-F_]+)|(\\b[1-9][0-9_]*(\\.[0-9_]+)?)|[0_]\\b',
  67. relevance: 0
  68. };
  69. var STRING = {
  70. className: 'string',
  71. variants: [{
  72. begin: /"/,
  73. end: /"/,
  74. contains: [{
  75. begin: /""/,
  76. relevance: 0
  77. }]
  78. },
  79. {
  80. begin: /'/,
  81. end: /'/,
  82. contains: [{
  83. begin: /''/,
  84. relevance: 0
  85. }]
  86. }
  87. ]
  88. };
  89. var ANNOTATION = {
  90. className: 'meta',
  91. begin: /%[\w-:]+/
  92. };
  93. var COMMENT = {
  94. className: 'comment',
  95. begin: '\\(:',
  96. end: ':\\)',
  97. relevance: 10,
  98. contains: [{
  99. className: 'doctag',
  100. begin: '@\\w+'
  101. }]
  102. };
  103. // see https://www.w3.org/TR/xquery/#id-computedConstructors
  104. // mocha: computed_inbuilt
  105. // see https://www.regexpal.com/?fam=99749
  106. var COMPUTED = {
  107. beginKeywords: 'element attribute comment document processing-instruction',
  108. end: '{',
  109. excludeEnd: true
  110. };
  111. // mocha: direct_method
  112. var DIRECT = {
  113. begin: /<([\w\._:\-]+)((\s*.*)=('|").*('|"))?>/,
  114. end: /(\/[\w\._:\-]+>)/,
  115. subLanguage: 'xml',
  116. contains: [{
  117. begin: '{',
  118. end: '}',
  119. subLanguage: 'xquery'
  120. }, 'self']
  121. };
  122. var CONTAINS = [
  123. VAR,
  124. BUILT_IN,
  125. STRING,
  126. NUMBER,
  127. COMMENT,
  128. ANNOTATION,
  129. TITLE,
  130. COMPUTED,
  131. DIRECT
  132. ];
  133. var METHOD = {
  134. begin: '{',
  135. end: '}',
  136. contains: CONTAINS
  137. };
  138. return {
  139. aliases: ['xpath', 'xq'],
  140. case_insensitive: false,
  141. lexemes: /[a-zA-Z\$][a-zA-Z0-9_:\-]*/,
  142. illegal: /(proc)|(abstract)|(extends)|(until)|(#)/,
  143. keywords: {
  144. keyword: KEYWORDS,
  145. type: TYPE,
  146. literal: LITERAL
  147. },
  148. contains: CONTAINS
  149. };
  150. };