arcade.js 8.2 KB

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