cal.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /*
  2. Language: C/AL
  3. Author: Kenneth Fuglsang Christensen <kfuglsang@gmail.com>
  4. Description: Provides highlighting of Microsoft Dynamics NAV C/AL code files
  5. Website: https://docs.microsoft.com/en-us/dynamics-nav/programming-in-c-al
  6. Category: enterprise
  7. */
  8. /** @type LanguageFn */
  9. function cal(hljs) {
  10. const regex = hljs.regex;
  11. const KEYWORDS = [
  12. "div",
  13. "mod",
  14. "in",
  15. "and",
  16. "or",
  17. "not",
  18. "xor",
  19. "asserterror",
  20. "begin",
  21. "case",
  22. "do",
  23. "downto",
  24. "else",
  25. "end",
  26. "exit",
  27. "for",
  28. "local",
  29. "if",
  30. "of",
  31. "repeat",
  32. "then",
  33. "to",
  34. "until",
  35. "while",
  36. "with",
  37. "var"
  38. ];
  39. const LITERALS = 'false true';
  40. const COMMENT_MODES = [
  41. hljs.C_LINE_COMMENT_MODE,
  42. hljs.COMMENT(
  43. /\{/,
  44. /\}/,
  45. { relevance: 0 }
  46. ),
  47. hljs.COMMENT(
  48. /\(\*/,
  49. /\*\)/,
  50. { relevance: 10 }
  51. )
  52. ];
  53. const STRING = {
  54. className: 'string',
  55. begin: /'/,
  56. end: /'/,
  57. contains: [ { begin: /''/ } ]
  58. };
  59. const CHAR_STRING = {
  60. className: 'string',
  61. begin: /(#\d+)+/
  62. };
  63. const DATE = {
  64. className: 'number',
  65. begin: '\\b\\d+(\\.\\d+)?(DT|D|T)',
  66. relevance: 0
  67. };
  68. const DBL_QUOTED_VARIABLE = {
  69. className: 'string', // not a string technically but makes sense to be highlighted in the same style
  70. begin: '"',
  71. end: '"'
  72. };
  73. const PROCEDURE = {
  74. match: [
  75. /procedure/,
  76. /\s+/,
  77. /[a-zA-Z_][\w@]*/,
  78. /\s*/
  79. ],
  80. scope: {
  81. 1: "keyword",
  82. 3: "title.function"
  83. },
  84. contains: [
  85. {
  86. className: 'params',
  87. begin: /\(/,
  88. end: /\)/,
  89. keywords: KEYWORDS,
  90. contains: [
  91. STRING,
  92. CHAR_STRING,
  93. hljs.NUMBER_MODE
  94. ]
  95. },
  96. ...COMMENT_MODES
  97. ]
  98. };
  99. const OBJECT_TYPES = [
  100. "Table",
  101. "Form",
  102. "Report",
  103. "Dataport",
  104. "Codeunit",
  105. "XMLport",
  106. "MenuSuite",
  107. "Page",
  108. "Query"
  109. ];
  110. const OBJECT = {
  111. match: [
  112. /OBJECT/,
  113. /\s+/,
  114. regex.either(...OBJECT_TYPES),
  115. /\s+/,
  116. /\d+/,
  117. /\s+(?=[^\s])/,
  118. /.*/,
  119. /$/
  120. ],
  121. relevance: 3,
  122. scope: {
  123. 1: "keyword",
  124. 3: "type",
  125. 5: "number",
  126. 7: "title"
  127. }
  128. };
  129. const PROPERTY = {
  130. match: /[\w]+(?=\=)/,
  131. scope: "attribute",
  132. relevance: 0
  133. };
  134. return {
  135. name: 'C/AL',
  136. case_insensitive: true,
  137. keywords: {
  138. keyword: KEYWORDS,
  139. literal: LITERALS
  140. },
  141. illegal: /\/\*/,
  142. contains: [
  143. PROPERTY,
  144. STRING,
  145. CHAR_STRING,
  146. DATE,
  147. DBL_QUOTED_VARIABLE,
  148. hljs.NUMBER_MODE,
  149. OBJECT,
  150. PROCEDURE
  151. ]
  152. };
  153. }
  154. export { cal as default };