scanner

package module
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2021 License: GPL-2.0 Imports: 8 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// Token types exposed from "text/scanner"
	EOF       = ts.EOF
	Ident     = ts.Ident
	String    = ts.String
	RawString = ts.RawString
	Comment   = ts.Comment
	Float     = ts.Float
	Int       = ts.Int
)
View Source
const (
	KeyWord     // A registered keyword
	HashComment // A shell-style # comments
	Timespan    // A toolman.org/timespan literal
	Regex       // A regular expression literal
	StdSize     // A toolman.org/numbers/stdsize Value
)
View Source
const (
	// Scan mode bits exposed from "text/scanner"
	ScanIdents     = ScanMode(ts.ScanIdents)
	ScanInts       = ScanMode(ts.ScanInts)
	ScanFloats     = ScanMode(ts.ScanFloats)
	ScanChars      = ScanMode(ts.ScanChars)
	ScanStrings    = ScanMode(ts.ScanStrings)
	ScanRawStrings = ScanMode(ts.ScanRawStrings)
	ScanComments   = ScanMode(ts.ScanComments)
	SkipComments   = ScanMode(ts.SkipComments)
	GoTokens       = ScanMode(ts.GoTokens)
)
View Source
const (

	// ScanHashComments is a scanner Option that enabled scanning of
	// hash comments. For Go style comments, see ScanComments. Similar
	// to ScanComments, the SkipComments option may be used to treat
	// comments as white space.
	ScanHashComments = ScanMode(1 << -HashComment)

	// ScanTimespans is a scanner Option that enabled scanning of
	// Timespan literals as defined by the toolman.org/timespan package.
	ScanTimespans = ScanMode(1 << -Timespan)

	// ScanRegexen is a scanner Option that enables unconditional
	// scanning of regular expression. For a more restrictive regular
	// expression option, which only enables scanning after specific
	// tokens, see ScanRegexenAfter.
	ScanRegexen = ScanMode(1 << -Regex)

	// ScanStdSizes is a scanner Option that enabled scanning ofstandard
	// size designations as defined by the toolman.org/numbers/stdsize
	// package.
	ScanStdSizes = ScanMode(1 << -StdSize)
)

Variables

This section is empty.

Functions

func IsZeroPosition added in v0.7.0

func IsZeroPosition(p Position) bool

func PositionsEqual added in v0.7.0

func PositionsEqual(p1, p2 Position) bool

func ScanRegexenAfter

func ScanRegexenAfter(tokens ...int) *reAfter

ScanRegexenAfter returns a scanner Option that enables the scanning of regular expressions immediately following one of the provided tokens. Regular expression scanning is otherwise disabled.

This option should not be used in conjunction with the broader ScanRegexen, which enables regular expression scanning unconditionally.

func TokenString

func TokenString(tok rune) string

Types

type Double

type Double struct {
	Rune  rune
	Token int
}

type Doubles

type Doubles []*Double

type ErrFunc

type ErrFunc func(string)

type Keyword

type Keyword struct {
	Word  string
	Token int
}

type KeywordMap

type KeywordMap map[string]int

type Keywords

type Keywords []*Keyword

type Option

type Option interface {
	// contains filtered or unexported methods
}

type Position

type Position = ts.Position

func ZeroPosition

func ZeroPosition() Position

type RunePair

type RunePair struct {
	Left  rune
	Right rune
	Token int
}

type RunePairs

type RunePairs []*RunePair

type ScanMode

type ScanMode int

type Scanner

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

func New

func New(src Source, options ...Option) *Scanner

func (*Scanner) Disable

func (s *Scanner) Disable(mode ...ScanMode)

func (*Scanner) Enable

func (s *Scanner) Enable(mode ...ScanMode)

func (*Scanner) Next

func (s *Scanner) Next() rune

func (*Scanner) Peek

func (s *Scanner) Peek() rune

func (*Scanner) Position

func (s *Scanner) Position() Position

Position returns the position of the most recently scanned token or, if that is invalid, the position of the character immediately following the most recently scanned token or character.

func (*Scanner) Regex

func (s *Scanner) Regex() *regexp.Regexp

func (*Scanner) Scan

func (s *Scanner) Scan() (tok rune)

func (*Scanner) StdSize

func (s *Scanner) StdSize() stdsize.Value

func (*Scanner) Text

func (s *Scanner) Text() string

func (*Scanner) Timespan

func (s *Scanner) Timespan() *timespan.Timespan

func (*Scanner) Token

func (s *Scanner) Token() int

func (*Scanner) TokenString

func (s *Scanner) TokenString(tok rune) string

type Source

type Source interface {
	Name() string
	io.Reader
}

Source is a data source for Scanner text input. Any io.Reader having a `Name() string` method can be used as a Source, and -- as luck would have it, `*os.File` satisfies Source.

Jump to

Keyboard shortcuts

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