From 7047b74151735c17ecd7ee291d9feff519b5f50c Mon Sep 17 00:00:00 2001 From: reidspencer Date: Tue, 3 Oct 2023 10:18:01 -0400 Subject: [PATCH] Make app and epic syntax more palatable You can now you various aliases for "input", "output" and "group". These are recognized in both the Application definition and in their use in epic case steps Signed-off-by: reidspencer --- .../language/parsing/ApplicationParser.scala | 35 +++---------------- .../riddl/language/parsing/CommonParser.scala | 27 ++++++++++++++ .../language/parsing/ReferenceParser.scala | 19 +++++----- testkit/src/test/input/issues/447.riddl | 21 +++++++++++ .../riddl/testkit/ReportedIssuesTest.scala | 8 +++++ 5 files changed, 70 insertions(+), 40 deletions(-) create mode 100644 testkit/src/test/input/issues/447.riddl diff --git a/language/src/main/scala/com/reactific/riddl/language/parsing/ApplicationParser.scala b/language/src/main/scala/com/reactific/riddl/language/parsing/ApplicationParser.scala index a7de1e112..ab08769c9 100644 --- a/language/src/main/scala/com/reactific/riddl/language/parsing/ApplicationParser.scala +++ b/language/src/main/scala/com/reactific/riddl/language/parsing/ApplicationParser.scala @@ -17,7 +17,8 @@ private[parsing] trait ApplicationParser { with ReferenceParser with HandlerParser with StatementParser - with TypeParser => + with TypeParser + with CommonParser => private def applicationOptions[u: P]: P[Seq[ApplicationOption]] = { options[u, ApplicationOption](StringIn(Options.technology).!) { case (loc, Options.technology, args) => @@ -25,13 +26,7 @@ private[parsing] trait ApplicationParser { } } - private def groupAliases[u: P]: P[String] = { - P( - StringIn(Keywords.group, "page", "pane", "dialog", "popup", "frame", "column", "window", "section", "tab").! - ) - } - - private def groupDefinitions[u:P]: P[Seq[GroupDefinition]] = { + private def groupDefinitions[u: P]: P[Seq[GroupDefinition]] = { P { undefined(Seq.empty[GroupDefinition]) | (group | appOutput | appInput).rep(0) } @@ -40,27 +35,13 @@ private[parsing] trait ApplicationParser { private def group[u: P]: P[Group] = { P( location ~ groupAliases ~ identifier ~/ is ~ open ~ - groupDefinitions ~ - close ~ briefly ~ description + groupDefinitions ~ + close ~ briefly ~ description ).map { case (loc, alias, id, elements, brief, description) => Group(loc, alias, id, elements, brief, description) } } - private def outputAliases[u: P]: P[String] = { - P( - StringIn( - Keywords.output, - "document", - "list", - "table", - "graph", - "animation", - "picture" - ).! - ) - } - private def presentationAliases[u: P]: P[Unit] = { StringIn(Keywords.presents, "shows", "displays", "writes", "emits") } @@ -83,12 +64,6 @@ private[parsing] trait ApplicationParser { } } - private def inputAliases[u: P]: P[String] = { - P( - StringIn(Keywords.input, "form", "textblock", "button", "picklist").! - ) - } - private def inputDefinitions[uP: P]: P[Seq[InputDefinition]] = { P( is ~ open ~ diff --git a/language/src/main/scala/com/reactific/riddl/language/parsing/CommonParser.scala b/language/src/main/scala/com/reactific/riddl/language/parsing/CommonParser.scala index 4105e9bd7..e32235856 100644 --- a/language/src/main/scala/com/reactific/riddl/language/parsing/CommonParser.scala +++ b/language/src/main/scala/com/reactific/riddl/language/parsing/CommonParser.scala @@ -226,4 +226,31 @@ private[parsing] trait CommonParser extends NoWhiteSpaceParsers { def term[u: P]: P[Term] = { P(location ~ Keywords.term ~ identifier ~ is ~ briefly ~ description)./.map(tpl => (Term.apply _).tupled(tpl)) } + + def groupAliases[u: P]: P[String] = { + P( + StringIn(Keywords.group, "page", "pane", "dialog", "popup", "frame", "column", "window", "section", "tab").! + ) + } + + def inputAliases[u: P]: P[String] = { + P( + StringIn(Keywords.input, "form", "text", "button", "picklist", "select").! + ) + } + + def outputAliases[u: P]: P[String] = { + P( + StringIn( + Keywords.output, + "document", + "list", + "table", + "graph", + "animation", + "picture" + ).! + ) + } + } diff --git a/language/src/main/scala/com/reactific/riddl/language/parsing/ReferenceParser.scala b/language/src/main/scala/com/reactific/riddl/language/parsing/ReferenceParser.scala index 1ce068dbc..c3d5f850a 100644 --- a/language/src/main/scala/com/reactific/riddl/language/parsing/ReferenceParser.scala +++ b/language/src/main/scala/com/reactific/riddl/language/parsing/ReferenceParser.scala @@ -156,18 +156,18 @@ private[parsing] trait ReferenceParser extends CommonParser { } def outputRef[u: P]: P[OutputRef] = { - P(location ~ Keywords.output ~ pathIdentifier) - .map(tpl => (OutputRef.apply _).tupled(tpl)) + P(location ~ outputAliases ~ pathIdentifier) + .map { case (loc, _, pid) => OutputRef(loc, pid) } } def inputRef[u: P]: P[InputRef] = { - P(location ~ Keywords.input ~ pathIdentifier) - .map(tpl => (InputRef.apply _).tupled(tpl)) + P(location ~ inputAliases ~ pathIdentifier) + .map { case (loc, _, pid) => InputRef(loc, pid) } } - def groupRef[u:P]: P[GroupRef] = { - P(location ~ Keywords.group ~ pathIdentifier) - .map(tpl => (GroupRef.apply _).tupled(tpl)) + def groupRef[u: P]: P[GroupRef] = { + P(location ~ groupAliases ~ pathIdentifier) + .map { case (loc, _, pid) => GroupRef(loc, pid) } } def authorRefs[u: P]: P[Seq[AuthorRef]] = { @@ -183,11 +183,10 @@ private[parsing] trait ReferenceParser extends CommonParser { ) } - def arbitraryInteractionRef[u:P]: P[Reference[Definition]] = { - P( processorRef | sagaRef | inputRef | outputRef | groupRef ) + def arbitraryInteractionRef[u: P]: P[Reference[Definition]] = { + P(processorRef | sagaRef | inputRef | outputRef | groupRef) } - def anyInteractionRef[u: P]: P[Reference[Definition]] = { arbitraryInteractionRef | userRef } diff --git a/testkit/src/test/input/issues/447.riddl b/testkit/src/test/input/issues/447.riddl new file mode 100644 index 000000000..debe8314c --- /dev/null +++ b/testkit/src/test/input/issues/447.riddl @@ -0,0 +1,21 @@ +domain example is { + context TenantControl { + command CreateTenant { name: String } + event TenantCreated { name: String, result: String } + } + record Create { name: String } + user Admin is "fickle" + application App is { + page NewTenantPage { + input NameEntry acquires record example.Create + button Create acquires record example.Create + } + } + epic check_for_wrong_types_to_and_from_vitals { + case UserCreatesANewCompany { + user Admin wants to "create a new tenant" so that "the tenant can do stuff" + step from user Admin "presses" button App.NewTenantPage.Create, + step from button App.NewTenantPage.Create "sends" to context TenantControl + } + } +} diff --git a/testkit/src/test/scala/com/reactific/riddl/testkit/ReportedIssuesTest.scala b/testkit/src/test/scala/com/reactific/riddl/testkit/ReportedIssuesTest.scala index d4f39ab21..34faa43c7 100644 --- a/testkit/src/test/scala/com/reactific/riddl/testkit/ReportedIssuesTest.scala +++ b/testkit/src/test/scala/com/reactific/riddl/testkit/ReportedIssuesTest.scala @@ -96,5 +96,13 @@ class ReportedIssuesTest extends ValidatingTest { succeed } } + "447" in { + checkOne("447.riddl") { + case Left(messages) => + fail(messages.format) + case Right(result) => + succeed + } + } } }