arcade.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. module.exports = function(hljs) {
  2. var IDENT_RE = '[A-Za-z_][0-9A-Za-z_]*';
  3. var KEYWORDS = {
  4. keyword:
  5. 'if for while var new function do return void else break',
  6. literal:
  7. 'true false null undefined NaN Infinity PI BackSlash DoubleQuote ForwardSlash NewLine SingleQuote Tab',
  8. built_in:
  9. 'Abs Acos Area AreaGeodetic Asin Atan Atan2 Average Boolean Buffer BufferGeodetic ' +
  10. 'Ceil Centroid Clip Console Constrain Contains Cos Count Crosses Cut Date DateAdd ' +
  11. 'DateDiff Day Decode DefaultValue Dictionary Difference Disjoint Distance Distinct ' +
  12. 'DomainCode DomainName Equals Exp Extent Feature FeatureSet FeatureSetById FeatureSetByTitle ' +
  13. 'FeatureSetByUrl Filter First Floor Geometry Guid HasKey Hour IIf IndexOf Intersection ' +
  14. 'Intersects IsEmpty Length LengthGeodetic Log Max Mean Millisecond Min Minute Month ' +
  15. 'MultiPartToSinglePart Multipoint NextSequenceValue Now Number OrderBy Overlaps Point Polygon ' +
  16. 'Polyline Pow Random Relate Reverse Round Second SetGeometry Sin Sort Sqrt Stdev Sum ' +
  17. 'SymmetricDifference Tan Text Timestamp Today ToLocal Top Touches ToUTC TypeOf Union Variance ' +
  18. 'Weekday When Within Year '
  19. };
  20. var EXPRESSIONS;
  21. var SYMBOL = {
  22. className: 'symbol',
  23. begin: '\\$[feature|layer|map|value|view]+'
  24. };
  25. var NUMBER = {
  26. className: 'number',
  27. variants: [
  28. { begin: '\\b(0[bB][01]+)' },
  29. { begin: '\\b(0[oO][0-7]+)' },
  30. { begin: hljs.C_NUMBER_RE }
  31. ],
  32. relevance: 0
  33. };
  34. var SUBST = {
  35. className: 'subst',
  36. begin: '\\$\\{', end: '\\}',
  37. keywords: KEYWORDS,
  38. contains: [] // defined later
  39. };
  40. var TEMPLATE_STRING = {
  41. className: 'string',
  42. begin: '`', end: '`',
  43. contains: [
  44. hljs.BACKSLASH_ESCAPE,
  45. SUBST
  46. ]
  47. };
  48. SUBST.contains = [
  49. hljs.APOS_STRING_MODE,
  50. hljs.QUOTE_STRING_MODE,
  51. TEMPLATE_STRING,
  52. NUMBER,
  53. hljs.REGEXP_MODE
  54. ];
  55. var PARAMS_CONTAINS = SUBST.contains.concat([
  56. hljs.C_BLOCK_COMMENT_MODE,
  57. hljs.C_LINE_COMMENT_MODE
  58. ]);
  59. return {
  60. aliases: ['arcade'],
  61. keywords: KEYWORDS,
  62. contains: [
  63. hljs.APOS_STRING_MODE,
  64. hljs.QUOTE_STRING_MODE,
  65. TEMPLATE_STRING,
  66. hljs.C_LINE_COMMENT_MODE,
  67. hljs.C_BLOCK_COMMENT_MODE,
  68. SYMBOL,
  69. NUMBER,
  70. { // object attr container
  71. begin: /[{,]\s*/, relevance: 0,
  72. contains: [
  73. {
  74. begin: IDENT_RE + '\\s*:', returnBegin: true,
  75. relevance: 0,
  76. contains: [{className: 'attr', begin: IDENT_RE, relevance: 0}]
  77. }
  78. ]
  79. },
  80. { // "value" container
  81. begin: '(' + hljs.RE_STARTERS_RE + '|\\b(return)\\b)\\s*',
  82. keywords: 'return',
  83. contains: [
  84. hljs.C_LINE_COMMENT_MODE,
  85. hljs.C_BLOCK_COMMENT_MODE,
  86. hljs.REGEXP_MODE,
  87. {
  88. className: 'function',
  89. begin: '(\\(.*?\\)|' + IDENT_RE + ')\\s*=>', returnBegin: true,
  90. end: '\\s*=>',
  91. contains: [
  92. {
  93. className: 'params',
  94. variants: [
  95. {
  96. begin: IDENT_RE
  97. },
  98. {
  99. begin: /\(\s*\)/,
  100. },
  101. {
  102. begin: /\(/, end: /\)/,
  103. excludeBegin: true, excludeEnd: true,
  104. keywords: KEYWORDS,
  105. contains: PARAMS_CONTAINS
  106. }
  107. ]
  108. }
  109. ]
  110. }
  111. ],
  112. relevance: 0
  113. },
  114. {
  115. className: 'function',
  116. beginKeywords: 'function', end: /\{/, excludeEnd: true,
  117. contains: [
  118. hljs.inherit(hljs.TITLE_MODE, {begin: IDENT_RE}),
  119. {
  120. className: 'params',
  121. begin: /\(/, end: /\)/,
  122. excludeBegin: true,
  123. excludeEnd: true,
  124. contains: PARAMS_CONTAINS
  125. }
  126. ],
  127. illegal: /\[|%/
  128. },
  129. {
  130. begin: /\$[(.]/
  131. }
  132. ],
  133. illegal: /#(?!!)/
  134. };
  135. };