scanner

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2016 License: MIT Imports: 6 Imported by: 0

README

scanner GoDoc

Package scanner implements a simple lexical scanner for SQL statements.

There is no backward compatibility guarantee for this package.

Documentation

Overview

Package scanner implements a simple lexical scanner for SQL statements.

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) AddKeywords

func (s *Scanner) AddKeywords(keywords ...string)

AddKeywords informs the scanner of keywords. Keywords are not case sensitive.

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 (
	ILLEGAL     Token = iota // unexpected character
	EOF                      // End of input
	WS                       // White space
	COMMENT                  // SQL comment
	IDENT                    // identifer, which may be quoted
	KEYWORD                  // keyword as per AddKeywords
	LITERAL                  // string or numeric literal
	OP                       // operator
	PLACEHOLDER              // prepared statement placeholder
)

Tokens

Jump to

Keyboard shortcuts

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