lex

package
v0.0.0-...-ef1f557 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2018 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package lex implements a simple lexical scanner for SQL statements.

This package was adapted from github.com/jjeffery/sqlr/private/scanner.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsQuoted

func IsQuoted(ident string) bool

IsQuoted returns true if the identifier is a quoted identifier.

func Quote

func Quote(ident, start, end string) string

Quote the identifer using the start and end quote strings. If the end quote string occurs in ident, it is escaped.

func Unquote

func Unquote(ident string) string

Unquote will unquote an identifier, if it is quoted. If the syntax of the identifier is not valid the result is undefined.

Types

type Scanner

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

Scanner is a simple lexical scanner for SQL statements.

func New

func New(r io.Reader) *Scanner

New returns a new scanner that takes its input from r.

func (*Scanner) Err

func (s *Scanner) Err() error

Err returns the first non-EOF error that was encountered by the Scanner.

func (*Scanner) Scan

func (s *Scanner) Scan() bool

Scan the next SQL token.

func (*Scanner) Text

func (s *Scanner) Text() string

Text returns the token's text from the last scan.

func (*Scanner) Token

func (s *Scanner) Token() Token

Token returns the token from the last scan.

type Token

type Token int

Token is a lexical token for SQL.

const (
	TokenIllegal     Token = iota // unexpected character
	TokenEOF                      // End of input
	TokenWhiteSpace               // White space
	TokenComment                  // SQL comment
	TokenIdent                    // identifer, which may be quoted
	TokenKeyword                  // keyword
	TokenLiteral                  // string or numeric literal
	TokenOperator                 // operator
	TokenPlaceholder              // prepared statement placeholder
)

Tokens

Jump to

Keyboard shortcuts

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