Skip to content

Commit

Permalink
Require ??? in otherwise empty application definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
reid-spencer committed Nov 18, 2023
1 parent e1315a8 commit 57417b7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,14 @@ private[parsing] trait ApplicationParser {
}
}

private def groupDefinitions[u: P]: P[Seq[GroupDefinition]] =
P(
undefined(Seq.empty[GroupDefinition]) |
(group | containedGroup | appOutput | appInput).rep(0)
)
private def groupDefinitions[u: P]: P[Seq[GroupDefinition]] = {
P(group | containedGroup | appOutput | appInput).rep(1)
}

private def group[u: P]: P[Group] = {
P(
location ~ groupAliases ~ identifier ~/ is ~ open ~
groupDefinitions ~
(undefined(Seq.empty[GroupDefinition]) | groupDefinitions) ~
close ~ briefly ~ description
).map { case (loc, alias, id, elements, brief, description) =>
Group(loc, alias, id, elements, brief, description)
Expand All @@ -62,7 +60,9 @@ private[parsing] trait ApplicationParser {

private def outputDefinitions[u: P]: P[Seq[OutputDefinition]] = {
P(
is ~ open ~ appOutput.rep(1) ~ close
is ~ open ~
(undefined(Seq.empty[OutputDefinition]) | appOutput.rep(1)) ~
close
).?.map {
case Some(definitions) => definitions
case None => Seq.empty[OutputDefinition]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,24 @@ import org.scalatest.matchers.must.Matchers
class ApplicationParsingTest extends ParsingTest with Matchers {

"Application Components" must {
"empty definitions should fail" in {
"nested empty definitions should fail" in {
val input =
"""
|domain foo {
|application foo2 {
| group {}
| group g1 is { ??? }
| group g2 is {
| group g3 is { ??? }
| input i1 acquires String is { ??? }
| output o1 displays String is { ??? }
| }
|}
|}""".stripMargin
parseDefinition[Domain](input) match {
case Left(messages: Messages) =>
val errors = messages.justErrors
errors.size mustBe 1
val msg = errors.head
msg.message contains "Expected one of"
msg.message contains "???"
msg.loc.line mustBe 4

fail(messages.format)
case Right((dom: Domain, _)) =>
fail("should have required ??? syntax")
succeed
}
}
}
Expand Down

0 comments on commit 57417b7

Please sign in to comment.