scanner

package
v0.0.0-...-fc8933c Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const EndCh = rune(-1)

Variables

View Source
var (
	Always        = func(r rune) bool { return r != EndCh }
	IsCharAF      = Or(IsUpperCharAF, IsLowerCharAF)
	IsCharAZ      = Or(IsUpperCharAZ, IsLowerCharAZ)
	IsCurrency    = func(r rune) bool { return unicode.Is(unicode.Sc, r) }
	IsDigit01     = Rune2('0', '1')
	IsDigit07     = RuneRange('0', '7')
	IsDigit09     = RuneRange('0', '9')
	IsDigit0F     = Or(IsDigit09, IsLowerCharAF, IsUpperCharAF)
	IsEnd         = Rune(EndCh)
	IsLowerCharAF = RuneRange('a', 'f')
	IsLowerCharAZ = RuneRange('a', 'z')
	IsNewline     = Rune('\n')
	Never         = func(r rune) bool { return false }
	IsUpperCharAF = RuneRange('A', 'F')
	IsUpperCharAZ = RuneRange('A', 'Z')
)
View Source
var (
	BinDef = NumberDef{
		Digit: IsDigit01,
	}
	DecDef = NumberDef{
		Digit:  IsDigit09,
		DecSep: Rune('.'),
		Sign:   Rune2('+', '-'),
	}
	FloatDef = NumberDef{
		Digit:    IsDigit09,
		DecSep:   Rune('.'),
		Sign:     Rune2('+', '-'),
		Exponent: Rune2('e', 'E'),
	}
	HexDef = NumberDef{
		Digit: IsDigit0F,
	}
	IntDef = NumberDef{
		Digit: IsDigit09,
		Sign:  Rune2('+', '-'),
	}
	OctDef = NumberDef{
		Digit: IsDigit07,
	}
	StringDef = QuotedDef{
		Escape: Rune('\\'),
	}
	UIntDef = NumberDef{
		Digit: IsDigit09,
	}
	UDecRef = NumberDef{
		Digit:  IsDigit09,
		DecSep: Rune('.'),
	}
)
View Source
var ErrNotTerminated = errors.New("not terminated")

Functions

func Line

func Line(s *Scanner)

func LineTrimSpace

func LineTrimSpace(s *Scanner)

func ParseFloat64

func ParseFloat64(s string) float64

func ParseInt

func ParseInt(s string) int

func Word

func Word(s *Scanner)

Types

type Func

type Func func(*Scanner)

func NumberFunc

func NumberFunc(def NumberDef) Func

func QuotedFunc

func QuotedFunc(def QuotedDef) Func

func UntilFunc

func UntilFunc(until RuneClass) Func

func UntilRepeatsFunc

func UntilRepeatsFunc(is RuneClass, n int) Func

func WhileFunc

func WhileFunc(while RuneClass) Func

type NumberDef

type NumberDef struct {
	Digit    RuneClass
	DecSep   RuneClass
	Sign     RuneClass
	Exponent RuneClass
}

type Pos

type Pos struct {
	Name   string
	Line   int
	Column int
}

func NewPos

func NewPos(file string, line int, column int) Pos

func (Pos) IsValid

func (p Pos) IsValid() bool

func (Pos) String

func (p Pos) String() string

type QuotedDef

type QuotedDef struct {
	Escape    RuneClass
	EscapeMap map[rune]rune
	AltEnd    RuneClass
}

type Reader

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

func NewReader

func NewReader(src io.Reader, n int) *Reader

func NewStringReader

func NewStringReader(src string, n int) *Reader

func (*Reader) Peek

func (r *Reader) Peek(i int) rune

func (*Reader) PeekN

func (r *Reader) PeekN(n int) string

func (*Reader) Read

func (r *Reader) Read() rune

type RuneClass

type RuneClass func(rune) bool

func Not

func Not(class RuneClass) RuneClass

func OptionalClass

func OptionalClass(r RuneClass) RuneClass

func Or

func Or(classes ...RuneClass) RuneClass

func Rune

func Rune(r1 rune) RuneClass

func Rune2

func Rune2(r1 rune, r2 rune) RuneClass

func RuneRange

func RuneRange(from rune, to rune) RuneClass

func Runes

func Runes(rs ...rune) RuneClass

type Scanner

type Scanner struct {
	Error     error
	Ch        rune
	Lookahead rune
	Text      strings.Builder
	TokenPos  Pos
	ChPos     Pos
	Debug     bool
	TrimText  bool
	// contains filtered or unexported fields
}

func New

func New(src io.Reader) *Scanner

func NewBytes

func NewBytes(src []byte) *Scanner

func NewString

func NewString(src string) *Scanner

func (*Scanner) End

func (s *Scanner) End() bool

func (*Scanner) Keep

func (s *Scanner) Keep()

func (*Scanner) KeepIf

func (s *Scanner) KeepIf(c RuneClass)

func (*Scanner) Next

func (s *Scanner) Next()

func (*Scanner) Ok

func (s *Scanner) Ok() bool

func (*Scanner) Scan

func (s *Scanner) Scan(fn Func) string

func (*Scanner) ScanUntil

func (s *Scanner) ScanUntil(c RuneClass) string

func (*Scanner) ScanWhile

func (s *Scanner) ScanWhile(c RuneClass) string

func (*Scanner) SetBytes

func (s *Scanner) SetBytes(src []byte)

func (*Scanner) SetName

func (s *Scanner) SetName(name string)

func (*Scanner) SetReader

func (s *Scanner) SetReader(src io.Reader)

func (*Scanner) SetString

func (s *Scanner) SetString(src string)

func (*Scanner) SkipIf

func (s *Scanner) SkipIf(c RuneClass)

func (*Scanner) Start

func (s *Scanner) Start()

func (*Scanner) Token

func (s *Scanner) Token() string

func (*Scanner) TrimToken

func (s *Scanner) TrimToken() string

Jump to

Keyboard shortcuts

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