Skip to content

Commit 552fe0f

Browse files
committed
added empty list and empty structure handling
1 parent 511d1c9 commit 552fe0f

File tree

4 files changed

+22
-6
lines changed

4 files changed

+22
-6
lines changed

app/aem/core/src/main/antlr/ApmLang.g4

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ name
3333
;
3434

3535
privilegeName
36-
: IDENTIFIER ':' IDENTIFIER
36+
: IDENTIFIER COLON IDENTIFIER
3737
;
3838

3939
path
@@ -42,7 +42,7 @@ path
4242
;
4343

4444
array
45-
: ARRAY_BEGIN arrayValue (',' arrayValue)* ARRAY_END
45+
: ARRAY_BEGIN (arrayValue (COMMA arrayValue)*)? ARRAY_END
4646
;
4747

4848
arrayValue
@@ -53,11 +53,11 @@ arrayValue
5353
;
5454

5555
structure
56-
: STRUCTURE_BEGIN structureEntry (',' structureEntry)* STRUCTURE_END
56+
: STRUCTURE_BEGIN (structureEntry (COMMA structureEntry)*)? STRUCTURE_END
5757
;
5858

5959
structureEntry
60-
: structureKey ':' structureValue
60+
: structureKey COLON structureValue
6161
;
6262

6363
structureKey
@@ -156,7 +156,7 @@ flag
156156
;
157157

158158
body
159-
: BLOCK_BEGIN command+ BLOCK_END
159+
: BLOCK_BEGIN command* BLOCK_END
160160
;
161161

162162
/*
@@ -176,6 +176,12 @@ STRUCTURE_BEGIN
176176
STRUCTURE_END
177177
: '}'
178178
;
179+
COMMA
180+
: ','
181+
;
182+
COLON
183+
: ':'
184+
;
179185
BLOCK_BEGIN
180186
: 'begin'
181187
| 'BEGIN'

app/aem/core/src/main/java/com/cognifide/apm/core/grammar/ScriptRunner.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ public Status visitRequireVariable(RequireVariableContext ctx) {
145145
public Status visitForEach(ForEachContext ctx) {
146146
List<Map<String, ApmType>> values = readValues(ctx);
147147
ListIterator<Map<String, ApmType>> iterator = values.listIterator();
148+
if (!iterator.hasNext() && shouldVisitNextChild()) {
149+
String key = ctx.IDENTIFIER().toString();
150+
progress(ctx, Status.SKIPPED, "for-each", String.format("%s is always empty", key));
151+
}
148152
while (iterator.hasNext() && shouldVisitNextChild()) {
149153
try {
150154
int index = iterator.nextIndex();

app/aem/core/src/test/groovy/com/cognifide/apm/core/grammar/ScriptRunnerTest.groovy

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ class ScriptRunnerTest extends Specification {
9292
"Executing command SHOW \"t\"",
9393
"Executing command SHOW [3, \"ab\"]",
9494
"Executing command SHOW [\"a\", \"b\", \"c\", \"d\", 1, 2]",
95-
"Executing command SHOW [\n\t[\"a\", \"b\"],\n\t[\"c\", \"d\"]\n]"]
95+
"Executing command SHOW [\n\t[\"a\", \"b\"],\n\t[\"c\", \"d\"]\n]",
96+
"Executing command SHOW []",
97+
"Executing command SHOW {}"]
9698
}
9799

98100
def "run macro"() {

app/aem/core/src/test/resources/define.apm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ DEFINE tab3 [['a', 'b'], ['c', 'd']]
4343
DEFINE obj {x:'a', y:1, z:['c', 1], 't':'t'}
4444
DEFINE tabEnum [a, b, "c", "d", 1, 2]
4545
DEFINE tab4 [1 + 2, "a" + "b"]
46+
DEFINE emptyList []
47+
DEFINE emptyMap {}
4648
SHOW $a
4749
SHOW $b
4850
SHOW $tab1
@@ -60,3 +62,5 @@ SHOW ${obj[t]}
6062
SHOW $tab4
6163
SHOW $tabEnum
6264
SHOW $tab3
65+
SHOW $emptyList
66+
SHOW $emptyMap

0 commit comments

Comments
 (0)