scanner

package
v0.63.0 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

type Error struct {
	Pos     Position
	Message string
}

Error represents a scanner error.

type Position

type Position struct {
	Offset int // start offset in bytes
	End    int // end offset in bytes
	Row    int // line number computed in bytes
	Col    int // column number computed in bytes
}

Position represents a point in the scanned source code.

type Scanner

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

Scanner is used to tokenize an input stream of Rego source code.

func New

func New(r io.Reader) (*Scanner, error)

New returns an initialized scanner that will scan through the source code provided by the io.Reader.

func (*Scanner) AddKeyword added in v0.34.0

func (s *Scanner) AddKeyword(kw string, tok tokens.Token)

AddKeyword adds a string -> token mapping to this Scanner instance.

func (*Scanner) Bytes

func (s *Scanner) Bytes() []byte

Bytes returns the raw bytes for the full source which the scanner has read in.

func (*Scanner) HasKeyword added in v0.58.0

func (s *Scanner) HasKeyword(keywords map[string]tokens.Token) bool

func (*Scanner) Keyword added in v0.34.0

func (s *Scanner) Keyword(lit string) tokens.Token

Keyword will return a token for the passed in literal value. If the value is a Rego keyword then the appropriate token is returned. Everything else is an Ident.

func (*Scanner) RegoV1Compatible added in v0.58.0

func (s *Scanner) RegoV1Compatible() bool

func (*Scanner) Scan

func (s *Scanner) Scan() (tokens.Token, Position, string, []Error)

Scan will increment the scanners position in the source code until the next token is found. The token, starting position of the token, string literal, and any errors encountered are returned. A token will always be returned, the caller must check for any errors before using the other values.

func (*Scanner) SetRegoV1Compatible added in v0.58.0

func (s *Scanner) SetRegoV1Compatible()

func (*Scanner) String

func (s *Scanner) String() string

String returns a human readable string of the current scanner state.

func (*Scanner) WithKeywords added in v0.34.0

func (s *Scanner) WithKeywords(kws map[string]tokens.Token) *Scanner

WithKeywords returns a new copy of the Scanner struct `s`, with the set of known keywords being that of `s` with `kws` added.

func (*Scanner) WithoutKeywords added in v0.37.0

func (s *Scanner) WithoutKeywords(kws map[string]tokens.Token) (*Scanner, map[string]tokens.Token)

WithoutKeywords returns a new copy of the Scanner struct `s`, with the set of known keywords being that of `s` with `kws` removed. The previously known keywords are returned for a convenient reset.

Jump to

Keyboard shortcuts

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