Skip to content
Permalink
Browse files

Feat: New Language ArcGIS Arcade (#1371)

ArcGIS Arcade is an expression language based on JavaScript
  • Loading branch information...
jf990 authored and marcoscaceres committed Sep 6, 2018
1 parent 2734ca6 commit 101ec4fc0ffa090b3da500107f2b2890bd9538fb
@@ -157,6 +157,8 @@ Language names and aliases
+-------------------------+---------------------------------------------------+
| AppleScript | applescript, osascript |
+-------------------------+---------------------------------------------------+
| Arcade | arcade |
+-------------------------+---------------------------------------------------+
| AsciiDoc | asciidoc, adoc |
+-------------------------+---------------------------------------------------+
| AspectJ | aspectj |
@@ -0,0 +1,142 @@
/*
Language: ArcGIS Arcade
Category: scripting
Author: John Foster <jfoster@esri.com>
Description: ArcGIS Arcade is an expression language used in many Esri ArcGIS products such as Pro, Online, Server, Runtime, JavaScript, and Python
*/
function(hljs) {
var IDENT_RE = '[A-Za-z_][0-9A-Za-z_]*';
var KEYWORDS = {
keyword:
'if for while var new function do return void else break',
literal:
'true false null undefined NaN Infinity PI BackSlash DoubleQuote ForwardSlash NewLine SingleQuote Tab',
built_in:
'Abs Acos Area AreaGeodetic Asin Atan Atan2 Average Boolean Buffer BufferGeodetic ' +
'Ceil Centroid Clip Console Constrain Contains Cos Count Crosses Cut Date DateAdd ' +
'DateDiff Day Decode DefaultValue Dictionary Difference Disjoint Distance Distinct ' +
'DomainCode DomainName Equals Exp Extent Feature FeatureSet FeatureSetById FeatureSetByTitle ' +
'FeatureSetByUrl Filter First Floor Geometry Guid HasKey Hour IIf IndexOf Intersection ' +
'Intersects IsEmpty Length LengthGeodetic Log Max Mean Millisecond Min Minute Month ' +
'MultiPartToSinglePart Multipoint NextSequenceValue Now Number OrderBy Overlaps Point Polygon ' +
'Polyline Pow Random Relate Reverse Round Second SetGeometry Sin Sort Sqrt Stdev Sum ' +
'SymmetricDifference Tan Text Timestamp Today ToLocal Top Touches ToUTC TypeOf Union Variance ' +
'Weekday When Within Year '
};
var EXPRESSIONS;
var SYMBOL = {
className: 'symbol',
begin: '\\$[feature|layer|map|value|view]+'
};
var NUMBER = {
className: 'number',
variants: [
{ begin: '\\b(0[bB][01]+)' },
{ begin: '\\b(0[oO][0-7]+)' },
{ begin: hljs.C_NUMBER_RE }
],
relevance: 0
};
var SUBST = {
className: 'subst',
begin: '\\$\\{', end: '\\}',
keywords: KEYWORDS,
contains: [] // defined later
};
var TEMPLATE_STRING = {
className: 'string',
begin: '`', end: '`',
contains: [
hljs.BACKSLASH_ESCAPE,
SUBST
]
};
SUBST.contains = [
hljs.APOS_STRING_MODE,
hljs.QUOTE_STRING_MODE,
TEMPLATE_STRING,
NUMBER,
hljs.REGEXP_MODE
];
var PARAMS_CONTAINS = SUBST.contains.concat([
hljs.C_BLOCK_COMMENT_MODE,
hljs.C_LINE_COMMENT_MODE
]);

return {
aliases: ['arcade'],
keywords: KEYWORDS,
contains: [
hljs.APOS_STRING_MODE,
hljs.QUOTE_STRING_MODE,
TEMPLATE_STRING,
hljs.C_LINE_COMMENT_MODE,
hljs.C_BLOCK_COMMENT_MODE,
SYMBOL,
NUMBER,
{ // object attr container
begin: /[{,]\s*/, relevance: 0,
contains: [
{
begin: IDENT_RE + '\\s*:', returnBegin: true,
relevance: 0,
contains: [{className: 'attr', begin: IDENT_RE, relevance: 0}]
}
]
},
{ // "value" container
begin: '(' + hljs.RE_STARTERS_RE + '|\\b(return)\\b)\\s*',
keywords: 'return',
contains: [
hljs.C_LINE_COMMENT_MODE,
hljs.C_BLOCK_COMMENT_MODE,
hljs.REGEXP_MODE,
{
className: 'function',
begin: '(\\(.*?\\)|' + IDENT_RE + ')\\s*=>', returnBegin: true,
end: '\\s*=>',
contains: [
{
className: 'params',
variants: [
{
begin: IDENT_RE
},
{
begin: /\(\s*\)/,
},
{
begin: /\(/, end: /\)/,
excludeBegin: true, excludeEnd: true,
keywords: KEYWORDS,
contains: PARAMS_CONTAINS
}
]
}
]
}
],
relevance: 0
},
{
className: 'function',
beginKeywords: 'function', end: /\{/, excludeEnd: true,
contains: [
hljs.inherit(hljs.TITLE_MODE, {begin: IDENT_RE}),
{
className: 'params',
begin: /\(/, end: /\)/,
excludeBegin: true,
excludeEnd: true,
contains: PARAMS_CONTAINS
}
],
illegal: /\[|%/
},
{
begin: /\$[(.]/
}
],
illegal: /#(?!!)/
};
}
@@ -0,0 +1,14 @@
function testGeometry(element, point) {
if (point.y != -1)
return point;
for (var i = 0 / 2; i < element.length; i++) {
if (checkCondition($map.element[i]) === Infinity) {
return element[i];
}
}
return element;
}

var filePath = "literal " + TextFormatting.BackSlash + TextFormatting.SingleQuote + ".ext"
var d = Dictionary("field1", 1, "field2",2);
return testGeometry(Geometry(d["field1"], filePath);
@@ -0,0 +1,9 @@
<span class="hljs-comment">/*
Isolated test for the most recent version
*/</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">offsetPopulation</span>(<span class="hljs-params">offset</span>)</span>{
<span class="hljs-keyword">var</span> popDensity = <span class="hljs-built_in">Round</span>( <span class="hljs-symbol">$feature</span>.POPULATION / <span class="hljs-built_in">AreaGeodetic</span>(<span class="hljs-built_in">Geometry</span>(<span class="hljs-symbol">$feature</span>), <span class="hljs-string">"square-kilometers"</span>) );
<span class="hljs-keyword">var</span> geom = <span class="hljs-built_in">Geometry</span>({ <span class="hljs-string">'x'</span>: offset.x, <span class="hljs-string">'y'</span>: offset.y, <span class="hljs-string">'spatialReference'</span>:{<span class="hljs-string">'wkid'</span>:<span class="hljs-number">102100</span>} });
<span class="hljs-keyword">var</span> myLayer = <span class="hljs-built_in">FeatureSet</span>(<span class="hljs-symbol">$map</span>, [<span class="hljs-string">"POPULATION"</span>, <span class="hljs-string">"ELECTION-DATA"</span>]);
<span class="hljs-keyword">return</span> popDensity;
}
@@ -0,0 +1,9 @@
/*
Isolated test for the most recent version
*/
function offsetPopulation(offset){
var popDensity = Round( $feature.POPULATION / AreaGeodetic(Geometry($feature), "square-kilometers") );
var geom = Geometry({ 'x': offset.x, 'y': offset.y, 'spatialReference':{'wkid':102100} });
var myLayer = FeatureSet($map, ["POPULATION", "ELECTION-DATA"]);
return popDensity;
}

0 comments on commit 101ec4f

Please sign in to comment.
You can’t perform that action at this time.