Use LALR error recovery for contextual help
mainThe parser leverages the LALR error token to provide help during error recovery. When an unexpected token is encountered, the parser pops the stack until it matches a rule containing the error token.
To implement this in the grammar, you can use the helpWith(sqllex, "KEYWORD") function within an error rule. This function:
- Halts parsing.
- Returns a non-zero error code.
- Extends the error message with help text that clients can use to display friendly messages.
Shorthand Syntax: You can use a special comment to automate the generation of these rules:
| BACKUP error // SHOW HELP: BACKUPThis is automatically expanded by replace_help_rules.awk into the full helpWith return statement.
backup_stmt:
BACKUP targets TO string_or_placeholder opt_as_of_clause opt_incremental opt_with_options
{
$$.val = &Backup{...}
}
| BACKUP error { return helpWith(sqllex, `BACKUP`) }