Skip to content

Commit

Permalink
Merge pull request #424 from wttech/add-empty-list-maps
Browse files Browse the repository at this point in the history
added handling for empty lists and empty structures
  • Loading branch information
dprzybyl authored Nov 1, 2023
2 parents 9c1b3cd + d1450f1 commit eab40f8
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
14 changes: 10 additions & 4 deletions app/aem/core/src/main/antlr/ApmLang.g4
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ name
;

privilegeName
: IDENTIFIER ':' IDENTIFIER
: IDENTIFIER COLON IDENTIFIER
;

path
Expand All @@ -42,7 +42,7 @@ path
;

array
: ARRAY_BEGIN arrayValue (',' arrayValue)* ARRAY_END
: ARRAY_BEGIN (arrayValue (COMMA arrayValue)*)? ARRAY_END
;

arrayValue
Expand All @@ -53,11 +53,11 @@ arrayValue
;

structure
: STRUCTURE_BEGIN structureEntry (',' structureEntry)* STRUCTURE_END
: STRUCTURE_BEGIN (structureEntry (COMMA structureEntry)*)? STRUCTURE_END
;

structureEntry
: structureKey ':' structureValue
: structureKey COLON structureValue
;

structureKey
Expand Down Expand Up @@ -176,6 +176,12 @@ STRUCTURE_BEGIN
STRUCTURE_END
: '}'
;
COMMA
: ','
;
COLON
: ':'
;
BLOCK_BEGIN
: 'begin'
| 'BEGIN'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ public Status visitRequireVariable(RequireVariableContext ctx) {
public Status visitForEach(ForEachContext ctx) {
List<Map<String, ApmType>> values = readValues(ctx);
ListIterator<Map<String, ApmType>> iterator = values.listIterator();
if (!iterator.hasNext() && shouldVisitNextChild()) {
String key = ctx.IDENTIFIER().toString();
progress(ctx, Status.SKIPPED, "for-each", String.format("%s is always empty", key));
}
while (iterator.hasNext() && shouldVisitNextChild()) {
try {
int index = iterator.nextIndex();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ class ScriptRunnerTest extends Specification {
"Executing command SHOW \"t\"",
"Executing command SHOW [3, \"ab\"]",
"Executing command SHOW [\"a\", \"b\", \"c\", \"d\", 1, 2]",
"Executing command SHOW [\n\t[\"a\", \"b\"],\n\t[\"c\", \"d\"]\n]"]
"Executing command SHOW [\n\t[\"a\", \"b\"],\n\t[\"c\", \"d\"]\n]",
"Executing command SHOW []",
"Executing command SHOW {}"]
}

def "run macro"() {
Expand Down
4 changes: 4 additions & 0 deletions app/aem/core/src/test/resources/define.apm
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ DEFINE tab3 [['a', 'b'], ['c', 'd']]
DEFINE obj {x:'a', y:1, z:['c', 1], 't':'t'}
DEFINE tabEnum [a, b, "c", "d", 1, 2]
DEFINE tab4 [1 + 2, "a" + "b"]
DEFINE emptyList []
DEFINE emptyMap {}
SHOW $a
SHOW $b
SHOW $tab1
Expand All @@ -60,3 +62,5 @@ SHOW ${obj[t]}
SHOW $tab4
SHOW $tabEnum
SHOW $tab3
SHOW $emptyList
SHOW $emptyMap

0 comments on commit eab40f8

Please sign in to comment.