diff --git a/app/aem/core/src/main/antlr/ApmLang.g4 b/app/aem/core/src/main/antlr/ApmLang.g4 index bc3e12b9..9b7c6df5 100644 --- a/app/aem/core/src/main/antlr/ApmLang.g4 +++ b/app/aem/core/src/main/antlr/ApmLang.g4 @@ -42,7 +42,7 @@ path ; array - : ARRAY_BEGIN arrayValue (COMMA arrayValue)* ARRAY_END + : ARRAY_BEGIN arrayValue (',' arrayValue)* ARRAY_END ; arrayValue @@ -53,7 +53,7 @@ arrayValue ; structure - : STRUCTURE_BEGIN structureEntry (COMMA structureEntry)* STRUCTURE_END + : STRUCTURE_BEGIN structureEntry (',' structureEntry)* STRUCTURE_END ; structureEntry @@ -116,8 +116,6 @@ command | FOR_EACH IDENTIFIER IN argument body # ForEach | DEFINE IDENTIFIER argument # DefineVariable | REQUIRE IDENTIFIER # RequireVariable - | REGISTER_MACRO identifier variableList? body # RegisterMacro - | RUN_MACRO identifier argumentList? # RunMacro | (ALLOW | DENY) argument ON? complexArguments # AllowDenyCommand | commandName complexArguments? body? # GenericCommand ; @@ -161,14 +159,6 @@ body : BLOCK_BEGIN command+ BLOCK_END ; -variableList - : BRACKET_BEGIN IDENTIFIER (COMMA IDENTIFIER)* BRACKET_END - ; - -argumentList - : BRACKET_BEGIN argument (COMMA argument)* BRACKET_END - ; - /* * Lexer Rules */ @@ -186,15 +176,6 @@ STRUCTURE_BEGIN STRUCTURE_END : '}' ; -BRACKET_BEGIN - : '(' - ; -BRACKET_END - : ')' - ; -COMMA - : ',' - ; BLOCK_BEGIN : 'begin' | 'BEGIN' @@ -223,14 +204,6 @@ DEFINE : 'define' | 'DEFINE' ; -REGISTER_MACRO - : 'register-macro' - | 'REGISTER-MACRO' - ; -RUN_MACRO - : 'run-macro' - | 'RUN-MACRO' - ; REQUIRE : 'require' | 'REQUIRE' diff --git a/app/aem/core/src/main/java/com/cognifide/apm/core/grammar/macro/Macro.java b/app/aem/core/src/main/java/com/cognifide/apm/core/grammar/macro/Macro.java deleted file mode 100644 index 6963c7a5..00000000 --- a/app/aem/core/src/main/java/com/cognifide/apm/core/grammar/macro/Macro.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * ========================LICENSE_START================================= - * AEM Permission Management - * %% - * Copyright (C) 2013 Wunderman Thompson Technology - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * =========================LICENSE_END================================== - */ -package com.cognifide.apm.core.grammar.macro; - -import com.cognifide.apm.core.grammar.antlr.ApmLangParser; - -import java.util.List; - -public class Macro { - - private final String macroName; - - private final List variableList; - - private final ApmLangParser.BodyContext body; - - public Macro(String macroName, List variableList, ApmLangParser.BodyContext body) { - this.macroName = macroName; - this.variableList = variableList; - this.body = body; - } - - public String getMacroName() { - return macroName; - } - - public List getVariableList() { - return variableList; - } - - public ApmLangParser.BodyContext getBody() { - return body; - } -} diff --git a/app/aem/core/src/main/kotlin/com/cognifide/apm/core/grammar/ScriptRunner.kt b/app/aem/core/src/main/kotlin/com/cognifide/apm/core/grammar/ScriptRunner.kt index 20febccd..15a466e8 100644 --- a/app/aem/core/src/main/kotlin/com/cognifide/apm/core/grammar/ScriptRunner.kt +++ b/app/aem/core/src/main/kotlin/com/cognifide/apm/core/grammar/ScriptRunner.kt @@ -29,7 +29,6 @@ import com.cognifide.apm.core.grammar.argument.Arguments import com.cognifide.apm.core.grammar.common.getIdentifier import com.cognifide.apm.core.grammar.common.getPath import com.cognifide.apm.core.grammar.executioncontext.ExecutionContext -import com.cognifide.apm.core.grammar.macro.Macro import com.cognifide.apm.core.grammar.parsedscript.InvalidSyntaxException import com.cognifide.apm.core.grammar.parsedscript.InvalidSyntaxMessageFactory import com.cognifide.apm.core.grammar.utils.ImportScript @@ -224,45 +223,6 @@ class ScriptRunner( return Status.SUCCESS } - override fun visitRegisterMacro(ctx: RegisterMacroContext): Status { - val macroName = getIdentifier(ctx.identifier()) - val variableList = ctx.variableList() - ?.IDENTIFIER() - ?.map { it.toString() } - ?: listOf() - val body = ctx.body() - executionContext.registerMacro(Macro(macroName, variableList, body)) - return Status.SUCCESS - } - - override fun visitRunMacro(ctx: RunMacroContext): Status { - val macroName = getIdentifier(ctx.identifier()) - val macro = executionContext.fetchMacro(macroName) - if (macro == null) { - progress(ctx, Status.ERROR, "run-macro", "Macro \"$macroName\" is not registered") - } else { - val argumentList = ctx.argumentList() - ?.argument() - ?.map { executionContext.resolveArgument(it) } - ?: listOf() - val values = macro.variableList - .zip(argumentList) - .toMap() - try { - executionContext.createLocalContext() - val valueStr = values.map { it.key + "=" + it.value } - .joinToString() - progress(ctx, Status.SUCCESS, "run-macro", "Begin: $valueStr") - values.forEach { (k, v) -> executionContext.setVariable(k, v) } - visit(macro.body) - progress(ctx, Status.SUCCESS, "run-macro", "End") - } finally { - executionContext.removeLocalContext() - } - } - return Status.SUCCESS - } - private fun readValues(ctx: ForEachContext): List> { val keys = listOf(ctx.IDENTIFIER().toString()) val values = when (val variableValue = executionContext.resolveArgument(ctx.argument())) { diff --git a/app/aem/core/src/main/kotlin/com/cognifide/apm/core/grammar/executioncontext/ExecutionContext.kt b/app/aem/core/src/main/kotlin/com/cognifide/apm/core/grammar/executioncontext/ExecutionContext.kt index e208797f..e8664291 100644 --- a/app/aem/core/src/main/kotlin/com/cognifide/apm/core/grammar/executioncontext/ExecutionContext.kt +++ b/app/aem/core/src/main/kotlin/com/cognifide/apm/core/grammar/executioncontext/ExecutionContext.kt @@ -28,7 +28,6 @@ import com.cognifide.apm.core.grammar.antlr.ApmLangParser.* import com.cognifide.apm.core.grammar.argument.ArgumentResolver import com.cognifide.apm.core.grammar.argument.Arguments import com.cognifide.apm.core.grammar.common.StackWithRoot -import com.cognifide.apm.core.grammar.macro.Macro import com.cognifide.apm.core.grammar.parsedscript.ParsedScript import com.cognifide.apm.core.logger.Progress import org.apache.commons.lang3.StringUtils @@ -36,15 +35,13 @@ import org.apache.jackrabbit.api.security.user.Authorizable import org.apache.sling.api.resource.ResourceResolver class ExecutionContext private constructor( - private val scriptFinder: ScriptFinder, - private val resourceResolver: ResourceResolver, - val root: ParsedScript, - override val progress: Progress -) : ExternalExecutionContext { + private val scriptFinder: ScriptFinder, + private val resourceResolver: ResourceResolver, + val root: ParsedScript, + override val progress: Progress) : ExternalExecutionContext { private val parsedScripts: MutableMap = mutableMapOf() private var runScripts: StackWithRoot = StackWithRoot(RunScript(root)) - private val registeredMacros: MutableMap = mutableMapOf() val currentRunScript: RunScript get() = runScripts.peek() @@ -59,12 +56,7 @@ class ExecutionContext private constructor( companion object { @JvmStatic - fun create( - scriptFinder: ScriptFinder, - resourceResolver: ResourceResolver, - script: Script, - progress: Progress - ): ExecutionContext { + fun create(scriptFinder: ScriptFinder, resourceResolver: ResourceResolver, script: Script, progress: Progress): ExecutionContext { return ExecutionContext(scriptFinder, resourceResolver, ParsedScript.create(script), progress) } } @@ -124,7 +116,7 @@ class ExecutionContext private constructor( private fun fetchScript(path: String): ParsedScript { val script = scriptFinder.find(path, resourceResolver) - ?: throw ScriptExecutionException("Script not found $path") + ?: throw ScriptExecutionException("Script not found $path") val parsedScript = ParsedScript.create(script) registerScript(parsedScript) return parsedScript @@ -141,10 +133,4 @@ class ExecutionContext private constructor( StringUtils.substringBeforeLast(runScripts.peek().path, "/") + "/" + path } } - - fun registerMacro(macro: Macro) { - registeredMacros[macro.macroName] = macro - } - - fun fetchMacro(macroName: String): Macro? = registeredMacros[macroName] } diff --git a/app/aem/core/src/test/groovy/com/cognifide/apm/core/grammar/ScriptRunnerTest.groovy b/app/aem/core/src/test/groovy/com/cognifide/apm/core/grammar/ScriptRunnerTest.groovy index 06e131a6..25b1e6dc 100644 --- a/app/aem/core/src/test/groovy/com/cognifide/apm/core/grammar/ScriptRunnerTest.groovy +++ b/app/aem/core/src/test/groovy/com/cognifide/apm/core/grammar/ScriptRunnerTest.groovy @@ -95,27 +95,6 @@ class ScriptRunnerTest extends Specification { "Executing command SHOW [[\"a\", \"b\"], [\"c\", \"d\"]]"] } - def "run macro"() { - given: - Script script = createScript("/macro.apm") - - when: - def result = scriptExecutor.execute(script, new ProgressImpl("")) - - then: - def commands = result.entries - .collect { it.command } - .findAll { it.startsWith("Executing") } - commands == ["Executing command SHOW \"simpleMacro\"", - "Executing command SHOW \"parameterizedMacro1 param\"", - "Executing command SHOW \"parameterizedMacro2 param1 param2\"", - "Executing command SHOW \"parameterizedMacro1 ab\"", - "Executing command SHOW \"parameterizedMacro2 a b\"", - "Executing command SHOW \"parameterizedMacroOuter param\"", - "Executing command SHOW \"parameterizedMacroInner param 1\"", - "Executing command SHOW \"parameterizedMacroInner param 2\""] - } - def "run import"() { given: Script script = createScript("/import.apm") diff --git a/app/aem/core/src/test/resources/macro.apm b/app/aem/core/src/test/resources/macro.apm deleted file mode 100644 index 9c5b05ac..00000000 --- a/app/aem/core/src/test/resources/macro.apm +++ /dev/null @@ -1,49 +0,0 @@ - # ========================LICENSE_START================================= - # AEM Permission Management - # %% - # Copyright (C) 2013 Wunderman Thompson Technology - # %% - # Licensed under the Apache License, Version 2.0 (the "License"); - # you may not use this file except in compliance with the License. - # You may obtain a copy of the License at - # - # http://www.apache.org/licenses/LICENSE-2.0 - # - # Unless required by applicable law or agreed to in writing, software - # distributed under the License is distributed on an "AS IS" BASIS, - # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - # See the License for the specific language governing permissions and - # limitations under the License. - # =========================LICENSE_END================================== - -DEFINE str1 'a' -DEFINE str2 'b' - -REGISTER-MACRO simpleMacro BEGIN - SHOW 'simpleMacro' -END - -REGISTER-MACRO parameterizedMacro1(param) BEGIN - SHOW 'parameterizedMacro1 ${param}' -END - -REGISTER-MACRO parameterizedMacro2(param1, param2) BEGIN - SHOW 'parameterizedMacro2 ${param1} ${param2}' -END - -REGISTER-MACRO parameterizedMacroOuter(param) BEGIN - SHOW 'parameterizedMacroOuter ${param}' - RUN-MACRO parameterizedMacroInner($param, '1') - RUN-MACRO parameterizedMacroInner($param, '2') -END - -REGISTER-MACRO parameterizedMacroInner(param1, param2) BEGIN - SHOW 'parameterizedMacroInner ${param1} ${param2}' -END - -RUN-MACRO simpleMacro -RUN-MACRO parameterizedMacro1('param') -RUN-MACRO parameterizedMacro2('param1', 'param2') -RUN-MACRO parameterizedMacro1($str1 + $str2) -RUN-MACRO parameterizedMacro2($str1, $str2) -RUN-MACRO parameterizedMacroOuter('param')