Previous Up Next

Chapter 12  Ptry

Ptrys provide the ability to do arbitrary look-ahead. It checkpoints the data source, then parses the data at the current position using the underlying type of the Ptry. It sets the in-memory representation and parse descriptor for the Ptry as indicated by the parse, and then rolls back the data source to the check point.

12.1  Syntax

try_ty ::= Ptry identifier [p_formals] [p_actuals] ;

12.1.1  Example

The following code fragment defines the Ptry type ForwardInt.

Ptry ForwardInt Puint8_FW(:1:);

Punion VarInt(:Puint8 i:){
  
Pswitch(i>5) {
    
Pcase 0: Puint32 smallInt;
    
Pcase 1: Puint64 largeInt;
  }
};

Pstruct entry_t{
  ForwardInt           firstDigit;
  VarInt(:firstDigit:) fullNumber;
};

The type entry_t uses ForwardInt to parse the first digit of an integer. The Punion VarInt switches on whether this first digit is greater than 5 to determine if the integer should be parsed as a 32- or 64-bit integer.

12.2  Generated library

12.2.1  In-memory representation

The in-memory representation of a Ptry is the same as the representation of underlying type.

12.2.2  Mask

The mask of a Ptry is the same as the mask of the underlying type.

12.2.3  Parse descriptor

The parse descriptor for a Ptry is the same as the parse descriptor for the underlying type.

12.2.4  Operations

The operations generated by the Pads compiler for a Ptry are those described in Chapter 3.

Read function

The error codes for Ptry are the same as for the underlying type.

Accumulator functions

Accumulator functions for Ptry are just as the accumulator functions for the underlying type.

Histogram functions

Histogram functions for Ptry are just as the histogram functions for the underlying type.

Clustering functions

Clustering functions for Ptry are just as the clustering functions for the underlying type.


Previous Up Next