I started working on the gold parser and tried to adopt its syntax to c#. This is a fragment code. I'm interested in what this particular part does, and if I can see which of the characters in the text which i entered with textbox is wrong with my grammar?
private void TokenErrorEvent(LALRParser parser, TokenErrorEventArgs args)
{
string message = "Token error with input: '"+args.Token.ToString()+"'";
}
private void ParseErrorEvent(LALRParser parser, ParseErrorEventArgs args)
{
string message = "Parse error caused by token: '"+args.UnexpectedToken.ToString()+"'";
}
Gold parser uses events to communicate with the host application. You posted handlers for two of them, which are:
ContinueMode
: supply a replacement token, ignore, or stop.According to documentation, source location information is available with these properties:
args.UnexpectedToken.Location.LineNr
and
args.UnexpectedToken.Location.ColumnNr
They are both zero-based, so if you split your source into an array of lines, you can directly use LineNr
as index, and then the SubString
function to point to the first character of the unexpected token literal.