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 | const IDENT_RE = '[A-Za-z_][0-9A-Za-z_]*';
|
---|
12 | const 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 | const SYMBOL = {
|
---|
31 | className: 'symbol',
|
---|
32 | begin: '\\$[datastore|feature|layer|map|measure|sourcefeature|sourcelayer|targetfeature|targetlayer|value|view]+'
|
---|
33 | };
|
---|
34 | const NUMBER = {
|
---|
35 | className: 'number',
|
---|
36 | variants: [
|
---|
37 | {
|
---|
38 | begin: '\\b(0[bB][01]+)'
|
---|
39 | },
|
---|
40 | {
|
---|
41 | begin: '\\b(0[oO][0-7]+)'
|
---|
42 | },
|
---|
43 | {
|
---|
44 | begin: hljs.C_NUMBER_RE
|
---|
45 | }
|
---|
46 | ],
|
---|
47 | relevance: 0
|
---|
48 | };
|
---|
49 | const SUBST = {
|
---|
50 | className: 'subst',
|
---|
51 | begin: '\\$\\{',
|
---|
52 | end: '\\}',
|
---|
53 | keywords: KEYWORDS,
|
---|
54 | contains: [] // defined later
|
---|
55 | };
|
---|
56 | const TEMPLATE_STRING = {
|
---|
57 | className: 'string',
|
---|
58 | begin: '`',
|
---|
59 | end: '`',
|
---|
60 | contains: [
|
---|
61 | hljs.BACKSLASH_ESCAPE,
|
---|
62 | SUBST
|
---|
63 | ]
|
---|
64 | };
|
---|
65 | SUBST.contains = [
|
---|
66 | hljs.APOS_STRING_MODE,
|
---|
67 | hljs.QUOTE_STRING_MODE,
|
---|
68 | TEMPLATE_STRING,
|
---|
69 | NUMBER,
|
---|
70 | hljs.REGEXP_MODE
|
---|
71 | ];
|
---|
72 | const PARAMS_CONTAINS = SUBST.contains.concat([
|
---|
73 | hljs.C_BLOCK_COMMENT_MODE,
|
---|
74 | hljs.C_LINE_COMMENT_MODE
|
---|
75 | ]);
|
---|
76 |
|
---|
77 | return {
|
---|
78 | name: 'ArcGIS Arcade',
|
---|
79 | keywords: KEYWORDS,
|
---|
80 | contains: [
|
---|
81 | hljs.APOS_STRING_MODE,
|
---|
82 | hljs.QUOTE_STRING_MODE,
|
---|
83 | TEMPLATE_STRING,
|
---|
84 | hljs.C_LINE_COMMENT_MODE,
|
---|
85 | hljs.C_BLOCK_COMMENT_MODE,
|
---|
86 | SYMBOL,
|
---|
87 | NUMBER,
|
---|
88 | { // object attr container
|
---|
89 | begin: /[{,]\s*/,
|
---|
90 | relevance: 0,
|
---|
91 | contains: [{
|
---|
92 | begin: IDENT_RE + '\\s*:',
|
---|
93 | returnBegin: true,
|
---|
94 | relevance: 0,
|
---|
95 | contains: [{
|
---|
96 | className: 'attr',
|
---|
97 | begin: IDENT_RE,
|
---|
98 | relevance: 0
|
---|
99 | }]
|
---|
100 | }]
|
---|
101 | },
|
---|
102 | { // "value" container
|
---|
103 | begin: '(' + hljs.RE_STARTERS_RE + '|\\b(return)\\b)\\s*',
|
---|
104 | keywords: 'return',
|
---|
105 | contains: [
|
---|
106 | hljs.C_LINE_COMMENT_MODE,
|
---|
107 | hljs.C_BLOCK_COMMENT_MODE,
|
---|
108 | hljs.REGEXP_MODE,
|
---|
109 | {
|
---|
110 | className: 'function',
|
---|
111 | begin: '(\\(.*?\\)|' + IDENT_RE + ')\\s*=>',
|
---|
112 | returnBegin: true,
|
---|
113 | end: '\\s*=>',
|
---|
114 | contains: [{
|
---|
115 | className: 'params',
|
---|
116 | variants: [
|
---|
117 | {
|
---|
118 | begin: IDENT_RE
|
---|
119 | },
|
---|
120 | {
|
---|
121 | begin: /\(\s*\)/
|
---|
122 | },
|
---|
123 | {
|
---|
124 | begin: /\(/,
|
---|
125 | end: /\)/,
|
---|
126 | excludeBegin: true,
|
---|
127 | excludeEnd: true,
|
---|
128 | keywords: KEYWORDS,
|
---|
129 | contains: PARAMS_CONTAINS
|
---|
130 | }
|
---|
131 | ]
|
---|
132 | }]
|
---|
133 | }
|
---|
134 | ],
|
---|
135 | relevance: 0
|
---|
136 | },
|
---|
137 | {
|
---|
138 | className: 'function',
|
---|
139 | beginKeywords: 'function',
|
---|
140 | end: /\{/,
|
---|
141 | excludeEnd: true,
|
---|
142 | contains: [
|
---|
143 | hljs.inherit(hljs.TITLE_MODE, {
|
---|
144 | begin: IDENT_RE
|
---|
145 | }),
|
---|
146 | {
|
---|
147 | className: 'params',
|
---|
148 | begin: /\(/,
|
---|
149 | end: /\)/,
|
---|
150 | excludeBegin: true,
|
---|
151 | excludeEnd: true,
|
---|
152 | contains: PARAMS_CONTAINS
|
---|
153 | }
|
---|
154 | ],
|
---|
155 | illegal: /\[|%/
|
---|
156 | },
|
---|
157 | {
|
---|
158 | begin: /\$[(.]/
|
---|
159 | }
|
---|
160 | ],
|
---|
161 | illegal: /#(?!!)/
|
---|
162 | };
|
---|
163 | }
|
---|
164 |
|
---|
165 | module.exports = arcade;
|
---|