scanner

package
v0.0.16 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2022 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const EOF = rune(0)

EOF is a rune representing the end of a file

Variables

This section is empty.

Functions

This section is empty.

Types

type Location

type Location struct {
	BytePos, RunePos, Line, Column int
}

Location describes a location in the Scanner's stream.

func (Location) String

func (p Location) String() string

type Scanner

type Scanner struct {

	// Path is the file path.
	Path string
	// Location is the current position in the stream.
	Location Location
	// contains filtered or unexported fields
}

Scanner is a backtracking reader.

func New

func New(r io.RuneReader, path string) (*Scanner, error)

New creates a new Scanner.

func (*Scanner) Advance

func (s *Scanner) Advance() error

Advance reads a rune.

func (*Scanner) ConsumeRune

func (s *Scanner) ConsumeRune(r rune) error

ConsumeRune consumes the given rune

func (*Scanner) ConsumeUntil

func (s *Scanner) ConsumeUntil(pred func(r rune) bool) error

ConsumeUntil advances the parser until the predicate holds

func (*Scanner) ConsumeWhile

func (s *Scanner) ConsumeWhile(pred func(r rune) bool) error

ConsumeWhile advances the parser while the predicate holds

func (*Scanner) Current

func (s *Scanner) Current() rune

Current returns the current rune.

func (*Scanner) ParseError

func (s *Scanner) ParseError(err error) error

ParseError creates a new parser error with the current position.

func (*Scanner) ParseString

func (s *Scanner) ParseString(str string) error

ParseString parses the given string

func (*Scanner) ReadN

func (s *Scanner) ReadN(n int) (string, error)

ReadN reads a string with n runes

func (*Scanner) ReadRune

func (s *Scanner) ReadRune() (r rune, size int, err error)

ReadRune implements io.RuneReader.

func (*Scanner) ReadWhile

func (s *Scanner) ReadWhile(pred func(r rune) bool) (string, error)

ReadWhile reads runes into the builder while the predicate holds

Jump to

Keyboard shortcuts

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