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.
try_ty | ::= | Ptry identifier [p_formals] [p_actuals] ; |
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.
The in-memory representation of a Ptry is the same as the representation of underlying type.
The mask of a Ptry is the same as the mask of the underlying type.
The parse descriptor for a Ptry is the same as the parse descriptor for the underlying type.
The operations generated by the Pads compiler for a Ptry are those described in Chapter 3.
The error codes for Ptry are the same as for the underlying type.
Accumulator functions for Ptry are just as the accumulator functions for the underlying type.
Histogram functions for Ptry are just as the histogram functions for the underlying type.
Clustering functions for Ptry are just as the clustering functions for the underlying type.