MCPcopy Create free account
hub / github.com/auxten/postgresql-parser / SetHelp

Method SetHelp

pkg/sql/parser/lexer.go:239–253  ·  view source on GitHub ↗

SetHelp marks the "last error" field in the lexer to become a help text. This method is invoked in the error action of the parser, so the help text is only produced if the last token encountered was HELPTOKEN -- other cases are just syntax errors, and in that case we do not want the help text to ove

(msg HelpMessage)

Source from the content-addressed store, hash-verified

237// lastError field, which was set earlier to contain details about the
238// syntax error.
239func (l *lexer) SetHelp(msg HelpMessage) {
240 if l.lastError == nil {
241 l.lastError = pgerror.WithCandidateCode(errors.New("help request"), pgcode.Syntax)
242 }
243
244 if lastTok := l.lastToken(); lastTok.id == HELPTOKEN {
245 l.populateHelpMsg(msg.String())
246 } else {
247 if msg.Command != "" {
248 l.lastError = errors.WithHintf(l.lastError, `try \h %s`, msg.Command)
249 } else {
250 l.lastError = errors.WithHintf(l.lastError, `try \hf %s`, msg.Function)
251 }
252 }
253}
254
255func (l *lexer) populateHelpMsg(msg string) {
256 l.lastError = errors.WithHint(errors.Wrap(l.lastError, "help token in input"), msg)

Callers 2

helpWithFunction · 0.80
helpWithFunctionFunction · 0.80

Calls 4

lastTokenMethod · 0.95
populateHelpMsgMethod · 0.95
WithCandidateCodeFunction · 0.92
StringMethod · 0.65

Tested by

no test coverage detected