diff --git a/app/aem/core/src/main/antlr/ApmLang.g4 b/app/aem/core/src/main/antlr/ApmLang.g4 index 9428dc380..320302369 100644 --- a/app/aem/core/src/main/antlr/ApmLang.g4 +++ b/app/aem/core/src/main/antlr/ApmLang.g4 @@ -25,7 +25,7 @@ grammar ApmLang; */ apm - : command+ + : command+ EOF ; name diff --git a/app/aem/core/src/main/kotlin/com/cognifide/apm/core/grammar/parsedscript/ApmLangParserFactory.kt b/app/aem/core/src/main/kotlin/com/cognifide/apm/core/grammar/parsedscript/ApmLangParserFactory.kt index 556763428..da919fca4 100644 --- a/app/aem/core/src/main/kotlin/com/cognifide/apm/core/grammar/parsedscript/ApmLangParserFactory.kt +++ b/app/aem/core/src/main/kotlin/com/cognifide/apm/core/grammar/parsedscript/ApmLangParserFactory.kt @@ -48,6 +48,10 @@ object ApmLangParserFactory { throw InvalidSyntaxException(InputMismatchException(recognizer)) } + override fun reportError(recognizer: Parser?, e: RecognitionException?) { + throw InvalidSyntaxException(e!!) + } + override fun sync(recognizer: Parser) {} } 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 b54f7ab9a..36b10cb0b 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 @@ -23,7 +23,6 @@ package com.cognifide.apm.core.grammar import com.cognifide.apm.api.scripts.Script import com.cognifide.apm.api.services.ScriptFinder import com.cognifide.apm.api.status.Status -import com.cognifide.apm.core.grammar.argument.Arguments import com.cognifide.apm.core.progress.ProgressImpl import org.apache.commons.io.IOUtils import org.apache.sling.api.resource.ResourceResolver @@ -104,7 +103,7 @@ class ScriptRunnerTest extends Specification { def result = scriptExecutor.execute(script, new ProgressImpl("")) then: - result.entries.size() == 3 + result.entries.size() == 7 result.entries[0].messages == ["Import from script /import-define.apm. Notice, only DEFINE actions were processed!", "Imported variable: var=\"imported val\""] @@ -116,6 +115,11 @@ class ScriptRunnerTest extends Specification { result.entries[2].messages == ["Import from script /import-deep-define.apm. Notice, only DEFINE actions were processed!", "Imported variable: deepNamespace={deeperNamespace: {var: \"imported val\"}, deepVar: \"imported val + imported val\"}"] + + result.entries[3].command == "Executing command SHOW \"imported val\"" + result.entries[4].command == "Executing command SHOW \"imported val\"" + result.entries[5].command == "Executing command SHOW \"imported val\"" + result.entries[6].command == "Executing command SHOW \"imported val + imported val\"" } def "run script filename.apm"() { diff --git a/app/aem/core/src/test/groovy/com/cognifide/apm/core/grammar/parsedscript/ParsedScriptTest.groovy b/app/aem/core/src/test/groovy/com/cognifide/apm/core/grammar/parsedscript/ParsedScriptTest.groovy index f44bc970a..333783f49 100644 --- a/app/aem/core/src/test/groovy/com/cognifide/apm/core/grammar/parsedscript/ParsedScriptTest.groovy +++ b/app/aem/core/src/test/groovy/com/cognifide/apm/core/grammar/parsedscript/ParsedScriptTest.groovy @@ -44,8 +44,20 @@ class ParsedScriptTest extends Specification { error == output where: - file | output - "/invalid1.apm" | ["Invalid line [20:7]: DEFINE \$ nana", "Invalid sequence: \$"] - "/invalid2.apm" | ["Invalid line [20:7]: DEFINE / nana"] + file | output + "/invalid/invalid1.apm" | ["Invalid line [20:7]: DEFINE \$ nana", "Invalid sequence: \$"] + "/invalid/invalid2.apm" | ["Invalid line [20:7]: DEFINE / nana"] + "/invalid/invalid3.apm" | ["Invalid line [20:0]: // define variable", "Invalid sequence: //"] + "/invalid/invalid4.apm" | ["Invalid line [20:0]: / define variable"] + "/invalid/invalid5.apm" | ["Invalid line [20:0]: /x define variable", "Invalid sequence: /x"] + "/invalid/invalid6.apm" | ["Invalid line [20:0]: /* define variable", "Invalid sequence: /*"] + "/invalid/invalid7.apm" | ["Invalid line [20:0]: diff --git a/app/aem/core/src/test/resources/invalid/invalid13.apm b/app/aem/core/src/test/resources/invalid/invalid13.apm new file mode 100644 index 000000000..6ac88d297 --- /dev/null +++ b/app/aem/core/src/test/resources/invalid/invalid13.apm @@ -0,0 +1,21 @@ + + # ========================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 variable" +DEFINE nana "nana" diff --git a/app/aem/core/src/test/resources/invalid/invalid14.apm b/app/aem/core/src/test/resources/invalid/invalid14.apm new file mode 100644 index 000000000..90ff2e9b6 --- /dev/null +++ b/app/aem/core/src/test/resources/invalid/invalid14.apm @@ -0,0 +1,21 @@ + + # ========================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 nana "nana" +"define variable" diff --git a/app/aem/core/src/test/resources/invalid2.apm b/app/aem/core/src/test/resources/invalid/invalid2.apm similarity index 100% rename from app/aem/core/src/test/resources/invalid2.apm rename to app/aem/core/src/test/resources/invalid/invalid2.apm diff --git a/app/aem/core/src/test/resources/invalid/invalid3.apm b/app/aem/core/src/test/resources/invalid/invalid3.apm new file mode 100644 index 000000000..853619fac --- /dev/null +++ b/app/aem/core/src/test/resources/invalid/invalid3.apm @@ -0,0 +1,21 @@ + + # ========================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 variable +DEFINE / nana diff --git a/app/aem/core/src/test/resources/invalid/invalid4.apm b/app/aem/core/src/test/resources/invalid/invalid4.apm new file mode 100644 index 000000000..b0a87e6dd --- /dev/null +++ b/app/aem/core/src/test/resources/invalid/invalid4.apm @@ -0,0 +1,21 @@ + + # ========================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 variable +DEFINE / nana diff --git a/app/aem/core/src/test/resources/invalid/invalid5.apm b/app/aem/core/src/test/resources/invalid/invalid5.apm new file mode 100644 index 000000000..ebe4a4cc8 --- /dev/null +++ b/app/aem/core/src/test/resources/invalid/invalid5.apm @@ -0,0 +1,21 @@ + + # ========================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================================== + +/x define variable +DEFINE / nana diff --git a/app/aem/core/src/test/resources/invalid/invalid6.apm b/app/aem/core/src/test/resources/invalid/invalid6.apm new file mode 100644 index 000000000..013ed0b1e --- /dev/null +++ b/app/aem/core/src/test/resources/invalid/invalid6.apm @@ -0,0 +1,22 @@ + + # ========================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 variable +*/ +DEFINE / nana diff --git a/app/aem/core/src/test/resources/invalid/invalid7.apm b/app/aem/core/src/test/resources/invalid/invalid7.apm new file mode 100644 index 000000000..0c092ad4a --- /dev/null +++ b/app/aem/core/src/test/resources/invalid/invalid7.apm @@ -0,0 +1,22 @@ + + # ========================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 / nana diff --git a/app/aem/core/src/test/resources/invalid/invalid8.apm b/app/aem/core/src/test/resources/invalid/invalid8.apm new file mode 100644 index 000000000..3179844bb --- /dev/null +++ b/app/aem/core/src/test/resources/invalid/invalid8.apm @@ -0,0 +1,21 @@ + + # ========================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 nana "nana" +// define variable diff --git a/app/aem/core/src/test/resources/invalid/invalid9.apm b/app/aem/core/src/test/resources/invalid/invalid9.apm new file mode 100644 index 000000000..84e8a1f2b --- /dev/null +++ b/app/aem/core/src/test/resources/invalid/invalid9.apm @@ -0,0 +1,21 @@ + + # ========================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 nana "nana" +/ define variable