cockroach: Index | Files

package lex

import ""


Package Files

encode.go experimental_keywords.go normalize.go predicates.go


var AllowedExperimental = map[string]struct{}{
    "ranges": {},

AllowedExperimental contains keywords for which the EXPERIMENTAL_ or TESTING_ prefixes are allowed to be parsed along with the keyword to the same token. This ambiguity exists during the deprecation period of an EXPERIMENTAL_ keyword as it is being transitioned to the normal version. Once the transition is done, the keyword should be removed from here as well.

func DecodeRawBytesToByteArray Uses

func DecodeRawBytesToByteArray(data string, be BytesEncodeFormat) ([]byte, error)

DecodeRawBytesToByteArray converts raw bytes to a SQL-level byte array according to the encoding specification in "be". When using the Hex format, the caller is responsible for skipping the "\x" prefix, if any. See DecodeRawBytesToByteArrayAuto() below for an alternative.

func DecodeRawBytesToByteArrayAuto Uses

func DecodeRawBytesToByteArrayAuto(data []byte) ([]byte, error)

DecodeRawBytesToByteArrayAuto detects which format to use with DecodeRawBytesToByteArray(). It only supports hex ("\x" prefix) and escape.

func EncodeByteArrayToRawBytes Uses

func EncodeByteArrayToRawBytes(data string, be BytesEncodeFormat, skipHexPrefix bool) string

EncodeByteArrayToRawBytes converts a SQL-level byte array into raw bytes according to the encoding specification in "be". If the skipHexPrefix argument is set, the hexadecimal encoding does not prefix the output with "\x". This is suitable e.g. for the encode() built-in.

func EncodeEscapedSQLIdent Uses

func EncodeEscapedSQLIdent(buf *bytes.Buffer, s string)

EncodeEscapedSQLIdent writes the identifier in s to buf. The identifier is always quoted. Double quotes inside the identifier are escaped.

func EncodeLocaleName Uses

func EncodeLocaleName(buf *bytes.Buffer, s string)

EncodeLocaleName writes the locale identifier in s to buf. Any dash characters are mapped to underscore characters. Underscore characters do not need to be quoted, and they are considered equivalent to dash characters by the CLDR standard:

func EncodeRestrictedSQLIdent Uses

func EncodeRestrictedSQLIdent(buf *bytes.Buffer, s string, flags EncodeFlags)

EncodeRestrictedSQLIdent writes the identifier in s to buf. The identifier is quoted if either the flags ask for it, the identifier contains special characters, or the identifier is a reserved SQL keyword.

func EncodeSQLBytes Uses

func EncodeSQLBytes(buf *bytes.Buffer, in string)

EncodeSQLBytes encodes the SQL byte array in 'in' to buf, to a format suitable for re-scanning. We don't use a straightforward hex encoding here with x'...' because the result would be less compact. We are trading a little more time during the encoding to have a little less bytes on the wire.

func EncodeSQLString Uses

func EncodeSQLString(buf *bytes.Buffer, in string)

EncodeSQLString writes a string literal to buf. All unicode and non-printable characters are escaped.

func EncodeSQLStringWithFlags Uses

func EncodeSQLStringWithFlags(buf *bytes.Buffer, in string, flags EncodeFlags)

EncodeSQLStringWithFlags writes a string literal to buf. All unicode and non-printable characters are escaped. flags controls the output format: if encodeBareString is set, the output string will not be wrapped in quotes if the strings contains no special characters.

func EncodeUnrestrictedSQLIdent Uses

func EncodeUnrestrictedSQLIdent(buf *bytes.Buffer, s string, flags EncodeFlags)

EncodeUnrestrictedSQLIdent writes the identifier in s to buf. The identifier is only quoted if the flags don't tell otherwise and the identifier contains special characters.

func EscapeSQLString Uses

func EscapeSQLString(in string) string

EscapeSQLString returns an escaped SQL representation of the given string. This is suitable for safely producing a SQL string valid for input to the parser.

func IsDigit Uses

func IsDigit(ch int) bool

IsDigit returns true if the character is between 0 and 9.

func IsHexDigit Uses

func IsHexDigit(ch int) bool

IsHexDigit returns true if the character is a valid hexadecimal digit.

func IsIdentMiddle Uses

func IsIdentMiddle(ch int) bool

IsIdentMiddle returns true if the character is valid inside an identifier.

func IsIdentStart Uses

func IsIdentStart(ch int) bool

IsIdentStart returns true if the character is valid at the start of an identifier.

func NormalizeName Uses

func NormalizeName(n string) string

NormalizeName normalizes to lowercase and Unicode Normalization Form C (NFC).

type BytesEncodeFormat Uses

type BytesEncodeFormat int

BytesEncodeFormat controls which format to use for BYTES->STRING conversions.

const (
    // BytesEncodeHex uses the hex format: e'abc\n'::BYTES::STRING -> '\x61626312'.
    // This is the default, for compatibility with PostgreSQL.
    BytesEncodeHex BytesEncodeFormat = iota
    // BytesEncodeEscape uses the escaped format: e'abc\n'::BYTES::STRING -> 'abc\012'.
    // BytesEncodeBase64 uses base64 encoding.

func BytesEncodeFormatFromString Uses

func BytesEncodeFormatFromString(val string) (_ BytesEncodeFormat, ok bool)

BytesEncodeFormatFromString converts a string into a BytesEncodeFormat.

func (BytesEncodeFormat) String Uses

func (f BytesEncodeFormat) String() string

type EncodeFlags Uses

type EncodeFlags int

EncodeFlags influence the formatting of strings and identifiers.

const (
    // EncNoFlags indicates nothing special should happen while encoding.
    EncNoFlags EncodeFlags = 0

    // EncBareStrings indicates that strings will be rendered without
    // wrapping quotes if they contain no special characters.
    EncBareStrings EncodeFlags = 1 << iota

    // EncBareIdentifiers indicates that identifiers will be rendered
    // without wrapping quotes.

    // EncFirstFreeFlagBit needs to remain unused; it is used as base
    // bit offset for tree.FmtFlags.

func (EncodeFlags) HasFlags Uses

func (f EncodeFlags) HasFlags(subset EncodeFlags) bool

HasFlags tests whether the given flags are set.

Package lex imports 12 packages (graph) and is imported by 78 packages. Updated 2020-08-13. Refresh now. Tools for package owners.