cos.js 5.1 KB

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