arcade.js 4.7 KB

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