arcade.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. /*
  2. Language: ArcGIS Arcade
  3. Category: scripting
  4. Website: https://developers.arcgis.com/arcade/
  5. Description: ArcGIS Arcade is an expression language used in many Esri ArcGIS products such as Pro, Online, Server, Runtime, JavaScript, and Python
  6. */
  7. /** @type LanguageFn */
  8. function arcade(hljs) {
  9. const regex = hljs.regex;
  10. const IDENT_RE = '[A-Za-z_][0-9A-Za-z_]*';
  11. const KEYWORDS = {
  12. keyword: [
  13. "break",
  14. "case",
  15. "catch",
  16. "continue",
  17. "debugger",
  18. "do",
  19. "else",
  20. "export",
  21. "for",
  22. "function",
  23. "if",
  24. "import",
  25. "in",
  26. "new",
  27. "of",
  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. "DistanceToCoordinate",
  99. "Distinct",
  100. "Domain",
  101. "DomainCode",
  102. "DomainName",
  103. "EnvelopeIntersects",
  104. "Equals",
  105. "Erase",
  106. "Exp",
  107. "Expects",
  108. "Extent",
  109. "Feature",
  110. "FeatureInFilter",
  111. "FeatureSet",
  112. "FeatureSetByAssociation",
  113. "FeatureSetById",
  114. "FeatureSetByName",
  115. "FeatureSetByPortalItem",
  116. "FeatureSetByRelationshipClass",
  117. "FeatureSetByRelationshipName",
  118. "Filter",
  119. "FilterBySubtypeCode",
  120. "Find",
  121. "First|0",
  122. "Floor",
  123. "FromCharCode",
  124. "FromCodePoint",
  125. "FromJSON",
  126. "Front",
  127. "GdbVersion",
  128. "Generalize",
  129. "Geometry",
  130. "GetEnvironment",
  131. "GetFeatureSet",
  132. "GetFeatureSetInfo",
  133. "GetUser",
  134. "GroupBy",
  135. "Guid",
  136. "HasKey",
  137. "HasValue",
  138. "Hash",
  139. "Hour",
  140. "IIf",
  141. "ISOMonth",
  142. "ISOWeek",
  143. "ISOWeekday",
  144. "ISOYear",
  145. "Includes",
  146. "IndexOf",
  147. "Insert",
  148. "Intersection",
  149. "Intersects",
  150. "IsEmpty",
  151. "IsNan",
  152. "IsSelfIntersecting",
  153. "IsSimple",
  154. "KnowledgeGraphByPortalItem",
  155. "Left|0",
  156. "Length",
  157. "Length3D",
  158. "LengthGeodetic",
  159. "Log",
  160. "Lower",
  161. "Map",
  162. "Max",
  163. "Mean",
  164. "MeasureToCoordinate",
  165. "Mid",
  166. "Millisecond",
  167. "Min",
  168. "Minute",
  169. "Month",
  170. "MultiPartToSinglePart",
  171. "Multipoint",
  172. "NearestCoordinate",
  173. "NearestVertex",
  174. "NextSequenceValue",
  175. "None",
  176. "Now",
  177. "Number",
  178. "Offset",
  179. "OrderBy",
  180. "Overlaps",
  181. "Point",
  182. "PointToCoordinate",
  183. "Polygon",
  184. "Polyline",
  185. "Pop",
  186. "Portal",
  187. "Pow",
  188. "Proper",
  189. "Push",
  190. "QueryGraph",
  191. "Random",
  192. "Reduce",
  193. "Relate",
  194. "Replace",
  195. "Resize",
  196. "Reverse",
  197. "Right|0",
  198. "RingIsClockwise",
  199. "Rotate",
  200. "Round",
  201. "Schema",
  202. "Second",
  203. "SetGeometry",
  204. "Simplify",
  205. "Sin",
  206. "Slice",
  207. "Sort",
  208. "Splice",
  209. "Split",
  210. "Sqrt",
  211. "StandardizeFilename",
  212. "StandardizeGuid",
  213. "Stdev",
  214. "SubtypeCode",
  215. "SubtypeName",
  216. "Subtypes",
  217. "Sum",
  218. "SymmetricDifference",
  219. "Tan",
  220. "Text",
  221. "Time",
  222. "TimeZone",
  223. "TimeZoneOffset",
  224. "Timestamp",
  225. "ToCharCode",
  226. "ToCodePoint",
  227. "ToHex",
  228. "ToLocal",
  229. "ToUTC",
  230. "Today",
  231. "Top|0",
  232. "Touches",
  233. "TrackAccelerationAt",
  234. "TrackAccelerationWindow",
  235. "TrackCurrentAcceleration",
  236. "TrackCurrentDistance",
  237. "TrackCurrentSpeed",
  238. "TrackCurrentTime",
  239. "TrackDistanceAt",
  240. "TrackDistanceWindow",
  241. "TrackDuration",
  242. "TrackFieldWindow",
  243. "TrackGeometryWindow",
  244. "TrackIndex",
  245. "TrackSpeedAt",
  246. "TrackSpeedWindow",
  247. "TrackStartTime",
  248. "TrackWindow",
  249. "Trim",
  250. "TypeOf",
  251. "Union",
  252. "Upper",
  253. "UrlEncode",
  254. "Variance",
  255. "Week",
  256. "Weekday",
  257. "When|0",
  258. "Within",
  259. "Year|0",
  260. ]
  261. };
  262. const PROFILE_VARS = [
  263. "aggregatedFeatures",
  264. "analytic",
  265. "config",
  266. "datapoint",
  267. "datastore",
  268. "editcontext",
  269. "feature",
  270. "featureSet",
  271. "feedfeature",
  272. "fencefeature",
  273. "fencenotificationtype",
  274. "graph",
  275. "join",
  276. "layer",
  277. "locationupdate",
  278. "map",
  279. "measure",
  280. "measure",
  281. "originalFeature",
  282. "record",
  283. "reference",
  284. "rowindex",
  285. "sourcedatastore",
  286. "sourcefeature",
  287. "sourcelayer",
  288. "target",
  289. "targetdatastore",
  290. "targetfeature",
  291. "targetlayer",
  292. "userInput",
  293. "value",
  294. "variables",
  295. "view"
  296. ];
  297. const SYMBOL = {
  298. className: 'symbol',
  299. begin: '\\$' + regex.either(...PROFILE_VARS)
  300. };
  301. const NUMBER = {
  302. className: 'number',
  303. variants: [
  304. { begin: '\\b(0[bB][01]+)' },
  305. { begin: '\\b(0[oO][0-7]+)' },
  306. { begin: hljs.C_NUMBER_RE }
  307. ],
  308. relevance: 0
  309. };
  310. const SUBST = {
  311. className: 'subst',
  312. begin: '\\$\\{',
  313. end: '\\}',
  314. keywords: KEYWORDS,
  315. contains: [] // defined later
  316. };
  317. const TEMPLATE_STRING = {
  318. className: 'string',
  319. begin: '`',
  320. end: '`',
  321. contains: [
  322. hljs.BACKSLASH_ESCAPE,
  323. SUBST
  324. ]
  325. };
  326. SUBST.contains = [
  327. hljs.APOS_STRING_MODE,
  328. hljs.QUOTE_STRING_MODE,
  329. TEMPLATE_STRING,
  330. NUMBER,
  331. hljs.REGEXP_MODE
  332. ];
  333. const PARAMS_CONTAINS = SUBST.contains.concat([
  334. hljs.C_BLOCK_COMMENT_MODE,
  335. hljs.C_LINE_COMMENT_MODE
  336. ]);
  337. return {
  338. name: 'ArcGIS Arcade',
  339. case_insensitive: true,
  340. keywords: KEYWORDS,
  341. contains: [
  342. hljs.APOS_STRING_MODE,
  343. hljs.QUOTE_STRING_MODE,
  344. TEMPLATE_STRING,
  345. hljs.C_LINE_COMMENT_MODE,
  346. hljs.C_BLOCK_COMMENT_MODE,
  347. SYMBOL,
  348. NUMBER,
  349. { // object attr container
  350. begin: /[{,]\s*/,
  351. relevance: 0,
  352. contains: [
  353. {
  354. begin: IDENT_RE + '\\s*:',
  355. returnBegin: true,
  356. relevance: 0,
  357. contains: [
  358. {
  359. className: 'attr',
  360. begin: IDENT_RE,
  361. relevance: 0
  362. }
  363. ]
  364. }
  365. ]
  366. },
  367. { // "value" container
  368. begin: '(' + hljs.RE_STARTERS_RE + '|\\b(return)\\b)\\s*',
  369. keywords: 'return',
  370. contains: [
  371. hljs.C_LINE_COMMENT_MODE,
  372. hljs.C_BLOCK_COMMENT_MODE,
  373. hljs.REGEXP_MODE,
  374. {
  375. className: 'function',
  376. begin: '(\\(.*?\\)|' + IDENT_RE + ')\\s*=>',
  377. returnBegin: true,
  378. end: '\\s*=>',
  379. contains: [
  380. {
  381. className: 'params',
  382. variants: [
  383. { begin: IDENT_RE },
  384. { begin: /\(\s*\)/ },
  385. {
  386. begin: /\(/,
  387. end: /\)/,
  388. excludeBegin: true,
  389. excludeEnd: true,
  390. keywords: KEYWORDS,
  391. contains: PARAMS_CONTAINS
  392. }
  393. ]
  394. }
  395. ]
  396. }
  397. ],
  398. relevance: 0
  399. },
  400. {
  401. beginKeywords: 'function',
  402. end: /\{/,
  403. excludeEnd: true,
  404. contains: [
  405. hljs.inherit(hljs.TITLE_MODE, {
  406. className: "title.function",
  407. begin: IDENT_RE
  408. }),
  409. {
  410. className: 'params',
  411. begin: /\(/,
  412. end: /\)/,
  413. excludeBegin: true,
  414. excludeEnd: true,
  415. contains: PARAMS_CONTAINS
  416. }
  417. ],
  418. illegal: /\[|%/
  419. },
  420. { begin: /\$[(.]/ }
  421. ],
  422. illegal: /#(?!!)/
  423. };
  424. }
  425. module.exports = arcade;