Class X
ReadOnly Property A
Get
Return Nothing
End Get
End Property
End Class
This topic explains the synchronizer pair error handling strategy.
The following topics are prerequisites to understanding this topic:
This topic contains the following sections:
The synchronizer pair strategy is similar to the synchronizer symbol strategy, although instead of using a single symbol to synchronize the parser to the token stream, it uses a pair of symbols. It is used whenever the presence of one symbol followed by another unambiguously determines the next position in a production being constructed. A good example of this is in Visual Basic. Most block structures in Visual Basic end with "End <X>" where <X> is the structure being ended. For example, consider this simple Visual Basic program:
In Visual Basic:
Class X
ReadOnly Property A
Get
Return Nothing
End Get
End Property
End Class
There are a bunch of ended blocks here and they are ended with "End Get", "End Property", and "End Class". If one of those is omitted by accident, the parser should be able to figure out what structures are being ended by the other endings. So let’s say the user forgot to type "End Get" or just hasn’t gotten to it yet:
In Visual Basic:
Class X
ReadOnly Property A
Get
Return Nothing
End Property
End Class
If the synchronizer symbol error handling strategy were to handle this error, it would detect an error at the keyword "Property" on line 5. At this point, it would report two errors:
"Get" expected
"End" expected
The first error indicates the user forgot to type "Get" after the "End" keyword to close the get accessor. The second error indicates that "End" is missing in the "End Property" that was expected (because the actual "End" keyword was used to close the get accessor). Intuitively, it is obvious that this is not ideal. "End Property" should really be treated as a logical unit.
This is where the synchronizer pair error handling strategy can be used. To enable this strategy, the Symbol.IsStartOfErrorRecoveryPair property should be set to True on the terminal symbol representing the "End" keyword. Now if an error occurs and the last created node for the syntax tree is associated with the "End" keyword, the parser will see if any productions being constructed at the time of the error were expecting "End" followed by "Property". The production representing a property declaration would indicate that is was, so the get accessor will be completed automatically by filling in the missing "End Get" structure and a single error message can be reported which says ‘"End Get" expected’.
The following topics provide additional information related to this topic.