parser

package
v1.1.4 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Split

func Split(sql io.Reader) (stats []string)

Use bufio.Scanner to split a PostgreSQL string into multiple statements.

The core problem is to figure out whether the current ; separator is inside an escaped string literal. PostgreSQL has multiple ways of opening a string literal, $$, ', --, /*, etc. We use a FSM to guarantee these states are entered exclusively. If not in one of the above escape states, the next ; token can be parsed as statement separator.

Each statement is split as it is, without removing comments or white spaces.

Types

type BlockState

type BlockState struct {
	// contains filtered or unexported fields
}

Opened a block comment

func (*BlockState) Next

func (s *BlockState) Next(r rune, data []byte) State

type CommentState

type CommentState struct{}

Opened a line comment

func (*CommentState) Next

func (s *CommentState) Next(r rune, data []byte) State

type DollarState

type DollarState struct {
	// contains filtered or unexported fields
}

Opened a dollar quote, no characters are ever esacped.

func (*DollarState) Next

func (s *DollarState) Next(r rune, data []byte) State

type EscapeState

type EscapeState struct{}

Opened a \ escape

func (*EscapeState) Next

func (s *EscapeState) Next(r rune, data []byte) State

type QuoteState

type QuoteState struct {
	// contains filtered or unexported fields
}

Opened a single quote '

func (*QuoteState) Next

func (s *QuoteState) Next(r rune, data []byte) State

type ReadyState

type ReadyState struct{}

Initial state: ready to parse next token

func (*ReadyState) Next

func (s *ReadyState) Next(r rune, data []byte) State

type State

type State interface {
	// Return nil to emit token
	Next(r rune, data []byte) State
}

type TagState

type TagState struct {
	// contains filtered or unexported fields
}

Opened a tag, ie. $tag$

func (*TagState) Next

func (s *TagState) Next(r rune, data []byte) State

Jump to

Keyboard shortcuts

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