braceexpansion

package module
v0.0.0-...-fc18a38 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2020 License: MIT Imports: 4 Imported by: 3

README

braceexpansion

Build Status Go Report Card Coverage Status

Shell brace expansion implemented in Go (golang).

Supports some specialties required by multigoogle.

Numeric ranges are currently not supported, as I didn't need them. Feel free to send a PR.

Build

$ cd cmd && go build -o be

Usage (command line):

$ be '{a,b}{1,2}'
a1
a2
b1
b2

Usage (library):

import (
	be "github.com/thomasheller/braceexpansion"
	"fmt"
)

func main() {
	tree, err := be.New().Parse("{a,b}{1,2}")
	if err != nil {
		panic(err)
	}
	for _, s := range tree.Expand() {
		fmt.Println(s)
	}
	
	// Output:
	// a1
	// a2
	// b1
	// b2
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cartesian

func Cartesian(sets [][]string) []string

func Cartesian2

func Cartesian2(first, second []string) []string

Types

type ListNode

type ListNode struct {
	NodeType
	Phrases []PhraseNode
	Tree    *Tree
}

func (ListNode) Expand

func (l ListNode) Expand(root bool) []string

type Node

type Node interface{}

type NodeType

type NodeType int
const (
	NodeList NodeType = iota
	NodePhrase
	NodeText
)

type ParseOpts

type ParseOpts struct {
	OpenBrace             string
	CloseBrace            string
	Separator             string
	TreatRootAsList       bool
	TreatSingleAsOptional bool
}

type PhraseNode

type PhraseNode struct {
	NodeType
	Parts []Node // TextNode or ListNode
}

func (PhraseNode) Expand

func (p PhraseNode) Expand() []string

type TextNode

type TextNode struct {
	NodeType
	// contains filtered or unexported fields
}

func (TextNode) Expand

func (t TextNode) Expand() []string

type Tree

type Tree struct {
	Root *ListNode
	// contains filtered or unexported fields
}

func New

func New() *Tree

func (*Tree) Expand

func (t *Tree) Expand() []string

func (*Tree) Parse

func (t *Tree) Parse(input string) (tree *Tree, err error)

func (*Tree) ParseCustom

func (t *Tree) ParseCustom(input string, opts ParseOpts) (tree *Tree, err error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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