scanner

package
v0.0.0-...-c1fdb11 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2024 License: GPL-3.0 Imports: 3 Imported by: 0

Documentation

Overview

Package scanner is a token scanner tailored to this library.

BUG(sw) this could probably be almost completely replaced with stdlib's text/scanner.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Scanner

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

Scanner is a token scanner.

func NewScanner

func NewScanner(source string) *Scanner

NewScanner creates a new scanner with the given source.

func (*Scanner) Advance

func (l *Scanner) Advance(count int) error

Advance consumes count runes but does not return them.

func (*Scanner) Chomp

func (l *Scanner) Chomp()

Chomp advances past any whitespace.

func (*Scanner) Expect

func (l *Scanner) Expect(token string) (string, error)

Expect tells the scanner that the given token must be found at the current position, and consumes it.

If it is not found, it will return an error and the scanner position will not change.

func (*Scanner) FindToken

func (l *Scanner) FindToken(token string, caseSensitive bool) bool

FindToken returns true if it finds the at the current position, and false otherwise. It does not consume the token.

FindToken will perform a case-insensitive match if caseSensitive = false.

func (*Scanner) Peek

func (l *Scanner) Peek() (rune, error)

Peek returns the next rune without consuming it. It returns io.EOF if the scanner is at the end of the source.

func (*Scanner) Pop

func (l *Scanner) Pop() (rune, error)

Pop returns the next rune and consumes it. It returns io.EOF if the scanner is at the end of the source.

func (*Scanner) Pos

func (l *Scanner) Pos() int

Pos returns the current position of the scanner.

func (*Scanner) Until

func (l *Scanner) Until(r rune) (string, error)

Until searches for the next occurrence of r and returns the string from the starting position to right before r.

All runes from the starting position to r are consumed. r is not consumed.

Notes

Bugs

  • this could probably be almost completely replaced with stdlib's text/scanner.

Jump to

Keyboard shortcuts

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