Synalize It only recognizes first instance of element in custom grammar?

0 votes
asked Nov 26, 2019 in Grammars by patrickl (140 points)

Hi, I'm trying to use Synalize It to help me design a file format for a college project, but have the issue that it only recognizes the first instance of the data, and concludes the rest of the file is just padding. I have repeat settings set correctly (I think), but can't figure out the cause of the problem! Any help or suggestions are appreciated, Thanks!

Here's the contents of the grammar file:
"<?xml version="1.0" encoding="UTF-8"?>
<ufwb version="1.17">
   <grammar name="SmartShelf Metadata" start="id:197" author="Patrick L">
       <description>Grammar for the Mech 90 SmartShelf Metadata</description>
       <structure name="BinContainer" id="213" encoding="ISO_8859-1:1987" endian="big" signed="no" order="variable">
           <structure name="Bin" id="197" length="64" alignment="1" repeatmax="-1" encoding="ISO_8859-1:1987" endian="big" signed="no">
               <binary name="Magic_Number" mustmatch="yes" id="198" strokecolor="FF0000" length="1">
                   <fixedvalues>
                       <fixedvalue name="Magic Number" value="B1"/>
                   </fixedvalues>
               </binary>
               <number name="Bin_ID" id="199" fillcolor="0000FF" type="integer" length="1"/>
               <number name="Offset_Steps" id="200" strokecolor="0000FF" type="integer" length="1"/>
               <number name="Steps_From_Home" id="201" strokecolor="00F1FF" type="integer" length="2"/>
               <number name="Protocol_Version" id="202" type="integer" length="1">
                   <fixedvalues>
                       <fixedvalue name="V1" value="1"/>
                   </fixedvalues>
               </number>
               <number name="<reserved>" id="203" strokecolor="999999" repeatmin="4" repeatmax="4" type="integer" length="1"/>
               <string name="Bin_Name" id="204" fillcolor="21D2C4" type="fixed-length" length="20"/>
               <string name="Bin_Description" id="205" fillcolor="A2FFFF" type="fixed-length" length="30"/>
               <binary name="Padding" mustmatch="yes" id="206" repeatmin="0" repeatmax="-1" length="1">
                   <fixedvalues>
                       <fixedvalue name="Padding" value="77"/>
                   </fixedvalues>
               </binary>
           </structure>
           <structure name="ExtendedBinData" id="208" length="64" disabled="yes" alignment="0" repeatmax="-1" encoding="ISO_8859-1:1987" endian="big" signed="no">
               <binary name="Magic_Number" id="209" length="remaining">
                   <fixedvalues>
                       <fixedvalue name="Magic_Number" value="B3"/>
                   </fixedvalues>
               </binary>
               <number name="Bin_ID" id="210" type="integer" length="1"/>
               <number name="<reserved>" id="211" repeatmax="-1" type="integer" length="1"/>
           </structure>
       </structure>
   </grammar>
</ufwb>
",
and here's enough my test file, consisting of two identical "Bin" Elements, and padded with 0xFFs:
"B1012000200100000000534D4420636F6D706F6E656E74732E000000000053757266616365204D6F756E74205265736973746F72732C20657463000077777777B1012000200100000000534D4420636F6D706F6E656E74732E000000000053757266616365204D6F756E74205265736973746F72732C20657463000077777777FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"

1 Answer

0 votes
answered Feb 28, 2020 by murphyschaos (210 points)

I know you're probably well-past the due date for your project, but I gave an answer in case somebody else had a similar question.

A couple of things:

The grammar tag shows start="id:197", which is the ID of the Bin structure. You want this to point at the BinContainer. Replace the preceding with start="id:213".

Your Padding piece has repeatmax="-1". I believe only structures support unlimited repeating. There are several things you could do here. Each of these has its own pros and cons:

  • Change repeatmax. Either match the Bin structure (set max to 64) or set it at a very large value (e.g. 65535, the decimal version of 0xFFFF).
  • Change length. Set repeatmax="1"length="remaining", and uncheck Must match (or remove the fixed value). This will repeat to the end of the size of Bin (64).
  • Embed the binary value inside a structure and set repeatmax="64". If you choose this method, you can leave your Must match with the 77 value.
  • Remove Padding. The parser will automatically skip to the end of the 64 bytes used by Bin.
...