MCPcopy Create free account
hub / github.com/dolthub/doltgresql / SetHelp

Method SetHelp

postgres/parser/parser/lexer.go:263–277  ·  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

261// lastError field, which was set earlier to contain details about the
262// syntax error.
263func (l *lexer) SetHelp(msg HelpMessage) {
264 if l.lastError == nil {
265 l.lastError = pgerror.WithCandidateCode(errors.New("help request"), pgcode.Syntax)
266 }
267
268 if lastTok := l.lastToken(); lastTok.id == HELPTOKEN {
269 l.populateHelpMsg(msg.String())
270 } else {
271 if msg.Command != "" {
272 l.lastError = errors.WithHintf(l.lastError, `try \h %s`, msg.Command)
273 } else {
274 l.lastError = errors.WithHintf(l.lastError, `try \hf %s`, msg.Function)
275 }
276 }
277}
278
279func (l *lexer) populateHelpMsg(msg string) {
280 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