lex

package
v0.7.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 14, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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.

Functions

func DecodeRawBytesToByteArray

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

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

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

func EncodeByteArrayToRawBytes

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

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

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: http://cldr.unicode.org/.

func EncodeRestrictedSQLIdent

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

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

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

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

func EncodeSQLStringWithFlags

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

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

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

func IsDigit(ch int) bool

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

func IsHexDigit

func IsHexDigit(ch int) bool

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

func IsIdentMiddle

func IsIdentMiddle(ch int) bool

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

func IsIdentStart

func IsIdentStart(ch int) bool

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

func NormalizeName

func NormalizeName(n string) string

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

Types

type BytesEncodeFormat

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'.
	BytesEncodeEscape
	// BytesEncodeBase64 uses base64 encoding.
	BytesEncodeBase64
)

func BytesEncodeFormatFromString

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

BytesEncodeFormatFromString converts a string into a BytesEncodeFormat.

func (BytesEncodeFormat) String

func (f BytesEncodeFormat) String() string

type EncodeFlags

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.
	EncBareIdentifiers

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

func (EncodeFlags) HasFlags

func (f EncodeFlags) HasFlags(subset EncodeFlags) bool

HasFlags tests whether the given flags are set.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL