arcade.js (4784B)
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 9 /** @type LanguageFn */ 10 function arcade(hljs) { 11 var IDENT_RE = '[A-Za-z_][0-9A-Za-z_]*'; 12 var KEYWORDS = { 13 keyword: 14 'if for while var new function do return void else break', 15 literal: 16 'BackSlash DoubleQuote false ForwardSlash Infinity NaN NewLine null PI SingleQuote Tab TextFormatting true undefined', 17 built_in: 18 'Abs Acos Angle Attachments Area AreaGeodetic Asin Atan Atan2 Average Bearing Boolean Buffer BufferGeodetic ' + 19 'Ceil Centroid Clip Console Constrain Contains Cos Count Crosses Cut Date DateAdd ' + 20 'DateDiff Day Decode DefaultValue Dictionary Difference Disjoint Distance DistanceGeodetic Distinct ' + 21 'DomainCode DomainName Equals Exp Extent Feature FeatureSet FeatureSetByAssociation FeatureSetById FeatureSetByPortalItem ' + 22 'FeatureSetByRelationshipName FeatureSetByTitle FeatureSetByUrl Filter First Floor Geometry GroupBy Guid HasKey Hour IIf IndexOf ' + 23 'Intersection Intersects IsEmpty IsNan IsSelfIntersecting Length LengthGeodetic Log Max Mean Millisecond Min Minute Month ' + 24 'MultiPartToSinglePart Multipoint NextSequenceValue Now Number OrderBy Overlaps Point Polygon ' + 25 'Polyline Portal Pow Random Relate Reverse RingIsClockWise Round Second SetGeometry Sin Sort Sqrt Stdev Sum ' + 26 'SymmetricDifference Tan Text Timestamp Today ToLocal Top Touches ToUTC TrackCurrentTime ' + 27 'TrackGeometryWindow TrackIndex TrackStartTime TrackWindow TypeOf Union UrlEncode Variance ' + 28 'Weekday When Within Year ' 29 }; 30 var SYMBOL = { 31 className: 'symbol', 32 begin: '\\$[datastore|feature|layer|map|measure|sourcefeature|sourcelayer|targetfeature|targetlayer|value|view]+' 33 }; 34 var NUMBER = { 35 className: 'number', 36 variants: [ 37 { begin: '\\b(0[bB][01]+)' }, 38 { begin: '\\b(0[oO][0-7]+)' }, 39 { begin: hljs.C_NUMBER_RE } 40 ], 41 relevance: 0 42 }; 43 var SUBST = { 44 className: 'subst', 45 begin: '\\$\\{', end: '\\}', 46 keywords: KEYWORDS, 47 contains: [] // defined later 48 }; 49 var TEMPLATE_STRING = { 50 className: 'string', 51 begin: '`', end: '`', 52 contains: [ 53 hljs.BACKSLASH_ESCAPE, 54 SUBST 55 ] 56 }; 57 SUBST.contains = [ 58 hljs.APOS_STRING_MODE, 59 hljs.QUOTE_STRING_MODE, 60 TEMPLATE_STRING, 61 NUMBER, 62 hljs.REGEXP_MODE 63 ]; 64 var PARAMS_CONTAINS = SUBST.contains.concat([ 65 hljs.C_BLOCK_COMMENT_MODE, 66 hljs.C_LINE_COMMENT_MODE 67 ]); 68 69 return { 70 name: 'ArcGIS Arcade', 71 aliases: ['arcade'], 72 keywords: KEYWORDS, 73 contains: [ 74 hljs.APOS_STRING_MODE, 75 hljs.QUOTE_STRING_MODE, 76 TEMPLATE_STRING, 77 hljs.C_LINE_COMMENT_MODE, 78 hljs.C_BLOCK_COMMENT_MODE, 79 SYMBOL, 80 NUMBER, 81 { // object attr container 82 begin: /[{,]\s*/, relevance: 0, 83 contains: [ 84 { 85 begin: IDENT_RE + '\\s*:', returnBegin: true, 86 relevance: 0, 87 contains: [{className: 'attr', begin: IDENT_RE, relevance: 0}] 88 } 89 ] 90 }, 91 { // "value" container 92 begin: '(' + hljs.RE_STARTERS_RE + '|\\b(return)\\b)\\s*', 93 keywords: 'return', 94 contains: [ 95 hljs.C_LINE_COMMENT_MODE, 96 hljs.C_BLOCK_COMMENT_MODE, 97 hljs.REGEXP_MODE, 98 { 99 className: 'function', 100 begin: '(\\(.*?\\)|' + IDENT_RE + ')\\s*=>', returnBegin: true, 101 end: '\\s*=>', 102 contains: [ 103 { 104 className: 'params', 105 variants: [ 106 { 107 begin: IDENT_RE 108 }, 109 { 110 begin: /\(\s*\)/, 111 }, 112 { 113 begin: /\(/, end: /\)/, 114 excludeBegin: true, excludeEnd: true, 115 keywords: KEYWORDS, 116 contains: PARAMS_CONTAINS 117 } 118 ] 119 } 120 ] 121 } 122 ], 123 relevance: 0 124 }, 125 { 126 className: 'function', 127 beginKeywords: 'function', end: /\{/, excludeEnd: true, 128 contains: [ 129 hljs.inherit(hljs.TITLE_MODE, {begin: IDENT_RE}), 130 { 131 className: 'params', 132 begin: /\(/, end: /\)/, 133 excludeBegin: true, 134 excludeEnd: true, 135 contains: PARAMS_CONTAINS 136 } 137 ], 138 illegal: /\[|%/ 139 }, 140 { 141 begin: /\$[(.]/ 142 } 143 ], 144 illegal: /#(?!!)/ 145 }; 146 } 147 148 module.exports = arcade;