You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@daffodil.apache.org by "Steinberger, Rick" <rs...@tresys.com> on 2020/08/26 17:38:29 UTC

How do I detect the position of a schema element during parse

I'm new to Daffodil, and trying to learn my way around the code.
I have picked up Daffodil-2277 Warning needed for misplaced discriminators.

Can you give me a hook into the code where schema elements are evaluated so that I can learn how to detect the position of specific elements in the schema like dfdl:discriminator.

I have evaluated multipleDiscriminators.tdml and stepped through the parse using the debugger. https://daffodil.apache.org/debugger/

Any pointers would be appreciated.



Re: How do I detect the position of a schema element during parse

Posted by Steve Lawrence <sl...@apache.org>.
The idea for DAFFODIL-2277 is that we want to create a warning if there
is a discriminator on a sequence AND that sequence is non-empty. This is
because a discriminator on a non-empty sequence is evaluated AFTER the
contents are parsed, which is often unintuitive since the discriminator
appears BEFORE the contents in the DFDL schema. For empty sequences with
a discriminator, there's no confusion about when the discriminator is
evaluated so we don't need a warning in that case.

Also note that the same goes for asserts as well (asserts are
essentially the same as discriminators, except a true discriminator
affects how Daffodil backtracks while a true assert does not).

So this is a schema compile time check, which means the logic goes
somewhere in the daffodil-core subproject. Inside this subproject,
Daffodil has what we call dsom (DFDL Schema Object Model), which is
essentially a representation of a DFDL schema in Scala classes with
various members to access information about those schema objects (such
as children of a model group/sequence, or if a object has
discriminators/assert).

The DSOM base class for sequences is SequenceGroupTermBase in

  daffodil-core/src/main/scala/org/apache/daffodil/dsom/SequenceGroup.scala

The DSOM mixin that has variables such as discriminatorStatments and
assertStatments, etc. that can be used to determine if such annotations
exist is ProvidesDFDLStatementMixin in


daffodil-core/src/main/scala/org/apache/daffodil/dsom/DFDLStatementMixin.scala

Through various traits, SequenceGroupTermBase mixes in
ProvidesDFDLStatementMixin, for reference

  SequenceGroupTermBase mixes in
  SequenceDefMixin which mixes in
  GroupDefLike which mixes in
  ProvidesDFDLStatementMixin

Thus, the SequenceGroupTermBase has access to the
discriminatorStatements and assertStatements variables.

Additionally, the ModelGroup class provides variables about model groups
(sequences are an example of a model group), including the groupMembers
variable, which provides access to the children of the model group.

Through various traits, SequenceGroupTermBase also mixes in ModelGroup,
for refrence,

  SequenceGroupTermBase mixes in
  SequenceTermBase which mixes in
  ModelGroup

So the SequenceGroupTermBase DSOM object has information about both the
members of a sequence (via groupMembers variable) and the
discriminators/asserts (via discriminatorStatements and assertStatements
variables). So we just need to add a check to produce a warning if the
length of groupMembers is > 0 and either the length of the
discriminatorStatements or assertStatements are also > 0.

Note that this class already has various checks (e.g.
checkIfValidUnorderedSequence). You'll probably want to create something
similar (e.g. checkIfNonEmptyAndDiscrimsOrAsserts), and that lazy val
can create a SDW rather than an SDE if the check fails.


Note that that although this is specific to this issue, the idea is the
same throughout Daffodil. DSOM is just a bunch of classes that mixin
traits to provide helpful member variables to easily inspect the DFDL
schema. Understanding that DSOM hierarchy can take some time since it's
pretty large but ultimately it's just a bunch of the same thing.

- Steve


On 8/25/20 2:59 PM, Steinberger, Rick wrote:
> https://issues.apache.org/jira/browse/DAFFODIL-2277
>
> Warning needed for misplaced discriminators
>
> Hey guys,
>
> Any pointers on where to look in the code to address this would be
much appreciated.
>
> Thanks,
>
> Rick
>



On 8/26/20 1:38 PM, Steinberger, Rick wrote:
> I'm new to Daffodil, and trying to learn my way around the code.
> I have picked up Daffodil-2277 Warning needed for misplaced discriminators.
> 
> Can you give me a hook into the code where schema elements are evaluated so that I can learn how to detect the position of specific elements in the schema like dfdl:discriminator.
> 
> I have evaluated multipleDiscriminators.tdml and stepped through the parse using the debugger. https://daffodil.apache.org/debugger/
> 
> Any pointers would be appreciated.
> 
> 
>