cal.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. */
  7. /** @type LanguageFn */
  8. function cal(hljs) {
  9. const KEYWORDS =
  10. 'div mod in and or not xor asserterror begin case do downto else end exit for if of repeat then to ' +
  11. 'until while with var';
  12. const LITERALS = 'false true';
  13. const COMMENT_MODES = [
  14. hljs.C_LINE_COMMENT_MODE,
  15. hljs.COMMENT(
  16. /\{/,
  17. /\}/,
  18. {
  19. relevance: 0
  20. }
  21. ),
  22. hljs.COMMENT(
  23. /\(\*/,
  24. /\*\)/,
  25. {
  26. relevance: 10
  27. }
  28. )
  29. ];
  30. const STRING = {
  31. className: 'string',
  32. begin: /'/,
  33. end: /'/,
  34. contains: [{
  35. begin: /''/
  36. }]
  37. };
  38. const CHAR_STRING = {
  39. className: 'string',
  40. begin: /(#\d+)+/
  41. };
  42. const DATE = {
  43. className: 'number',
  44. begin: '\\b\\d+(\\.\\d+)?(DT|D|T)',
  45. relevance: 0
  46. };
  47. const DBL_QUOTED_VARIABLE = {
  48. className: 'string', // not a string technically but makes sense to be highlighted in the same style
  49. begin: '"',
  50. end: '"'
  51. };
  52. const PROCEDURE = {
  53. className: 'function',
  54. beginKeywords: 'procedure',
  55. end: /[:;]/,
  56. keywords: 'procedure|10',
  57. contains: [
  58. hljs.TITLE_MODE,
  59. {
  60. className: 'params',
  61. begin: /\(/,
  62. end: /\)/,
  63. keywords: KEYWORDS,
  64. contains: [
  65. STRING,
  66. CHAR_STRING
  67. ]
  68. }
  69. ].concat(COMMENT_MODES)
  70. };
  71. const OBJECT = {
  72. className: 'class',
  73. begin: 'OBJECT (Table|Form|Report|Dataport|Codeunit|XMLport|MenuSuite|Page|Query) (\\d+) ([^\\r\\n]+)',
  74. returnBegin: true,
  75. contains: [
  76. hljs.TITLE_MODE,
  77. PROCEDURE
  78. ]
  79. };
  80. return {
  81. name: 'C/AL',
  82. case_insensitive: true,
  83. keywords: {
  84. keyword: KEYWORDS,
  85. literal: LITERALS
  86. },
  87. illegal: /\/\*/,
  88. contains: [
  89. STRING,
  90. CHAR_STRING,
  91. DATE,
  92. DBL_QUOTED_VARIABLE,
  93. hljs.NUMBER_MODE,
  94. OBJECT,
  95. PROCEDURE
  96. ]
  97. };
  98. }
  99. module.exports = cal;