lexer

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2020 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ParseError

type ParseError struct {
	// Input is the text to parse
	Input string
	// Msg s the error message
	Msg string
	// Post is where in the input the error occurred
	Pos int
}

ParseError represents a parsing error

func (*ParseError) Error

func (t *ParseError) Error() string

type Token

type Token struct {
	// Type is the token type
	Typ TokenType
	// Val the textual content
	Val string
	// Pos is the token position in the input
	Pos int
}

Token has a type, a value and a position in the input

func Tokenize

func Tokenize(usage string) ([]*Token, error)

Tokenize transforms the provided input into a slice of tokens or returns a ParseError

func (*Token) String

func (t *Token) String() string

type TokenType

type TokenType string

TokenType is a type representing the different kinds of tokens

const (
	// TTArg is an arg token, e.g. ARG, SRC. DST
	TTArg TokenType = "Arg"
	// TTOpenPar (
	TTOpenPar TokenType = "OpenPar"
	// TTClosePar )
	TTClosePar TokenType = "ClosePar"
	// TTOpenSq [
	TTOpenSq TokenType = "OpenSq"
	// TTCloseSq ]
	TTCloseSq TokenType = "CloseSq"
	// TTChoice |
	TTChoice TokenType = "Choice"
	// TTOptions is the special OPTIONS keyword
	TTOptions TokenType = "Options"
	// TTRep ...
	TTRep TokenType = "Rep"
	// TTShortOpt -a, -f, ...
	TTShortOpt TokenType = "ShortOpt"
	// TTLongOpt --force, --retry, ...
	TTLongOpt TokenType = "LongOpt"
	// TTOptSeq a folded option sequence, -rm
	TTOptSeq TokenType = "OptSeq"
	// TTOptValue is the special =<example> syntax token
	TTOptValue TokenType = "OptValue"
	// TTDoubleDash --
	TTDoubleDash TokenType = "DblDash"
)

Jump to

Keyboard shortcuts

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