arcade.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. 'BackSlash DoubleQuote false ForwardSlash Infinity NaN NewLine null PI SingleQuote Tab TextFormatting true undefined',
  8. built_in:
  9. 'Abs Acos Angle Attachments Area AreaGeodetic Asin Atan Atan2 Average Bearing 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 DistanceGeodetic Distinct ' +
  12. 'DomainCode DomainName Equals Exp Extent Feature FeatureSet FeatureSetByAssociation FeatureSetById FeatureSetByPortalItem ' +
  13. 'FeatureSetByRelationshipName FeatureSetByTitle FeatureSetByUrl Filter First Floor Geometry GroupBy Guid HasKey Hour IIf IndexOf ' +
  14. 'Intersection Intersects IsEmpty IsNan IsSelfIntersecting Length LengthGeodetic Log Max Mean Millisecond Min Minute Month ' +
  15. 'MultiPartToSinglePart Multipoint NextSequenceValue Now Number OrderBy Overlaps Point Polygon ' +
  16. 'Polyline Portal Pow Random Relate Reverse RingIsClockWise Round Second SetGeometry Sin Sort Sqrt Stdev Sum ' +
  17. 'SymmetricDifference Tan Text Timestamp Today ToLocal Top Touches ToUTC TrackCurrentTime ' +
  18. 'TrackGeometryWindow TrackIndex TrackStartTime TrackWindow TypeOf Union UrlEncode Variance ' +
  19. 'Weekday When Within Year '
  20. };
  21. var EXPRESSIONS;
  22. var SYMBOL = {
  23. className: 'symbol',
  24. begin: '\\$[datastore|feature|layer|map|measure|sourcefeature|sourcelayer|targetfeature|targetlayer|value|view]+'
  25. };
  26. var NUMBER = {
  27. className: 'number',
  28. variants: [
  29. { begin: '\\b(0[bB][01]+)' },
  30. { begin: '\\b(0[oO][0-7]+)' },
  31. { begin: hljs.C_NUMBER_RE }
  32. ],
  33. relevance: 0
  34. };
  35. var SUBST = {
  36. className: 'subst',
  37. begin: '\\$\\{', end: '\\}',
  38. keywords: KEYWORDS,
  39. contains: [] // defined later
  40. };
  41. var TEMPLATE_STRING = {
  42. className: 'string',
  43. begin: '`', end: '`',
  44. contains: [
  45. hljs.BACKSLASH_ESCAPE,
  46. SUBST
  47. ]
  48. };
  49. SUBST.contains = [
  50. hljs.APOS_STRING_MODE,
  51. hljs.QUOTE_STRING_MODE,
  52. TEMPLATE_STRING,
  53. NUMBER,
  54. hljs.REGEXP_MODE
  55. ];
  56. var PARAMS_CONTAINS = SUBST.contains.concat([
  57. hljs.C_BLOCK_COMMENT_MODE,
  58. hljs.C_LINE_COMMENT_MODE
  59. ]);
  60. return {
  61. aliases: ['arcade'],
  62. keywords: KEYWORDS,
  63. contains: [
  64. hljs.APOS_STRING_MODE,
  65. hljs.QUOTE_STRING_MODE,
  66. TEMPLATE_STRING,
  67. hljs.C_LINE_COMMENT_MODE,
  68. hljs.C_BLOCK_COMMENT_MODE,
  69. SYMBOL,
  70. NUMBER,
  71. { // object attr container
  72. begin: /[{,]\s*/, relevance: 0,
  73. contains: [
  74. {
  75. begin: IDENT_RE + '\\s*:', returnBegin: true,
  76. relevance: 0,
  77. contains: [{className: 'attr', begin: IDENT_RE, relevance: 0}]
  78. }
  79. ]
  80. },
  81. { // "value" container
  82. begin: '(' + hljs.RE_STARTERS_RE + '|\\b(return)\\b)\\s*',
  83. keywords: 'return',
  84. contains: [
  85. hljs.C_LINE_COMMENT_MODE,
  86. hljs.C_BLOCK_COMMENT_MODE,
  87. hljs.REGEXP_MODE,
  88. {
  89. className: 'function',
  90. begin: '(\\(.*?\\)|' + IDENT_RE + ')\\s*=>', returnBegin: true,
  91. end: '\\s*=>',
  92. contains: [
  93. {
  94. className: 'params',
  95. variants: [
  96. {
  97. begin: IDENT_RE
  98. },
  99. {
  100. begin: /\(\s*\)/,
  101. },
  102. {
  103. begin: /\(/, end: /\)/,
  104. excludeBegin: true, excludeEnd: true,
  105. keywords: KEYWORDS,
  106. contains: PARAMS_CONTAINS
  107. }
  108. ]
  109. }
  110. ]
  111. }
  112. ],
  113. relevance: 0
  114. },
  115. {
  116. className: 'function',
  117. beginKeywords: 'function', end: /\{/, excludeEnd: true,
  118. contains: [
  119. hljs.inherit(hljs.TITLE_MODE, {begin: IDENT_RE}),
  120. {
  121. className: 'params',
  122. begin: /\(/, end: /\)/,
  123. excludeBegin: true,
  124. excludeEnd: true,
  125. contains: PARAMS_CONTAINS
  126. }
  127. ],
  128. illegal: /\[|%/
  129. },
  130. {
  131. begin: /\$[(.]/
  132. }
  133. ],
  134. illegal: /#(?!!)/
  135. };
  136. };