parser

package
v10.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2022 License: MIT Imports: 2 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotACommand = errors.New("not a command")

ErrNotACommand is the error returned when the string to be parsed does not represent a command syntactically

View Source
var ErrTokenizeError = errors.New("error tokenizing")

ErrTokenizeError represents an error tokenizing where there was an opening quote without a paired closing

View Source
var ErrUnknownCommand = errors.New("unknown command")

ErrUnknownCommand is the error returned when the string to be parsed is a command syntactically but that command is not registered

Functions

func MaybeCount

func MaybeCount(line string) (string, string)

MaybeCount attempts to split some text that might contain a "count" at the end

Recognized "count" format is a string of digits, possibly preceded by an x, +, or -, preceeded by a space

func Tokenize

func Tokenize(msg string, delim, escape rune, quots []rune) ([]string, error)

Tokenize will split a string into delim-separated tokens, accounting for quoted sections and escapes

Types

type Options

type Options struct {
	CmdIndicator  string
	KnownCommands []string
	CaseSensitive bool
}

Options specifies options when constructing a new Parser

- CmdIndicator is the string that all commands must be prefixed with (e.g., "!" or "/") - KnownCommands is a list of commands that should be recognized (expanded with LearnCommand) - CaseSensitive will make the parser case-sensitive when determining if it knows about a command

type Parser

type Parser interface {
	ParseCommand(line string) (cmd string, err error)
	KnownCommand(cmd string) bool
	LearnCommand(cmd string)
	LeadChar() string
	IsCaseSensitive() bool
}

Parser is an interface describing a repl/text interface command parser

func NewParser

func NewParser(opts Options) Parser

NewParser constructs a new Parser

Directories

Path Synopsis
Code generated by counterfeiter.
Code generated by counterfeiter.

Jump to

Keyboard shortcuts

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