lexer

package
v0.0.0-...-ecdd562 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package lexer contains a simple lexer for dealing with command line arguments. This package is used to allow us to split strings that are meant to be turned into exec.Cmd into the args it understands. This should only take input from a controlled environment, as I did not attempt to prevent the myriad of possible injection attacks I'm sure can occur. This is for DevOps use where we are reading in files controlled by the engineers and peer reviewed, not for taking from some random user.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Item

type Item struct {
	// Type is the type of item.
	Type ItemType
	// Value is the value.
	Value string
}

Item describes a lexed item.

type ItemType

type ItemType int

ItemType describes the type of item being emitted by the Lexer. There are predefined ItemType(s) and the rest are defined by the user.

const (
	// ItemUnknown indicates that the Item is an unknown. This should only happen on
	// a Item that is the zero type.
	ItemUnknown ItemType = iota
	// ItemWord indicates this is simply a word character in the line.
	ItemWord
	// ItemFlag indicates this word started with -- or -. It will not contain an = sign.
	ItemFlag
	// ItemFlagAndValue indicates this word started with a -- or - and has a = sign in it.
	ItemFlagAndValue
	// ItemErr indicates we had an error and the Value will be the output text.
	ItemErr
	// ItemEOL indicates we have reached the end of the line.
	ItemEOL
)

type Line

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

Line is a line lexer targeted at command line arguments.

func New

func New() *Line

New is the constructor for Line.

func (*Line) Parse

func (l *Line) Parse(s string) chan Item

Parse parses our line into Item(s) and emits them on the returned channel.

Jump to

Keyboard shortcuts

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