scanner

package
v0.23.2 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NewNumValFn = func(constant.Value, string, bool) interface{} {
	return struct{}{}
}

NewNumValFn allows us to use tree.NewNumVal without a dependency on tree.

View Source
var NewPlaceholderFn = func(string) (interface{}, error) {
	return struct{}{}, nil
}

NewPlaceholderFn allows us to use tree.NewPlaceholder without a dependency on tree.

Functions

func FirstLexicalToken

func FirstLexicalToken(sql string) (tok int)

FirstLexicalToken returns the first lexical token. Returns 0 if there is no token.

func HasMultipleStatements

func HasMultipleStatements(sql string) (multipleStmt bool, err error)

HasMultipleStatements returns true if the sql string contains more than one statements. An error is returned if an invalid token was encountered.

func LastLexicalToken

func LastLexicalToken(sql string) (lastTok int, ok bool)

LastLexicalToken returns the last lexical token. If the string has no lexical tokens, returns 0 and ok=false.

Types

type InspectToken

type InspectToken struct {
	ID      int32
	MaybeID int32
	Start   int32
	End     int32
	Str     string
	Quoted  bool
}

InspectToken is the type of token that can be scanned by Inspect.

func Inspect

func Inspect(sql string) []InspectToken

Inspect analyses the string and returns the tokens found in it. If an incomplete token was encountered at the end, an InspectToken entry with ID -1 is appended.

If a syntax error was encountered, it is returned as a token with type ERROR.

See TestInspect and the examples in testdata/inspect for more details.

type SQLScanner

type SQLScanner struct {
	Scanner
}

SQLScanner is a scanner with a SQL specific scan function

func (*SQLScanner) Scan

func (s *SQLScanner) Scan(lval ScanSymType)

Scan scans the next token and populates its information into lval.

type ScanSymType

type ScanSymType interface {
	ID() int32
	SetID(int32)
	Pos() int32
	SetPos(int32)
	Str() string
	SetStr(string)
	UnionVal() interface{}
	SetUnionVal(interface{})
}

ScanSymType is the interface for accessing the fields of a yacc symType.

type Scanner

type Scanner struct {

	// Comments is the list of parsed comments from the SQL statement.
	Comments []string
	// contains filtered or unexported fields
}

Scanner lexes SQL statements.

func (*Scanner) Cleanup

func (s *Scanner) Cleanup()

Cleanup is used to avoid holding on to memory unnecessarily (for the cases where we reuse a Scanner).

func (*Scanner) In

func (s *Scanner) In() string

In returns the input string.

func (*Scanner) Init

func (s *Scanner) Init(str string)

Init initializes a new Scanner that will process str.

func (*Scanner) Pos

func (s *Scanner) Pos() int

Pos returns the current position being lexed.

func (*Scanner) ScanComment

func (s *Scanner) ScanComment(lval ScanSymType) (present, ok bool)

ScanComment scans the input as a comment.

Jump to

Keyboard shortcuts

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