cos.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. Language: Caché Object Script
  3. Author: Nikita Savchenko <zitros.lab@gmail.com>
  4. Category: enterprise, scripting
  5. Website: https://cedocs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls
  6. */
  7. /** @type LanguageFn */
  8. function cos(hljs) {
  9. const STRINGS = {
  10. className: 'string',
  11. variants: [
  12. {
  13. begin: '"',
  14. end: '"',
  15. contains: [
  16. { // escaped
  17. begin: "\"\"",
  18. relevance: 0
  19. }
  20. ]
  21. }
  22. ]
  23. };
  24. const NUMBERS = {
  25. className: "number",
  26. begin: "\\b(\\d+(\\.\\d*)?|\\.\\d+)",
  27. relevance: 0
  28. };
  29. const COS_KEYWORDS =
  30. 'property parameter class classmethod clientmethod extends as break '
  31. + 'catch close continue do d|0 else elseif for goto halt hang h|0 if job '
  32. + 'j|0 kill k|0 lock l|0 merge new open quit q|0 read r|0 return set s|0 '
  33. + 'tcommit throw trollback try tstart use view while write w|0 xecute x|0 '
  34. + 'zkill znspace zn ztrap zwrite zw zzdump zzwrite print zbreak zinsert '
  35. + 'zload zprint zremove zsave zzprint mv mvcall mvcrt mvdim mvprint zquit '
  36. + 'zsync ascii';
  37. // registered function - no need in them due to all functions are highlighted,
  38. // but I'll just leave this here.
  39. // "$bit", "$bitcount",
  40. // "$bitfind", "$bitlogic", "$case", "$char", "$classmethod", "$classname",
  41. // "$compile", "$data", "$decimal", "$double", "$extract", "$factor",
  42. // "$find", "$fnumber", "$get", "$increment", "$inumber", "$isobject",
  43. // "$isvaliddouble", "$isvalidnum", "$justify", "$length", "$list",
  44. // "$listbuild", "$listdata", "$listfind", "$listfromstring", "$listget",
  45. // "$listlength", "$listnext", "$listsame", "$listtostring", "$listvalid",
  46. // "$locate", "$match", "$method", "$name", "$nconvert", "$next",
  47. // "$normalize", "$now", "$number", "$order", "$parameter", "$piece",
  48. // "$prefetchoff", "$prefetchon", "$property", "$qlength", "$qsubscript",
  49. // "$query", "$random", "$replace", "$reverse", "$sconvert", "$select",
  50. // "$sortbegin", "$sortend", "$stack", "$text", "$translate", "$view",
  51. // "$wascii", "$wchar", "$wextract", "$wfind", "$wiswide", "$wlength",
  52. // "$wreverse", "$xecute", "$zabs", "$zarccos", "$zarcsin", "$zarctan",
  53. // "$zcos", "$zcot", "$zcsc", "$zdate", "$zdateh", "$zdatetime",
  54. // "$zdatetimeh", "$zexp", "$zhex", "$zln", "$zlog", "$zpower", "$zsec",
  55. // "$zsin", "$zsqr", "$ztan", "$ztime", "$ztimeh", "$zboolean",
  56. // "$zconvert", "$zcrc", "$zcyc", "$zdascii", "$zdchar", "$zf",
  57. // "$ziswide", "$zlascii", "$zlchar", "$zname", "$zposition", "$zqascii",
  58. // "$zqchar", "$zsearch", "$zseek", "$zstrip", "$zwascii", "$zwchar",
  59. // "$zwidth", "$zwpack", "$zwbpack", "$zwunpack", "$zwbunpack", "$zzenkaku",
  60. // "$change", "$mv", "$mvat", "$mvfmt", "$mvfmts", "$mviconv",
  61. // "$mviconvs", "$mvinmat", "$mvlover", "$mvoconv", "$mvoconvs", "$mvraise",
  62. // "$mvtrans", "$mvv", "$mvname", "$zbitand", "$zbitcount", "$zbitfind",
  63. // "$zbitget", "$zbitlen", "$zbitnot", "$zbitor", "$zbitset", "$zbitstr",
  64. // "$zbitxor", "$zincrement", "$znext", "$zorder", "$zprevious", "$zsort",
  65. // "device", "$ecode", "$estack", "$etrap", "$halt", "$horolog",
  66. // "$io", "$job", "$key", "$namespace", "$principal", "$quit", "$roles",
  67. // "$storage", "$system", "$test", "$this", "$tlevel", "$username",
  68. // "$x", "$y", "$za", "$zb", "$zchild", "$zeof", "$zeos", "$zerror",
  69. // "$zhorolog", "$zio", "$zjob", "$zmode", "$znspace", "$zparent", "$zpi",
  70. // "$zpos", "$zreference", "$zstorage", "$ztimestamp", "$ztimezone",
  71. // "$ztrap", "$zversion"
  72. return {
  73. name: 'Caché Object Script',
  74. case_insensitive: true,
  75. aliases: [ "cls" ],
  76. keywords: COS_KEYWORDS,
  77. contains: [
  78. NUMBERS,
  79. STRINGS,
  80. hljs.C_LINE_COMMENT_MODE,
  81. hljs.C_BLOCK_COMMENT_MODE,
  82. {
  83. className: "comment",
  84. begin: /;/,
  85. end: "$",
  86. relevance: 0
  87. },
  88. { // Functions and user-defined functions: write $ztime(60*60*3), $$myFunc(10), $$^Val(1)
  89. className: "built_in",
  90. begin: /(?:\$\$?|\.\.)\^?[a-zA-Z]+/
  91. },
  92. { // Macro command: quit $$$OK
  93. className: "built_in",
  94. begin: /\$\$\$[a-zA-Z]+/
  95. },
  96. { // Special (global) variables: write %request.Content; Built-in classes: %Library.Integer
  97. className: "built_in",
  98. begin: /%[a-z]+(?:\.[a-z]+)*/
  99. },
  100. { // Global variable: set ^globalName = 12 write ^globalName
  101. className: "symbol",
  102. begin: /\^%?[a-zA-Z][\w]*/
  103. },
  104. { // Some control constructions: do ##class(Package.ClassName).Method(), ##super()
  105. className: "keyword",
  106. begin: /##class|##super|#define|#dim/
  107. },
  108. // sub-languages: are not fully supported by hljs by 11/15/2015
  109. // left for the future implementation.
  110. {
  111. begin: /&sql\(/,
  112. end: /\)/,
  113. excludeBegin: true,
  114. excludeEnd: true,
  115. subLanguage: "sql"
  116. },
  117. {
  118. begin: /&(js|jscript|javascript)</,
  119. end: />/,
  120. excludeBegin: true,
  121. excludeEnd: true,
  122. subLanguage: "javascript"
  123. },
  124. {
  125. // this brakes first and last tag, but this is the only way to embed a valid html
  126. begin: /&html<\s*</,
  127. end: />\s*>/,
  128. subLanguage: "xml"
  129. }
  130. ]
  131. };
  132. }
  133. export { cos as default };