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

Reorder DFDL statement processing to match spec #1369

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ trait ProvidesDFDLStatementMixin extends ThrowsSDE with HasTermCheck {

final lazy val patternStatements: Seq[DFDLStatement] = patternAsserts ++ patternDiscrims

final lazy val lowPriorityStatements: Seq[DFDLStatement] =
setVariableStatements ++ nonPatternAsserts ++ nonPatternDiscrims
final lazy val nonPatternStatements: Seq[DFDLStatement] =
nonPatternAsserts ++ nonPatternDiscrims

final protected lazy val localStatements = this.annotationObjs.collect {
case st: DFDLStatement => st
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,18 @@ trait HasStatementsGrammarMixin extends GrammarMixin { self: Term =>

// Includes setVariable as well as assert/discriminator statements that
// are not testKind="pattern"
private lazy val lowPriorityStatementGrams = lowPriorityStatements.map { _.gram(self) }
private lazy val setVariableGrams = setVariableStatements.map { _.gram(self) }

final lazy val dfdlLowPriorityStatementEvaluations =
prod("dfdlStatementEvaluations", lowPriorityStatementGrams.length > 0) {
lowPriorityStatementGrams.fold(mt) { _ ~ _ }
final lazy val setVariableEvaluations =
prod("setVariableEvaluations", setVariableGrams.length > 0) {
setVariableGrams.fold(mt) { _ ~ _ }
}

private lazy val nonPatternGrams = nonPatternStatements.map { _.gram(self) }

final lazy val nonPatternEvaluations =
prod("dfdlStatementEvaluations", nonPatternGrams.length > 0) {
nonPatternGrams.fold(mt) { _ ~ _ }
}

// assert/discriminator statements with testKind="pattern"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ trait ModelGroupGrammarMixin
// See 9.5 Evaluation Order for Statement Annotations
dfdlPatternStatementEvaluations ~ // Assert and Discriminator statements with testKind="pattern"
dfdlScopeBegin ~ // newVariableInstance
dfdlLowPriorityStatementEvaluations ~ // setVariable and the rest of the Assert and Discriminator statements
groupLeftFraming ~ groupContentWithInitiatorTerminator ~ groupRightFraming ~ dfdlScopeEnd
setVariableEvaluations ~
groupLeftFraming ~ groupContentWithInitiatorTerminator ~ nonPatternEvaluations ~ groupRightFraming ~ dfdlScopeEnd
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think more is needed than this repositioning of the evaluation order.

The enclosing term combinator (for an element or a model group) may need to get the nonPatternEvaluations separately from the rest of the sequence of things to do. In fact, it might be necessary to isolate the nonPatternDiscriminatorEvaluations from the regular non-pattern asserts, as they get slightly different treatment.

So rather than this big long ~ separated sequence, you'll need the combinator to be passed this sequence up to, but not including the nonPatternDiscriminatorEvaluations, then pass the nonPatternDiscriminatorEvaluations, and then everything after those. The combinator then orchestrates evaluating the "body", then the nonPatternDiscriminatorEvaluations, that may set the discriminator true on the stack, and if so that changes the way the "body" failure will be handled.

This whole thing is kind of a trick to make it possible for discriminator/assert statements to look downward into the complexType/group on which they are expressed, instead of having to refer only backward to prior already parsed fields.

}

private lazy val groupContentWithInitiatorTerminator =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class TestDiscriminators {
@Test def test_discrimExpression_03() = { runner.runOneTest("discrimExpression_03") }

// DAFFODIL-1971
// @Test def test_discrimExpression_04() = { runner.runOneTest("discrimExpression_04") }
@Test def test_discrimExpression_04() = { runner.runOneTest("discrimExpression_04") }

@Test def test_discrimFailStopsFollowingAssert1(): Unit = {
runner.runOneTest("discrimFailStopsFollowingAssert1")
Expand Down
Loading