cockroach: github.com/cockroachdb/cockroach/pkg/sql/parser Index | Files

package parser

import "github.com/cockroachdb/cockroach/pkg/sql/parser"

Index

Package Files

help.go parse.go scan.go

Variables

var AllHelp = func(h map[string]HelpMessageBody) string {

    cmds := make(map[string][]string)
    for c, details := range h {
        if details.Category == "" {
            continue
        }
        cmds[details.Category] = append(cmds[details.Category], c)
    }

    // Ensure the result is deterministic.
    var categories []string
    for c, l := range cmds {
        categories = append(categories, c)
        sort.Strings(l)
    }
    sort.Strings(categories)

    // Compile the final help index.
    var buf bytes.Buffer
    w := tabwriter.NewWriter(&buf, 0, 0, 1, ' ', 0)
    for _, cat := range categories {
        fmt.Fprintf(w, "%s:\n", strings.Title(cat))
        for _, item := range cmds[cat] {
            fmt.Fprintf(w, "\t\t%s\t%s\n", item, h[item].ShortDescription)
        }
        fmt.Fprintln(w)
    }
    _ = w.Flush()
    return buf.String()
}(helpMessages)

AllHelp contains an overview of all statements with help messages. For example, displayed in the CLI shell with \h without additional parameters.

var HelpMessages = func(h map[string]HelpMessageBody) map[string]HelpMessageBody {
    appendSeeAlso := func(newItem, prevItems string) string {

        if prevItems != "" {
            return newItem + "\n  " + prevItems
        }
        return newItem
    }
    reformatSeeAlso := func(seeAlso string) string {
        return strings.Replace(
            strings.Replace(seeAlso, ", ", "\n  ", -1),
            "WEBDOCS", base.DocsURLBase, -1)
    }
    srcMsg := h["<SOURCE>"]
    srcMsg.SeeAlso = reformatSeeAlso(strings.TrimSpace(srcMsg.SeeAlso))
    selectMsg := h["<SELECTCLAUSE>"]
    selectMsg.SeeAlso = reformatSeeAlso(strings.TrimSpace(selectMsg.SeeAlso))
    for k, m := range h {
        m = h[k]
        m.ShortDescription = strings.TrimSpace(m.ShortDescription)
        m.Text = strings.TrimSpace(m.Text)
        m.SeeAlso = strings.TrimSpace(m.SeeAlso)

        if strings.Contains(m.Text, "<source>") && k != "<SOURCE>" {
            m.Text = strings.TrimSpace(m.Text) + "\n\n" + strings.TrimSpace(srcMsg.Text)
            m.SeeAlso = appendSeeAlso(srcMsg.SeeAlso, m.SeeAlso)
        }

        if strings.Contains(m.Text, "<selectclause>") && k != "<SELECTCLAUSE>" {
            m.Text = strings.TrimSpace(m.Text) + "\n\n" + strings.TrimSpace(selectMsg.Text)
            m.SeeAlso = appendSeeAlso(selectMsg.SeeAlso, m.SeeAlso)
        }

        if strings.Contains(m.Text, "<tablename>") {
            m.SeeAlso = appendSeeAlso("SHOW TABLES", m.SeeAlso)
        }
        m.SeeAlso = reformatSeeAlso(m.SeeAlso)
        h[k] = m
    }
    return h
}(helpMessages)

HelpMessages is the registry of all help messages, keyed by the top-level statement that they document. The key is intended for use via the \h client-side command.

func Parse Uses

func Parse(sql string) (tree.StatementList, error)

Parse parses a sql statement string and returns a list of Statements.

func ParseExpr Uses

func ParseExpr(sql string) (tree.Expr, error)

ParseExpr is a short-hand for parseExprs([]string{sql})

func ParseExprs Uses

func ParseExprs(sql []string) (tree.Exprs, error)

ParseExprs is a short-hand for parseExprs(sql)

func ParseOne Uses

func ParseOne(sql string) (tree.Statement, error)

ParseOne parses a sql statement string, ensuring that it contains only a single statement, and returns that Statement.

func ParseStringAs Uses

func ParseStringAs(t types.T, s string, evalCtx *tree.EvalContext) (tree.Datum, error)

ParseStringAs parses s as type t.

func ParseTableNameWithIndex Uses

func ParseTableNameWithIndex(sql string) (tree.TableNameWithIndex, error)

ParseTableNameWithIndex parses a table name with index.

func ParseType Uses

func ParseType(sql string) (coltypes.CastTargetType, error)

ParseType parses a column type.

type HelpMessage Uses

type HelpMessage struct {
    // Command is set if the message is about a statement.
    Command string
    // Function is set if the message is about a built-in function.
    Function string

    // HelpMessageBody contains the details of the message.
    HelpMessageBody
}

HelpMessage describes a contextual help message.

func (*HelpMessage) Format Uses

func (h *HelpMessage) Format(w io.Writer)

Format prints out details about the message onto the specified output stream.

func (*HelpMessage) String Uses

func (h *HelpMessage) String() string

String implements the fmt.String interface.

type HelpMessageBody Uses

type HelpMessageBody struct {
    Category         string
    ShortDescription string
    Text             string
    SeeAlso          string
}

HelpMessageBody defines the body of a help text. The messages are structured to facilitate future help navigation functionality.

type Parser Uses

type Parser struct {
    // contains filtered or unexported fields
}

Parser wraps a scanner, parser and other utilities present in the parser package.

func (*Parser) Parse Uses

func (p *Parser) Parse(sql string) (stmts tree.StatementList, err error)

Parse parses the sql and returns a list of statements.

type Scanner Uses

type Scanner struct {
    // contains filtered or unexported fields
}

Scanner lexes SQL statements.

func MakeScanner Uses

func MakeScanner(str string) Scanner

MakeScanner makes a Scanner from str.

func (*Scanner) Error Uses

func (s *Scanner) Error(e string)

func (*Scanner) Lex Uses

func (s *Scanner) Lex(lval *sqlSymType) int

Lex lexes a token from input.

func (*Scanner) SetHelp Uses

func (s *Scanner) SetHelp(msg HelpMessage)

SetHelp marks the "last error" field in the Scanner 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 overwrite the lastError field, which was set earlier to contain details about the syntax error.

func (*Scanner) Tokens Uses

func (s *Scanner) Tokens(f func(token int))

Tokens calls f on all tokens of the input until an EOF is encountered.

func (*Scanner) Unimplemented Uses

func (s *Scanner) Unimplemented(feature string)

Unimplemented wraps Error, setting lastUnimplementedError.

func (*Scanner) UnimplementedWithIssue Uses

func (s *Scanner) UnimplementedWithIssue(issue int)

UnimplementedWithIssue wraps Error, setting lastUnimplementedError.

Package parser imports 18 packages (graph) and is imported by 27 packages. Updated 2017-11-19. Refresh now. Tools for package owners.