scanner

package
v0.0.0-...-3259c9a Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrorHandler

type ErrorHandler func(pos gotok.Position, msg string)

An ErrorHandler may be provided to Scanner.Init. If a syntax error is encountered and a handler was installed, the handler is called with a position and an error message. The position points to the beginning of the offending token.

type Scanner

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

A Scanner holds the scanner's internal state while processing a given text. It can be allocated as part of another data structure but must be initialized via Init before use.

func (*Scanner) Init

func (s *Scanner) Init(file *gotok.File, src []byte, err ErrorHandler)

Init prepares the scanner s to tokenize the text src by setting the scanner at the beginning of src. The scanner uses the file set file for position information and it adds line information for each line. It is ok to re-use the same file when re-scanning the same file as line information which is already present is ignored. Init causes a panic if the file size does not match the src size.

Calls to Scan will invoke the error handler err if they encounter a syntax error and err is not nil.

Note that Init may call err if there is an error in the first character of the file.

func (*Scanner) Scan

func (s *Scanner) Scan() (pos gotok.Pos, tok token.Token, lit string)

Scan scans the next token and returns the token position, the token, and its literal string if applicable. The source end is indicated by token.EOF.

If the returned token is a literal, or token.TexComment, the literal string has the corresponding value.

If the returned token is token.Illegal, the literal string is the offending character.

In all other cases, Scan returns an empty literal string.

For more tolerant parsing, Scan will return a valid token if possible even if a syntax error was encountered. Thus, even if the resulting token sequence contains no illegal tokens, a client may not assume that no error has occurred. Instead, the client must check the scanner's ErrorCount or the number of calls of the error handler, if there was one installed.

Token positions are relative to the file.

type TemplateQuery

type TemplateQuery struct {
	Comments []string
	// Name of the query, from the comment preceding the query.
	// Like 'FindAuthors' in:
	//     -- Name: FindAuthors :many
	Name string
	// The SQL as it appeared in the source query file.
	SQL string
}

TemplateQuery represents a single parsed SQL TemplateQuery.

Jump to

Keyboard shortcuts

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