arcade.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  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",
  14. "for",
  15. "while",
  16. "var",
  17. "new",
  18. "function",
  19. "do",
  20. "return",
  21. "void",
  22. "else",
  23. "break"
  24. ],
  25. literal: [
  26. "BackSlash",
  27. "DoubleQuote",
  28. "false",
  29. "ForwardSlash",
  30. "Infinity",
  31. "NaN",
  32. "NewLine",
  33. "null",
  34. "PI",
  35. "SingleQuote",
  36. "Tab",
  37. "TextFormatting",
  38. "true",
  39. "undefined"
  40. ],
  41. built_in: [
  42. "Abs",
  43. "Acos",
  44. "All",
  45. "Angle",
  46. "Any",
  47. "Area",
  48. "AreaGeodetic",
  49. "Array",
  50. "Asin",
  51. "Atan",
  52. "Atan2",
  53. "Attachments",
  54. "Average",
  55. "Back",
  56. "Bearing",
  57. "Boolean",
  58. "Buffer",
  59. "BufferGeodetic",
  60. "Ceil",
  61. "Centroid",
  62. "Clip",
  63. "Concatenate",
  64. "Console",
  65. "Constrain",
  66. "Contains",
  67. "ConvertDirection",
  68. "Cos",
  69. "Count",
  70. "Crosses",
  71. "Cut",
  72. "Date",
  73. "DateAdd",
  74. "DateDiff",
  75. "Day",
  76. "Decode",
  77. "DefaultValue",
  78. "Densify",
  79. "DensifyGeodetic",
  80. "Dictionary",
  81. "Difference",
  82. "Disjoint",
  83. "Distance",
  84. "DistanceGeodetic",
  85. "Distinct",
  86. "Domain",
  87. "DomainCode",
  88. "DomainName",
  89. "EnvelopeIntersects",
  90. "Equals",
  91. "Erase",
  92. "Exp",
  93. "Expects",
  94. "Extent",
  95. "Feature",
  96. "FeatureSet",
  97. "FeatureSetByAssociation",
  98. "FeatureSetById",
  99. "FeatureSetByName",
  100. "FeatureSetByPortalItem",
  101. "FeatureSetByRelationshipName",
  102. "Filter",
  103. "Find",
  104. "First",
  105. "Floor",
  106. "FromCharCode",
  107. "FromCodePoint",
  108. "FromJSON",
  109. "GdbVersion",
  110. "Generalize",
  111. "Geometry",
  112. "GetFeatureSet",
  113. "GetUser",
  114. "GroupBy",
  115. "Guid",
  116. "Hash",
  117. "HasKey",
  118. "Hour",
  119. "IIf",
  120. "Includes",
  121. "IndexOf",
  122. "Insert",
  123. "Intersection",
  124. "Intersects",
  125. "IsEmpty",
  126. "IsNan",
  127. "ISOMonth",
  128. "ISOWeek",
  129. "ISOWeekday",
  130. "ISOYear",
  131. "IsSelfIntersecting",
  132. "IsSimple",
  133. "Left|0",
  134. "Length",
  135. "Length3D",
  136. "LengthGeodetic",
  137. "Log",
  138. "Lower",
  139. "Map",
  140. "Max",
  141. "Mean",
  142. "Mid",
  143. "Millisecond",
  144. "Min",
  145. "Minute",
  146. "Month",
  147. "MultiPartToSinglePart",
  148. "Multipoint",
  149. "NextSequenceValue",
  150. "None",
  151. "Now",
  152. "Number",
  153. "Offset|0",
  154. "OrderBy",
  155. "Overlaps",
  156. "Point",
  157. "Polygon",
  158. "Polyline",
  159. "Pop",
  160. "Portal",
  161. "Pow",
  162. "Proper",
  163. "Push",
  164. "Random",
  165. "Reduce",
  166. "Relate",
  167. "Replace",
  168. "Resize",
  169. "Reverse",
  170. "Right|0",
  171. "RingIsClockwise",
  172. "Rotate",
  173. "Round",
  174. "Schema",
  175. "Second",
  176. "SetGeometry",
  177. "Simplify",
  178. "Sin",
  179. "Slice",
  180. "Sort",
  181. "Splice",
  182. "Split",
  183. "Sqrt",
  184. "Stdev",
  185. "SubtypeCode",
  186. "SubtypeName",
  187. "Subtypes",
  188. "Sum",
  189. "SymmetricDifference",
  190. "Tan",
  191. "Text",
  192. "Timestamp",
  193. "ToCharCode",
  194. "ToCodePoint",
  195. "Today",
  196. "ToHex",
  197. "ToLocal",
  198. "Top|0",
  199. "Touches",
  200. "ToUTC",
  201. "TrackAccelerationAt",
  202. "TrackAccelerationWindow",
  203. "TrackCurrentAcceleration",
  204. "TrackCurrentDistance",
  205. "TrackCurrentSpeed",
  206. "TrackCurrentTime",
  207. "TrackDistanceAt",
  208. "TrackDistanceWindow",
  209. "TrackDuration",
  210. "TrackFieldWindow",
  211. "TrackGeometryWindow",
  212. "TrackIndex",
  213. "TrackSpeedAt",
  214. "TrackSpeedWindow",
  215. "TrackStartTime",
  216. "TrackWindow",
  217. "Trim",
  218. "TypeOf",
  219. "Union",
  220. "Upper",
  221. "UrlEncode",
  222. "Variance",
  223. "Week",
  224. "Weekday",
  225. "When",
  226. "Within",
  227. "Year"
  228. ]
  229. };
  230. const SYMBOL = {
  231. className: 'symbol',
  232. begin: '\\$[datastore|feature|layer|map|measure|sourcefeature|sourcelayer|targetfeature|targetlayer|value|view]+'
  233. };
  234. const NUMBER = {
  235. className: 'number',
  236. variants: [
  237. { begin: '\\b(0[bB][01]+)' },
  238. { begin: '\\b(0[oO][0-7]+)' },
  239. { begin: hljs.C_NUMBER_RE }
  240. ],
  241. relevance: 0
  242. };
  243. const SUBST = {
  244. className: 'subst',
  245. begin: '\\$\\{',
  246. end: '\\}',
  247. keywords: KEYWORDS,
  248. contains: [] // defined later
  249. };
  250. const TEMPLATE_STRING = {
  251. className: 'string',
  252. begin: '`',
  253. end: '`',
  254. contains: [
  255. hljs.BACKSLASH_ESCAPE,
  256. SUBST
  257. ]
  258. };
  259. SUBST.contains = [
  260. hljs.APOS_STRING_MODE,
  261. hljs.QUOTE_STRING_MODE,
  262. TEMPLATE_STRING,
  263. NUMBER,
  264. hljs.REGEXP_MODE
  265. ];
  266. const PARAMS_CONTAINS = SUBST.contains.concat([
  267. hljs.C_BLOCK_COMMENT_MODE,
  268. hljs.C_LINE_COMMENT_MODE
  269. ]);
  270. return {
  271. name: 'ArcGIS Arcade',
  272. case_insensitive: true,
  273. keywords: KEYWORDS,
  274. contains: [
  275. hljs.APOS_STRING_MODE,
  276. hljs.QUOTE_STRING_MODE,
  277. TEMPLATE_STRING,
  278. hljs.C_LINE_COMMENT_MODE,
  279. hljs.C_BLOCK_COMMENT_MODE,
  280. SYMBOL,
  281. NUMBER,
  282. { // object attr container
  283. begin: /[{,]\s*/,
  284. relevance: 0,
  285. contains: [
  286. {
  287. begin: IDENT_RE + '\\s*:',
  288. returnBegin: true,
  289. relevance: 0,
  290. contains: [
  291. {
  292. className: 'attr',
  293. begin: IDENT_RE,
  294. relevance: 0
  295. }
  296. ]
  297. }
  298. ]
  299. },
  300. { // "value" container
  301. begin: '(' + hljs.RE_STARTERS_RE + '|\\b(return)\\b)\\s*',
  302. keywords: 'return',
  303. contains: [
  304. hljs.C_LINE_COMMENT_MODE,
  305. hljs.C_BLOCK_COMMENT_MODE,
  306. hljs.REGEXP_MODE,
  307. {
  308. className: 'function',
  309. begin: '(\\(.*?\\)|' + IDENT_RE + ')\\s*=>',
  310. returnBegin: true,
  311. end: '\\s*=>',
  312. contains: [
  313. {
  314. className: 'params',
  315. variants: [
  316. { begin: IDENT_RE },
  317. { begin: /\(\s*\)/ },
  318. {
  319. begin: /\(/,
  320. end: /\)/,
  321. excludeBegin: true,
  322. excludeEnd: true,
  323. keywords: KEYWORDS,
  324. contains: PARAMS_CONTAINS
  325. }
  326. ]
  327. }
  328. ]
  329. }
  330. ],
  331. relevance: 0
  332. },
  333. {
  334. beginKeywords: 'function',
  335. end: /\{/,
  336. excludeEnd: true,
  337. contains: [
  338. hljs.inherit(hljs.TITLE_MODE, {
  339. className: "title.function",
  340. begin: IDENT_RE
  341. }),
  342. {
  343. className: 'params',
  344. begin: /\(/,
  345. end: /\)/,
  346. excludeBegin: true,
  347. excludeEnd: true,
  348. contains: PARAMS_CONTAINS
  349. }
  350. ],
  351. illegal: /\[|%/
  352. },
  353. { begin: /\$[(.]/ }
  354. ],
  355. illegal: /#(?!!)/
  356. };
  357. }
  358. export { arcade as default };