lexer

package
v2.2.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2019 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 Lexer

type Lexer struct {
	// Token is the lexical token.
	Token scanner.Token

	// Text is the lexical value.
	Text string

	// RawText is the scanned raw text.
	RawText []rune

	// Pos is the source position.
	Pos scanner.Position

	// Error is called for each error encountered. If no Error
	// function is set, the error is reported to os.Stderr.
	Error func(lexer *Lexer, err error)
	// contains filtered or unexported fields
}

Lexer is a lexer.

func NewLexer

func NewLexer(input io.Reader, opts ...Option) *Lexer

NewLexer creates a new lexer.

func (*Lexer) IsEOF

func (lex *Lexer) IsEOF() bool

IsEOF checks whether read buffer is empty.

func (*Lexer) LatestErr

func (lex *Lexer) LatestErr() error

LatestErr returns the latest non-EOF error that was encountered by the Lexer.Next().

func (*Lexer) Next

func (lex *Lexer) Next()

Next scans the read buffer.

func (*Lexer) NextComment

func (lex *Lexer) NextComment()

NextComment scans the read buffer with ScanComment mode.

func (*Lexer) NextKeyword

func (lex *Lexer) NextKeyword()

NextKeyword scans the read buffer with ScanKeyword mode.

func (*Lexer) NextKeywordOrStrLit

func (lex *Lexer) NextKeywordOrStrLit()

NextKeywordOrStrLit scans the read buffer with ScanKeyword or ScanStrLit modes.

func (*Lexer) NextLit

func (lex *Lexer) NextLit()

NextLit scans the read buffer with ScanLit mode.

func (*Lexer) NextNumberLit

func (lex *Lexer) NextNumberLit()

NextNumberLit scans the read buffer with ScanNumberLit mode.

func (*Lexer) NextStrLit

func (lex *Lexer) NextStrLit()

NextStrLit scans the read buffer with ScanStrLit mode.

func (*Lexer) Peek added in v1.3.0

func (lex *Lexer) Peek() scanner.Token

Peek returns the next token with keeping the read buffer unchanged.

func (*Lexer) ReadConstant

func (lex *Lexer) ReadConstant() (string, scanner.Position, error)

ReadConstant reads a constant. constant = fullIdent | ( [ "-" | "+" ] intLit ) | ( [ "-" | "+" ] floatLit ) | strLit | boolLit

func (*Lexer) ReadEmptyStatement

func (lex *Lexer) ReadEmptyStatement() error

ReadEmptyStatement reads an emptyStatement.

emptyStatement = ";"

See https://developers.google.com/protocol-buffers/docs/reference/proto3-spec#emptystatement

func (*Lexer) ReadEnumType

func (lex *Lexer) ReadEnumType() (string, scanner.Position, error)

ReadEnumType reads a messageType. enumType = [ "." ] { ident "." } enumName See https://developers.google.com/protocol-buffers/docs/reference/proto3-spec#identifiers

func (*Lexer) ReadFullIdent

func (lex *Lexer) ReadFullIdent() (string, scanner.Position, error)

ReadFullIdent reads a fullIdent. fullIdent = ident { "." ident }

func (*Lexer) ReadMessageType

func (lex *Lexer) ReadMessageType() (string, scanner.Position, error)

ReadMessageType reads a messageType. messageType = [ "." ] { ident "." } messageName See https://developers.google.com/protocol-buffers/docs/reference/proto3-spec#identifiers

func (*Lexer) UnNext

func (lex *Lexer) UnNext()

UnNext put the latest text back to the read buffer.

func (*Lexer) UnNextTo

func (lex *Lexer) UnNextTo(lastScan []rune)

UnNextTo put the given latest text back to the read buffer.

type Option

type Option func(*Lexer)

Option is an option for lexer.NewLexer.

func WithDebug

func WithDebug(debug bool) Option

WithDebug is an option to enable the debug mode.

func WithFilename

func WithFilename(filename string) Option

WithFilename is an option for scanner.Option.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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