Mike wrote:

  *   Your second assert should be a discriminator.

Mike, you are saying that instead of this:

<xs:element name='D' type="unsignedint4">
    <xs:annotation>
        <xs:appinfo source=http://www.ogf.org/dfdl/>
            <dfdl:assert>{(. eq 9) or (. eq 10)}</dfdl:assert>
        </xs:appinfo>
    </xs:annotation>
</xs:element>

I should use this:

<xs:element name='D' type="unsignedint4">
    <xs:annotation>
        <xs:appinfo source=http://www.ogf.org/dfdl/>
            <dfdl:discriminator test="{(. eq 9) or (. eq 10)}" />
        </xs:appinfo>
    </xs:annotation>
</xs:element>

Would you explain the difference between those two, please?

Would you provide an example of where the former would behave incorrectly 
whereas the latter would behave correctly, please?

/Roger


From: Mike Beckerle <mbecke...@apache.org>
Sent: Thursday, June 13, 2024 2:30 PM
To: users@daffodil.apache.org
Subject: [EXT] Re: Warning: Counterintuitive placement detected

Minor suggestion. Your second assert should be a discriminator. This would be a 
more precise expression of exactly the criteria for choosing this sequence as 
the data format. DFDL can use that to improve diagnostic behavior if both 
"assertions"
ZjQcmQRYFpfptBannerStart
Minor suggestion.

Your second assert should be a discriminator.

This would be a more precise expression of exactly the criteria for choosing 
this sequence as the data format.

DFDL can use that to improve diagnostic behavior if both "assertions" hold, but 
something is wrong with the data for elements B, C, and D.

There is even a small possibility of an incorrect false-positive parse 
happening that the discriminator rules out.


On Thu, Jun 13, 2024 at 7:52 AM Roger L Costello 
<coste...@mitre.org<mailto:coste...@mitre.org>> wrote:
I found a solution that seems to work. See below. Any suggestions for improving 
it is welcome.

<xs:element name="test">
    <xs:complexType>
        <xs:sequence>
            <!--
                The decimal value of the first bit of the input should be
                wrapped in an <A> tag if the decimal value of the next 4 bits
                equals 7 and the decimal value of the 4 bits after that equals 
9,
                or the decimal value of the next 4 bits equals 7 and the decimal
                value of the 4 bits after that equals 10, otherwise the first 
bit
                of the input should be wrapped in a <B> tag.

                The below is not looking ahead. Assume the input is ACD. If C 
is not
                equal to 7 and D is not equal to 9 or 10, then we realize that
                we made an error, back up, and try the next branch of the 
choice.
            -->
            <xs:choice>
                <xs:sequence>
                    <xs:element name='A' type="unsignedint1"/>
                    <xs:element name='C' type="unsignedint4">
                        <xs:annotation>
                            <xs:appinfo source="http://www.ogf.org/dfdl/";>
                                <dfdl:assert>{. eq 7}</dfdl:assert>
                            </xs:appinfo>
                        </xs:annotation>
                    </xs:element>
                    <xs:element name='D' type="unsignedint4">
                        <xs:annotation>
                            <xs:appinfo source="http://www.ogf.org/dfdl/";>
                                <dfdl:assert>{(. eq 9) or (. eq 
10)}</dfdl:assert>
                            </xs:appinfo>
                        </xs:annotation>
                    </xs:element>
                </xs:sequence>
                <xs:sequence>
                    <xs:element name='B' type="unsignedint1"/>
                    <xs:element name='C' type="unsignedint4"/>
                    <xs:element name='D' type="unsignedint4"/>
                </xs:sequence>
            </xs:choice>
        </xs:sequence>
    </xs:complexType>
</xs:element>

-----Original Message-----
From: Roger L Costello <coste...@mitre.org<mailto:coste...@mitre.org>>
Sent: Thursday, June 13, 2024 7:10 AM
To: users@daffodil.apache.org<mailto:users@daffodil.apache.org>
Subject: Warning: Counterintuitive placement detected

Hi Folks,

I need my DFDL to look-ahead:

The decimal value of the first bit of the input should be wrapped in an <A> tag 
if the decimal value of the next 4 bits equals 7 and the decimal value of the 4 
bits after that equals 9, or the decimal value of the next 4 bits equals 7 and 
the decimal value of the 4 bits after that equals 10, otherwise the first bit 
of the input should be wrapped in a <B> tag.

Below is my attempt at implementing this. Daffodil gives this warning message:

Schema Definition Warning: Counterintuitive placement detected. Wrap the 
discriminator or assert in an empty sequence to evaluate before the contents. 
(id: discouragedDiscriminatorPlacement)

Here is my DFDL:

<xs:element name="test">
    <xs:complexType>
        <xs:sequence>
            <xs:choice>
                <xs:sequence>
                    <xs:annotation>
                        <xs:appinfo source="http://www.ogf.org/dfdl/";>
                            <dfdl:discriminator testKind="pattern" 
testPattern="(.x7x9)|(.x7xA)" />
                        </xs:appinfo>
                    </xs:annotation>
                    <xs:element name='A' type="unsignedint1"/>
                </xs:sequence>
                <xs:sequence>
                    <xs:element name='B' type="unsignedint1"/>
                </xs:sequence>
            </xs:choice>
            <xs:element name='C' type="unsignedint4"/>
            <xs:element name='D' type="unsignedint4"/>
        </xs:sequence>
    </xs:complexType>
</xs:element>

Reply via email to