arcade.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. const IDENT_RE = '[A-Za-z_][0-9A-Za-z_]*';
  11. const 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. const SYMBOL = {
  30. className: 'symbol',
  31. begin: '\\$[datastore|feature|layer|map|measure|sourcefeature|sourcelayer|targetfeature|targetlayer|value|view]+'
  32. };
  33. const NUMBER = {
  34. className: 'number',
  35. variants: [
  36. {
  37. begin: '\\b(0[bB][01]+)'
  38. },
  39. {
  40. begin: '\\b(0[oO][0-7]+)'
  41. },
  42. {
  43. begin: hljs.C_NUMBER_RE
  44. }
  45. ],
  46. relevance: 0
  47. };
  48. const SUBST = {
  49. className: 'subst',
  50. begin: '\\$\\{',
  51. end: '\\}',
  52. keywords: KEYWORDS,
  53. contains: [] // defined later
  54. };
  55. const TEMPLATE_STRING = {
  56. className: 'string',
  57. begin: '`',
  58. end: '`',
  59. contains: [
  60. hljs.BACKSLASH_ESCAPE,
  61. SUBST
  62. ]
  63. };
  64. SUBST.contains = [
  65. hljs.APOS_STRING_MODE,
  66. hljs.QUOTE_STRING_MODE,
  67. TEMPLATE_STRING,
  68. NUMBER,
  69. hljs.REGEXP_MODE
  70. ];
  71. const PARAMS_CONTAINS = SUBST.contains.concat([
  72. hljs.C_BLOCK_COMMENT_MODE,
  73. hljs.C_LINE_COMMENT_MODE
  74. ]);
  75. return {
  76. name: 'ArcGIS Arcade',
  77. aliases: ['arcade'],
  78. keywords: KEYWORDS,
  79. contains: [
  80. hljs.APOS_STRING_MODE,
  81. hljs.QUOTE_STRING_MODE,
  82. TEMPLATE_STRING,
  83. hljs.C_LINE_COMMENT_MODE,
  84. hljs.C_BLOCK_COMMENT_MODE,
  85. SYMBOL,
  86. NUMBER,
  87. { // object attr container
  88. begin: /[{,]\s*/,
  89. relevance: 0,
  90. contains: [{
  91. begin: IDENT_RE + '\\s*:',
  92. returnBegin: true,
  93. relevance: 0,
  94. contains: [{
  95. className: 'attr',
  96. begin: IDENT_RE,
  97. relevance: 0
  98. }]
  99. }]
  100. },
  101. { // "value" container
  102. begin: '(' + hljs.RE_STARTERS_RE + '|\\b(return)\\b)\\s*',
  103. keywords: 'return',
  104. contains: [
  105. hljs.C_LINE_COMMENT_MODE,
  106. hljs.C_BLOCK_COMMENT_MODE,
  107. hljs.REGEXP_MODE,
  108. {
  109. className: 'function',
  110. begin: '(\\(.*?\\)|' + IDENT_RE + ')\\s*=>',
  111. returnBegin: true,
  112. end: '\\s*=>',
  113. contains: [{
  114. className: 'params',
  115. variants: [
  116. {
  117. begin: IDENT_RE
  118. },
  119. {
  120. begin: /\(\s*\)/
  121. },
  122. {
  123. begin: /\(/,
  124. end: /\)/,
  125. excludeBegin: true,
  126. excludeEnd: true,
  127. keywords: KEYWORDS,
  128. contains: PARAMS_CONTAINS
  129. }
  130. ]
  131. }]
  132. }
  133. ],
  134. relevance: 0
  135. },
  136. {
  137. className: 'function',
  138. beginKeywords: 'function',
  139. end: /\{/,
  140. excludeEnd: true,
  141. contains: [
  142. hljs.inherit(hljs.TITLE_MODE, {
  143. begin: IDENT_RE
  144. }),
  145. {
  146. className: 'params',
  147. begin: /\(/,
  148. end: /\)/,
  149. excludeBegin: true,
  150. excludeEnd: true,
  151. contains: PARAMS_CONTAINS
  152. }
  153. ],
  154. illegal: /\[|%/
  155. },
  156. {
  157. begin: /\$[(.]/
  158. }
  159. ],
  160. illegal: /#(?!!)/
  161. };
  162. }
  163. module.exports = arcade;