tokenizer

package
v0.0.0-...-44e12ef Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2024 License: BSD-2-Clause Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Tokenizer

type Tokenizer interface {
	// Next processes the next token and returns true
	// if there are more tokens to process.
	Next() bool
	// Token returns the current token.
	// It must be called after Next.
	Token() string
}

Tokenizer is an interface for tokenizers.

func Chain

func Chain(tokenizers ...Tokenizer) Tokenizer

Chain returns a Tokenizer that combines the given tokenizers into a chain.

The Next method of chain gets tokens serially from the chained tokenizers until the last one returns false. For example, the following code:

ch := tokenizer.Chain(tokenizer.Words("hello world"), tokenizer.Words("this is me"))
for ch.Next() {
	fmt.Printf("%s, ", ch.Token())
}

will print:

hello, world, this, is, me,

func Words

func Words(input string) Tokenizer

Words returns a Tokenizer that tokenizes input into words.

Jump to

Keyboard shortcuts

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