arcade.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. keywords: KEYWORDS,
  78. contains: [
  79. hljs.APOS_STRING_MODE,
  80. hljs.QUOTE_STRING_MODE,
  81. TEMPLATE_STRING,
  82. hljs.C_LINE_COMMENT_MODE,
  83. hljs.C_BLOCK_COMMENT_MODE,
  84. SYMBOL,
  85. NUMBER,
  86. { // object attr container
  87. begin: /[{,]\s*/,
  88. relevance: 0,
  89. contains: [{
  90. begin: IDENT_RE + '\\s*:',
  91. returnBegin: true,
  92. relevance: 0,
  93. contains: [{
  94. className: 'attr',
  95. begin: IDENT_RE,
  96. relevance: 0
  97. }]
  98. }]
  99. },
  100. { // "value" container
  101. begin: '(' + hljs.RE_STARTERS_RE + '|\\b(return)\\b)\\s*',
  102. keywords: 'return',
  103. contains: [
  104. hljs.C_LINE_COMMENT_MODE,
  105. hljs.C_BLOCK_COMMENT_MODE,
  106. hljs.REGEXP_MODE,
  107. {
  108. className: 'function',
  109. begin: '(\\(.*?\\)|' + IDENT_RE + ')\\s*=>',
  110. returnBegin: true,
  111. end: '\\s*=>',
  112. contains: [{
  113. className: 'params',
  114. variants: [
  115. {
  116. begin: IDENT_RE
  117. },
  118. {
  119. begin: /\(\s*\)/
  120. },
  121. {
  122. begin: /\(/,
  123. end: /\)/,
  124. excludeBegin: true,
  125. excludeEnd: true,
  126. keywords: KEYWORDS,
  127. contains: PARAMS_CONTAINS
  128. }
  129. ]
  130. }]
  131. }
  132. ],
  133. relevance: 0
  134. },
  135. {
  136. className: 'function',
  137. beginKeywords: 'function',
  138. end: /\{/,
  139. excludeEnd: true,
  140. contains: [
  141. hljs.inherit(hljs.TITLE_MODE, {
  142. begin: IDENT_RE
  143. }),
  144. {
  145. className: 'params',
  146. begin: /\(/,
  147. end: /\)/,
  148. excludeBegin: true,
  149. excludeEnd: true,
  150. contains: PARAMS_CONTAINS
  151. }
  152. ],
  153. illegal: /\[|%/
  154. },
  155. {
  156. begin: /\$[(.]/
  157. }
  158. ],
  159. illegal: /#(?!!)/
  160. };
  161. }
  162. module.exports = arcade;