how do i reject a zero length string - or alternatively how do i terminate parsing an element from a script?

0 votes
asked May 24, 2023 in Grammars by jportway (130 points)
Hi,

I am trying to write a grammar for EXR files. These have a header with a list of attributes. each attribute consists of an attribute name (string), type (another string), size (int) and then some data (dependent on the size). There are various predefined attribute types that I can write grammars to parse, and can fall back to a base-case undefined attribute for any unknown attribute types. This seems to be mostly working.

The problem is that this list of attributes is null terminated. So I need to know when there is a zero at the start of the next structure, and then move on to parsing the next bit of the file. Since the grammar is trying to parse another attribute, this shows up as a zero length attribute name (attribute names are zero-terminated). As far as I can tell there is no way to reject a zero-length string. And no direct way to detect the null terminator. I have written a script that detects the zero-length string, but then I don't know how to control the parser to tell it to move on. Any ideas?

thanks

1 Answer

+1 vote
answered May 25, 2023 by andreas (3,500 points)

This is probably best made with a scripting element - see some examples here: https://www.synalysis.net/scripting/

Let it read the byte at the current position with byteView.readByte(), then map the structure that selects one of the attributes.

If you need further assistance please send me an email to andreas@synalysis.com.

commented May 25, 2023 by jportway (130 points)
Thanks - I"ll have a look when I get time, although to be honest I had to move on and I ended up just writing code from scratch to do the job, so I'm not sure when I will get back to this.

It would have been very handy to just have a check box for strings that rejects zero-length strings (like "must match", but "must not be empty").This seems like it would be a generally useful feature to have.
...