Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added handling for empty lists and empty structures #424

Merged
merged 2 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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