schema

package
v0.0.0-...-2fb4953 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2018 License: MIT Imports: 5 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Split the token in two parts to build up an expression, the option flag and the assignment value.
	// The leftmost the option flag, and the rightmost the option assignment value.
	// nolint: dupl
	AssmbModelSplit = &ExprAssemblyModel{
		AssmbTypeSplit,
		func(groupParts TokenList, variant *OptExpressionVariant) (*OptionExpression, error) {
			if len(groupParts) != 1 {
				return nil, errors.New("assembly model 'Split' needs exactly one argument")
			}
			groups, err := matchLeftSideArg(variant, groupParts, 2, "Split")
			if err != nil {
				return nil, err
			}
			return NewOptionExpression(&OptionDefinition{
				variant,
				groups[0],
				groups[1],
			}), nil
		},
	}
	// Group two tokens in one expression.
	// The leftmost the option flag, and the rightmost the option assignment value.
	AssmbModelGroup = &ExprAssemblyModel{
		AssmbTypeGroup,
		func(groupParts TokenList, variant *OptExpressionVariant) (*OptionExpression, error) {
			if len(groupParts) != 2 {
				return nil, errors.New("assembly model 'Group' needs exactly two arguments")
			}
			groups, err := matchLeftSideArg(variant, groupParts, 1, "Group")
			if err != nil {
				return nil, err
			}
			return NewOptionExpression(&OptionDefinition{
				variant,
				groups[0],
				groupParts[1].Value,
			}), nil
		},
	}
	// Create an expression from one token, with no assignment value.
	AssmbModelFlag = &ExprAssemblyModel{
		AssmbTypeFlag,
		func(groupParts TokenList, variant *OptExpressionVariant) (*OptionExpression, error) {
			if len(groupParts) != 1 {
				return nil, errors.New("assembly model 'flag' needs exactly one argument")
			}
			groups, err := matchLeftSideArg(variant, groupParts, 1, "flag")
			if err != nil {
				return nil, err
			}
			return NewOptionExpression(&OptionDefinition{
				variant,
				groups[0],
				"",
			}), nil
		},
	}
	// Create an expression mapping to multiple options from one token, with no assignment value.
	AssmbModelFlagStack = &ExprAssemblyModel{
		AssmbTypeFlagStack,
		func(groupParts TokenList, variant *OptExpressionVariant) (*OptionExpression, error) {
			if len(groupParts) != 1 {
				return nil, errors.New("assembly model 'FlagStack' needs exactly one argument")
			}
			groups, err := matchLeftSideArg(variant, groupParts, 1, "FlagStack")
			if err != nil {
				return nil, err
			}
			flags := strings.Split(groups[0], "")
			options := make([]*OptionDefinition, len(flags))
			for i := range flags {
				options[i] = &OptionDefinition{variant, flags[i], ""}
			}
			return NewOptionExpression(options...), nil
		},
	}
	AssmModelNone = &ExprAssemblyModel{
		AssmbTypeNone,
		func(groupParts TokenList, variant *OptExpressionVariant) (*OptionExpression, error) {
			if len(groupParts) != 1 {
				return nil, errors.New("assembly model 'TypeNone' needs exactly one argument")
			}
			return NewOptionExpression(&OptionDefinition{variant, "", ""}), nil
		},
	}
)
View Source
var (
	VariantPOSIXShortSwitch          = NewOptExpressionVariant(OptStylePOSIX, RegBuilderOneDashLetter, AssmbModelFlag, "VariantPOSIXShortSwitch")
	VariantPOSIXStackedShortSwitches = NewOptExpressionVariant(OptStylePOSIX, RegBuilderOneDashWordAlphaNum, AssmbModelFlagStack, "VariantPOSIXStackedShortSwitches")
	VariantPOSIXShortAssignment      = NewOptExpressionVariant(OptStylePOSIX, RegBuilderOneDashLetter, AssmbModelGroup, "VariantPOSIXShortAssignment")
	VariantPOSIXShortStickyValue     = NewOptExpressionVariant(OptStylePOSIX, RegBuilderPosixShortStickyValue, AssmbModelSplit, "VariantPOSIXShortStickyValue")
	VariantX2lktSwitch               = NewOptExpressionVariant(OptStyleXToolkit, RegBuilderOneDashWord, AssmbModelFlag, "VariantX2lktSwitch")
	VariantX2lktReverseSwitch        = NewOptExpressionVariant(OptStyleXToolkit, RegBuilderX2lktReverseSwitch, AssmbModelFlag, "VariantX2lktReverseSwitch")
	VariantX2lktImplicitAssignment   = NewOptExpressionVariant(OptStyleXToolkit, RegBuilderOneDashWord, AssmbModelGroup, "VariantX2lktImplicitAssignment")
	VariantX2lktExplicitAssignment   = NewOptExpressionVariant(OptStyleXToolkit, RegBuilderX2lktExplicitAssignment, AssmbModelSplit, "VariantX2lktExplicitAssignment")
	VariantGNUSwitch                 = NewOptExpressionVariant(OptStyleGNU, RegBuilderTwoDashWord, AssmbModelFlag, "VariantGNUSwitch")
	VariantGNUImplicitAssignment     = NewOptExpressionVariant(OptStyleGNU, RegBuilderTwoDashWord, AssmbModelGroup, "VariantGNUImplicitAssignment")
	VariantGNUExplicitAssignment     = NewOptExpressionVariant(OptStyleGNU, RegBuilderGnuExplicitAssignment, AssmbModelSplit, "VariantGNUExplicitAssignment")
	VariantHeadlessOption            = NewOptExpressionVariant(OptStyleOld, RegBuilderOptWord, AssmbModelFlag, "VariantHeadlessOption")
	VariantEndOfOptions              = &OptExpressionVariant{
		style:         OptStyleNone,
		assemblyRegex: RegexEndOfOptions,
		assemblyModel: AssmModelNone,
		name:          "VariantEndOfOptions",
	}
)
View Source
var (
	OptionSchemePOSIXStrict = OptionScheme{
		VariantPOSIXShortSwitch,
		VariantPOSIXStackedShortSwitches,
		VariantPOSIXShortAssignment,
		VariantEndOfOptions,
	}
	OptSchemeLinuxStandard = OptionScheme{
		VariantPOSIXShortSwitch,
		VariantPOSIXStackedShortSwitches,
		VariantPOSIXShortAssignment,
		VariantGNUSwitch,
		VariantGNUImplicitAssignment,
		VariantGNUExplicitAssignment,
		VariantEndOfOptions,
	}
	OptSchemeLinuxExplicit = OptionScheme{
		VariantPOSIXShortSwitch,
		VariantPOSIXStackedShortSwitches,
		VariantPOSIXShortAssignment,
		VariantGNUSwitch,
		VariantGNUExplicitAssignment,
		VariantEndOfOptions,
	}
	OptSchemeLinuxImplicit = OptionScheme{
		VariantPOSIXShortSwitch,
		VariantPOSIXStackedShortSwitches,
		VariantPOSIXShortAssignment,
		VariantGNUSwitch,
		VariantGNUImplicitAssignment,
		VariantEndOfOptions,
	}
	OptSchemeXToolkitStrict = OptionScheme{
		VariantX2lktImplicitAssignment,
		VariantX2lktExplicitAssignment,
		VariantX2lktReverseSwitch,
		VariantX2lktSwitch,
		VariantEndOfOptions,
	}
	OptSchemeXToolkitStandard = OptionScheme{
		VariantPOSIXShortSwitch,
		VariantPOSIXShortAssignment,
		VariantX2lktImplicitAssignment,
		VariantX2lktExplicitAssignment,
		VariantX2lktReverseSwitch,
		VariantX2lktSwitch,
		VariantEndOfOptions,
	}
	OptSchemeXToolkitExplicit = OptionScheme{
		VariantPOSIXShortSwitch,
		VariantX2lktExplicitAssignment,
		VariantX2lktReverseSwitch,
		VariantX2lktSwitch,
		VariantEndOfOptions,
	}
	OptSchemeXToolkitImplicit = OptionScheme{
		VariantPOSIXShortSwitch,
		VariantPOSIXShortAssignment,
		VariantX2lktImplicitAssignment,
		VariantX2lktReverseSwitch,
		VariantX2lktSwitch,
		VariantEndOfOptions,
	}
)
View Source
var (
	PosModOptImplicitAssignmentLeftSide = &PositionalModel{
		Binding:      BindRight,
		IsSemantic:   true,
		IsOptionPart: true,
		IsOptionFlag: true,
		name:         "PosModOptImplicitAssignmentLeftSide",
	}
	PosModOptImplicitAssignmentValue = &PositionalModel{
		Binding:      BindLeft,
		IsSemantic:   true,
		IsOptionPart: true,
		IsOptionFlag: false,
		name:         "PosModOptImplicitAssignmentValue",
	}
	PosModStandaloneOptAssignment = &PositionalModel{
		Binding:      BindNone,
		IsSemantic:   true,
		IsOptionPart: true,
		IsOptionFlag: true,
		name:         "PosModStandaloneOptAssignment",
	}
	PosModOptSwitch = &PositionalModel{
		Binding:      BindNone,
		IsSemantic:   true,
		IsOptionPart: true,
		IsOptionFlag: true,
		name:         "PosModOptSwitch",
	}
	PosModCommandOperand = &PositionalModel{
		Binding:      BindNone,
		IsSemantic:   true,
		IsOptionPart: false,
		IsOptionFlag: false,
		name:         "PosModCommandOperand",
	}
	PosModUnset = &PositionalModel{
		Binding:      BindUnknown,
		IsSemantic:   false,
		IsOptionPart: false,
		IsOptionFlag: false,
		name:         "PosModUnset",
	}
)
View Source
var (
	RegBuilderGnuExplicitAssignment = &ParametricRegexBuilder{
		`^--(%s)=(%s)$`,
		regexOptionWordGroup,
		regexValueWordGroup,
	}
	RegBuilderX2lktExplicitAssignment = &ParametricRegexBuilder{
		`^-(%s)=(%s)$`,
		regexOptionWordGroup,
		regexValueWordGroup,
	}
	RegBuilderX2lktReverseSwitch = &ParametricRegexBuilder{
		`^\+(%s)$`,
		regexOptionWordGroup,
		"",
	}
	RegBuilderPosixShortStickyValue = &ParametricRegexBuilder{
		`^-(%s)(%s+)$`,
		regexAlphaChar,
		regexNumChar,
	}
	RegBuilderOneDashLetter = &ParametricRegexBuilder{
		`^-(%s)$`,
		regexAlphaNumChar,
		"",
	}
	RegBuilderOneDashWordAlphaNum = &ParametricRegexBuilder{
		`^-(%s{2,})$`,
		regexAlphaNumChar,
		"",
	}
	RegBuilderOneDashWord = &ParametricRegexBuilder{
		`^-(%s)$`,
		regexOptionWordGroup,
		"",
	}
	RegBuilderTwoDashWord = &ParametricRegexBuilder{
		`^--(%s)$`,
		regexOptionWordGroup,
		"",
	}
	RegBuilderOptWord = &ParametricRegexBuilder{
		`^(%s)$`,
		regexOptionWordGroup,
		"",
	}
	RegBuilderMatchAny = &ParametricRegexBuilder{
		`(%s)`,
		`.*`,
		"",
	}
	RegexGnuExplicitAssignment   = RegBuilderGnuExplicitAssignment.BuildDefault()
	RegexX2lktExplicitAssignment = RegBuilderX2lktExplicitAssignment.BuildDefault()
	RegexX2lktReverseSwitch      = RegBuilderX2lktReverseSwitch.BuildDefault()
	RegexPosixShortStickyValue   = RegBuilderPosixShortStickyValue.BuildDefault()
	RegexOneDashLetter           = RegBuilderOneDashLetter.BuildDefault()
	RegexOneDashWordAlphaNum     = RegBuilderOneDashWordAlphaNum.BuildDefault()
	RegexOneDashWord             = RegBuilderOneDashWord.BuildDefault()
	RegexTwoDashWord             = RegBuilderTwoDashWord.BuildDefault()
	RegexMatchAny                = RegBuilderMatchAny.BuildDefault()
	RegexOptWord                 = RegBuilderOptWord.BuildDefault()
	RegexEndOfOptions            = regexp.MustCompile(`^--$`)
)
View Source
var (
	CfGnuExplicitAssignment = &ContextFreeTokenType{
		semanticCandidates: []*SemanticTokenType{
			SemGNUExplicitAssignment,
		},
		regexp: RegexGnuExplicitAssignment,
		name:   "CfGnuExplicitAssignment",
	}
	CfX2lktExplicitAssignment = &ContextFreeTokenType{
		semanticCandidates: []*SemanticTokenType{
			SemX2lktExplicitAssignment,
		},
		regexp: RegexX2lktExplicitAssignment,
		name:   "CfX2lktExplicitAssignment",
	}
	CfX2lktReverseSwitch = &ContextFreeTokenType{
		semanticCandidates: []*SemanticTokenType{
			SemX2lktReverseSwitch,
		},
		regexp: RegexX2lktReverseSwitch,
		name:   "CfX2lktReverseSwitch",
	}
	CfEndOfOptions = &ContextFreeTokenType{
		semanticCandidates: []*SemanticTokenType{
			SemEndOfOptions,
		},
		regexp: RegexEndOfOptions,
		name:   "CfEndOfOptions",
	}
	CfOneDashLetter = &ContextFreeTokenType{
		semanticCandidates: []*SemanticTokenType{
			SemPOSIXShortAssignmentLeftSide,
			SemPOSIXShortSwitch,
		},
		regexp: RegexOneDashLetter,
		name:   "CfOneDashLetter",
	}
	CfPosixShortStickyValue = &ContextFreeTokenType{
		semanticCandidates: []*SemanticTokenType{
			SemPOSIXShortStickyValue,
		},
		regexp: RegexPosixShortStickyValue,
		name:   "CfPosixShortStickyValue",
	}
	CfOneDashWordAlphaNum = &ContextFreeTokenType{
		semanticCandidates: []*SemanticTokenType{
			SemPOSIXStackedShortSwitches,
			SemX2lktSwitch,
			SemX2lktImplicitAssignmentLeftSide,
		},
		regexp: RegexOneDashWordAlphaNum,
		name:   "CfOneDashWordAlphaNum",
	}
	CfOneDashWord = &ContextFreeTokenType{
		semanticCandidates: []*SemanticTokenType{
			SemX2lktSwitch,
			SemX2lktImplicitAssignmentLeftSide,
		},
		regexp: RegexOneDashWord,
		name:   "CfOneDashWord",
	}
	CfTwoDashWord = &ContextFreeTokenType{
		semanticCandidates: []*SemanticTokenType{
			SemGNUSwitch,
			SemGNUImplicitAssignmentLeftSide,
		},
		regexp: RegexTwoDashWord,
		name:   "CfTwoDashWord",
	}
	CfOptWord = &ContextFreeTokenType{
		semanticCandidates: []*SemanticTokenType{
			SemOperand,
			SemPOSIXShortAssignmentValue,
			SemGNUImplicitAssignmentValue,
			SemX2lktImplicitAssignmentValue,
			SemHeadlessOption,
		},
		regexp: RegexOptWord,
		name:   "CfOptWord",
	}
	CfWord = &ContextFreeTokenType{
		semanticCandidates: []*SemanticTokenType{
			SemOperand,
			SemPOSIXShortAssignmentValue,
			SemGNUImplicitAssignmentValue,
			SemX2lktImplicitAssignmentValue,
		},
		name: "CfWord",
	}
)
View Source
var (
	// Posix
	SemPOSIXShortSwitch = NewSemanticTokenType(
		PosModOptSwitch,
		"SemPOSIXShortSwitch",
		VariantPOSIXShortSwitch,
		OptStylePOSIX,
	)
	SemPOSIXStackedShortSwitches = NewSemanticTokenType(
		PosModOptSwitch,
		"SemPOSIXStackedShortSwitches",
		VariantPOSIXStackedShortSwitches,
		OptStylePOSIX,
	)
	SemPOSIXShortAssignmentLeftSide = NewSemanticTokenType(
		PosModOptImplicitAssignmentLeftSide,
		"SemPOSIXShortAssignmentLeftSide",
		VariantPOSIXShortAssignment,
		OptStylePOSIX,
	)
	SemPOSIXShortAssignmentValue = NewSemanticTokenType(
		PosModOptImplicitAssignmentValue,
		"SemPOSIXShortAssignmentValue",
		VariantPOSIXShortAssignment,
		OptStylePOSIX,
	)
	SemPOSIXShortStickyValue = NewSemanticTokenType(
		PosModStandaloneOptAssignment,
		"SemPOSIXShortStickyValue",
		VariantPOSIXShortStickyValue,
		OptStylePOSIX,
	)
	// GNU
	SemGNUSwitch = NewSemanticTokenType(
		PosModOptSwitch,
		"SemGNUSwitch",
		VariantGNUSwitch,
		OptStyleGNU,
	)
	SemGNUExplicitAssignment = NewSemanticTokenType(
		PosModStandaloneOptAssignment,
		"SemGNUExplicitAssignment",
		VariantGNUExplicitAssignment,
		OptStyleGNU,
	)
	SemGNUImplicitAssignmentLeftSide = NewSemanticTokenType(
		PosModOptImplicitAssignmentLeftSide,
		"SemGNUImplicitAssignmentLeftSide",
		VariantGNUImplicitAssignment,
		OptStyleGNU,
	)
	SemGNUImplicitAssignmentValue = NewSemanticTokenType(
		PosModOptImplicitAssignmentValue,
		"SemGNUImplicitAssignmentValue",
		VariantGNUImplicitAssignment,
		OptStyleGNU,
	)
	// X-Toolkit
	SemX2lktSwitch = NewSemanticTokenType(
		PosModOptSwitch,
		"SemX2lktSwitch",
		VariantX2lktSwitch,
		OptStyleXToolkit,
	)
	SemX2lktReverseSwitch = NewSemanticTokenType(
		PosModOptSwitch,
		"SemX2lktReverseSwitch",
		VariantX2lktReverseSwitch,
		OptStyleXToolkit,
	)
	SemX2lktExplicitAssignment = NewSemanticTokenType(
		PosModStandaloneOptAssignment,
		"SemX2lktExplicitAssignment",
		VariantX2lktExplicitAssignment,
		OptStyleXToolkit,
	)
	SemX2lktImplicitAssignmentLeftSide = NewSemanticTokenType(
		PosModOptImplicitAssignmentLeftSide,
		"SemX2lktImplicitAssignmentLeftSide",
		VariantX2lktImplicitAssignment,
		OptStyleXToolkit,
	)
	SemX2lktImplicitAssignmentValue = NewSemanticTokenType(
		PosModOptImplicitAssignmentValue,
		"SemX2lktImplicitAssignmentValue",
		VariantX2lktImplicitAssignment,
		OptStyleXToolkit,
	)
	// Special tokens
	SemEndOfOptions = NewSemanticTokenType(
		PosModOptSwitch,
		"SemEndOfOptions",
		VariantEndOfOptions,
		OptStyleNone,
	)
	SemOperand = NewSemanticTokenType(
		PosModCommandOperand,
		"SemOperand",
		nil,
		OptStyleNone,
	)
	SemHeadlessOption = NewSemanticTokenType(
		PosModOptSwitch,
		"SemHeadlessOption",
		VariantHeadlessOption,
		OptStyleOld,
	)
)

Functions

This section is empty.

Types

type Binding

type Binding int
const (
	BindUnknown Binding = iota
	BindNone
	BindLeft
	BindRight
)

func (Binding) String

func (binding Binding) String() string

type Bindings

type Bindings []Binding

func (Bindings) Contains

func (bindings Bindings) Contains(bindingToCheck Binding) bool

type CandidatePredicate

type CandidatePredicate func(*SemanticTokenType) bool

CandidatePredicate is a predicate given a SemanticTokenType

type ContextFreeTokenType

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

func (*ContextFreeTokenType) Equal

func (tokenType *ContextFreeTokenType) Equal(comparedTType TokenType) bool

func (*ContextFreeTokenType) IsSemantic

func (tokenType *ContextFreeTokenType) IsSemantic() bool

func (*ContextFreeTokenType) Name

func (tokenType *ContextFreeTokenType) Name() string

func (*ContextFreeTokenType) PosModel

func (*ContextFreeTokenType) Regexp

func (tokenType *ContextFreeTokenType) Regexp() (*regexp.Regexp, bool)

func (*ContextFreeTokenType) SemanticCandidates

func (tokenType *ContextFreeTokenType) SemanticCandidates() []*SemanticTokenType

SemanticCandidates returns a copy of inner semanticCandidates field.

func (*ContextFreeTokenType) String

func (tokenType *ContextFreeTokenType) String() string

func (*ContextFreeTokenType) Variant

func (tokenType *ContextFreeTokenType) Variant() *OptExpressionVariant

type ExprAssemblyModel

type ExprAssemblyModel struct {
	Assemble func(TokenList, *OptExpressionVariant) (*OptionExpression, error)
	// contains filtered or unexported fields
}

An implementation of the assembling mechanism to create option expressions from tokens

type ExprAssemblyType

type ExprAssemblyType int

The assembling mechanism to create option expressions from tokens

const (
	AssmbTypeSplit     ExprAssemblyType = iota // tokens 1, options 1, use leftSideRegex to split flagName and value
	AssmbTypeGroup                             // tokens 2, options 1, assign left side to flagName, right side to value
	AssmbTypeFlag                              // tokens 1, options 1, standalone flagName
	AssmbTypeFlagStack                         // tokens 1, options n, split each letter to one AssmbTypeFlag
	AssmbTypeNone                              // tokens 1, options 1
)

type MatchModel

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

MatchModel is a structure to recognize option expressions

Internally, it is composed of a flagName, an optional paramName part and an OpExpressionVariant flagName is the option identifier, with any leading hyphens (or + sign) stripped paramName is optional, relevant for option assignments

Example: --flagName=paramName, VariantGNUExplicitAssignment

func NewAssignmentMatchModel

func NewAssignmentMatchModel(variant *OptExpressionVariant, flagName string, paramName string) *MatchModel

NewAssignmentMatchModel creates a MatchModel given an OptExpressionVariant, a flagName, a paramName. flagName is the option identifier, with any leading hyphens (or + sign) stripped paramName won't be used for matching and is just provided as a placeholder for information purpose.

Examples :

MatchModel grabbing '--opt=<something>' :

NewStandaloneMatchModel(VariantGNUExplicitAssignment, "opt", "something")

MatchModel grabbing '--option <something>' :

NewStandaloneMatchModel(VariantGNUImplicitAssignment, "option", "something")

MatchModel grabbing '-option=<something>' :

NewStandaloneMatchModel(VariantX2lktExplicitAssignment, "option", "something")

MatchModel grabbing '-p<n>' :

NewStandaloneMatchModel(VariantPOSIXShortStickyValue, "p", "n")

func NewMatchModelFromDefinition

func NewMatchModelFromDefinition(description *OptionDefinition) *MatchModel

NewMatchModelFromDefinition creates a MatchModel from an OptionDefinition

func NewPOSIXStackMatchModel

func NewPOSIXStackMatchModel(model OptDescriptionModel) *MatchModel

NewPOSIXStackMatchModel creates a MatchModel from an OptDescriptionModel Returned instance matches any expression composed of 'model' POSIXShortSwitch option variants.

func NewStandaloneMatchModel

func NewStandaloneMatchModel(variant *OptExpressionVariant, flagName string) *MatchModel

NewStandaloneMatchModel creates a MatchModel given an OptExpressionVariant and a flagName. flagName is the option identifier, with any leading hyphens (or + sign) stripped

Examples :

MatchModel grabbing '--opt' :

NewStandaloneMatchModel(VariantGNUSwitch, "opt")

MatchModel grabbing '-switch' :

NewStandaloneMatchModel(VariantX2lktSwitch, "switch")

MatchModel grabbing '+switch' :

NewStandaloneMatchModel(VariantX2lktReverseSwitch, "switch")

MatchModel grabbing '-p' :

NewStandaloneMatchModel(VariantPOSIXShortSwitch, "p")

func (*MatchModel) Description

func (matchModel *MatchModel) Description() string

Return the description bound to the underlying OptionDescription.

func (*MatchModel) FlagName

func (matchModel *MatchModel) FlagName() string

func (*MatchModel) LeftSideRegex

func (matchModel *MatchModel) LeftSideRegex() *regexp.Regexp

func (*MatchModel) MatchLeftSide

func (matchModel *MatchModel) MatchLeftSide(arg string) bool

MatchLeftSide matches the left side of an option expression against it's model.

func (*MatchModel) ParamAllowedValues

func (matchModel *MatchModel) ParamAllowedValues() []string

func (*MatchModel) ParamName

func (matchModel *MatchModel) ParamName() string

func (*MatchModel) Variant

func (matchModel *MatchModel) Variant() *OptExpressionVariant

type MatchModels

type MatchModels []*MatchModel

A slice of MatchModel

type OptDescription

type OptDescription struct {
	Description string
	MatchModels MatchModels
}

func NewOptDescription

func NewOptDescription(description string, matchModels ...*MatchModel) *OptDescription

Initialize an OptDescription ; assign description address to matchModels' description field.

func (*OptDescription) MatchArgument

func (optDescription *OptDescription) MatchArgument(arg string) ([]*SemanticTokenType, bool)

This function returns the semantic tokens type associated with the provided argument if it matched at least one, nil otherwise

func (*OptDescription) Variants

func (optDescription *OptDescription) Variants() []*OptExpressionVariant

Variants returns the option expression variants supported by its match models

type OptDescriptionModel

type OptDescriptionModel []*OptDescription

func (OptDescriptionModel) MatchArgument

func (model OptDescriptionModel) MatchArgument(arg string) ([]*SemanticTokenType, bool)

MatchArgument returns true if the provided argument matches at least one description

func (OptDescriptionModel) Variants

func (model OptDescriptionModel) Variants() []*OptExpressionVariant

Variants returns the option expression variants supported by each of its option description

type OptExpressionVariant

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

func NewOptExpressionVariant

func NewOptExpressionVariant(style OptionStyle, builder *ParametricRegexBuilder, model *ExprAssemblyModel, name string) *OptExpressionVariant

func (*OptExpressionVariant) Assemble

func (optVariant *OptExpressionVariant) Assemble(groupParts TokenList) (*OptionExpression, error)

Assemble groups a token list of one or two tokens forming a "group part" to an option expression.

func (*OptExpressionVariant) Build

func (optVariant *OptExpressionVariant) Build(flagName string, paramList []string) *regexp.Regexp

Build a leftSideRegex given a flagName name and a list paramAllowedValues. When paramAllowedValues is non-zero, it is evaluated as the concatenation of possible values a|b|c ... etc

func (*OptExpressionVariant) FlagTokenType

func (optVariant *OptExpressionVariant) FlagTokenType() *SemanticTokenType

func (*OptExpressionVariant) Name

func (optVariant *OptExpressionVariant) Name() string

func (*OptExpressionVariant) OptValueTokenType

func (optVariant *OptExpressionVariant) OptValueTokenType() *SemanticTokenType

type OptionDefinition

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

func (*OptionDefinition) AssignmentValue

func (optDefinition *OptionDefinition) AssignmentValue() string

func (*OptionDefinition) Flag

func (optDefinition *OptionDefinition) Flag() string

func (*OptionDefinition) Variant

func (optDefinition *OptionDefinition) Variant() *OptExpressionVariant

type OptionExpression

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

func NewOptionExpression

func NewOptionExpression(options ...*OptionDefinition) *OptionExpression

func (*OptionExpression) Options

func (optExpression *OptionExpression) Options() []*OptionDefinition

type OptionParts

type OptionParts interface {
	Args() []string
}

type OptionScheme

type OptionScheme []*OptExpressionVariant

func (OptionScheme) SupportsTokenType

func (scheme OptionScheme) SupportsTokenType(tokenType *SemanticTokenType) bool

type OptionStyle

type OptionStyle int
const (
	OptStyleNone OptionStyle = iota
	OptStyleXToolkit
	OptStyleGNU
	OptStylePOSIX
	OptStyleOld
)

type ParametricRegexBuilder

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

func (*ParametricRegexBuilder) Build

func (parRegex *ParametricRegexBuilder) Build(flag string, param string) (*regexp.Regexp, error)

Build a new regex from parameters flagName and paramName If paramName is empty string, defaults to defaultParamMatch

func (*ParametricRegexBuilder) BuildDefault

func (parRegex *ParametricRegexBuilder) BuildDefault() *regexp.Regexp

type PositionalModel

type PositionalModel struct {
	Binding      Binding
	IsSemantic   bool
	IsOptionPart bool
	IsOptionFlag bool
	// contains filtered or unexported fields
}

func (PositionalModel) Equal

func (posModel PositionalModel) Equal(comparedPosModel *PositionalModel) bool

func (PositionalModel) String

func (posModel PositionalModel) String() string

type ProgramInterfaceModel

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

A ProgramInterfaceModel describes the command line interface capabilities of a program.

func NewProgramInterfaceModel

func NewProgramInterfaceModel(optionScheme OptionScheme, optionDescriptions OptDescriptionModel) *ProgramInterfaceModel

Create a ProgramInterfaceModel

func (*ProgramInterfaceModel) DescriptionModel

func (pim *ProgramInterfaceModel) DescriptionModel() OptDescriptionModel

Return the OptDescriptionModel in nil-safe mode. An option description model is a set of option descriptions, which are composed of a description text field and a collection of match models. Each match model is related to an option expression Variant and has a one-or-two groups regular expression. When two groups can be matched, the latest is the option parameter of an explicit option assignments.

func (*ProgramInterfaceModel) Scheme

func (pim *ProgramInterfaceModel) Scheme() OptionScheme

Return the OptionScheme in nil-safe mode. An OptionScheme is a set of option expression variants supported by a program command line interface.

type SemanticTokenType

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

func NewSemanticTokenType

func NewSemanticTokenType(posModel *PositionalModel, name string, variant *OptExpressionVariant, style OptionStyle) *SemanticTokenType

func (*SemanticTokenType) Equal

func (tokenType *SemanticTokenType) Equal(comparedTType TokenType) bool

func (*SemanticTokenType) IsSemantic

func (tokenType *SemanticTokenType) IsSemantic() bool

func (*SemanticTokenType) Name

func (tokenType *SemanticTokenType) Name() string

func (*SemanticTokenType) PosModel

func (tokenType *SemanticTokenType) PosModel() *PositionalModel

func (*SemanticTokenType) String

func (tokenType *SemanticTokenType) String() string

func (*SemanticTokenType) Variant

func (tokenType *SemanticTokenType) Variant() *OptExpressionVariant

type Token

type Token struct {
	ArgumentPosition   int
	Ttype              TokenType
	Value              string
	BoundTo            *Token
	Tokens             TokenList
	SemanticCandidates []*SemanticTokenType
}

Token is a dynamic value which hold information about the underlying argument's semantics

func NewToken

func NewToken(argumentPosition int, ttype TokenType, value string, tokens TokenList) *Token

NewToken creates a new token. It ttype is context-free, its SemanticCandidates are assigned to a copy of ttype's candidates.

func (*Token) AttemptConvertToSemantic

func (token *Token) AttemptConvertToSemantic()

AttemptConvertToSemantic assign the only semantic type left in SemanticCandidates if its length is 1, do nothing otherwise. When such assignment happen, it will assign a bound value to its neighbour depending on its positional model.

func (*Token) InferLeft

func (token *Token) InferLeft()

InferLeft will update semantic candidates given its left-neighbour properties. If only one semantic candidate remains, the token's type will be assigned its value.

func (*Token) InferPositional

func (token *Token) InferPositional()

InferPositional will turn the last token to a SemOperand

func (*Token) InferRight

func (token *Token) InferRight()

InferRight will update semantic candidates given its right-neighbour properties. If only one semantic candidate remains, the token's type will be assigned its value.

func (*Token) IsBoundTo

func (token *Token) IsBoundTo(binding Binding) bool

IsBoundTo returns true if the current token is bound to the given binding.

func (*Token) IsBoundToOneOf

func (token *Token) IsBoundToOneOf(bindings Bindings) bool

IsBoundToOneOf returns true * when its positional model is unset, if all of its semantic candidates' bindings are contained in the given bindings slice. * when its positional model is not unset, if its positional model is contained in the provided bindings slice.

func (*Token) IsContextFree

func (token *Token) IsContextFree() bool

IsContextFree return true if this token's type is of type ContextFreeTokenType

func (*Token) IsOptionFlag

func (token *Token) IsOptionFlag() bool

IsOptionFlag returns true if * A (token Ttype positional model is Unset) : all its semantic candidates are option flags * B (token type positional model is not Unset) : token Ttype is an option flag

func (*Token) IsOptionPart

func (token *Token) IsOptionPart() bool

IsOptionPart returns true if * A (token Ttype positional model is Unset) : all its semantic candidates are option parts * B (token type positional model is not Unset) : token Ttype is an option part

func (*Token) IsSemantic

func (token *Token) IsSemantic() bool

IsSemantic return true if this token's type is of type SemanticTokenType

func (*Token) ReduceCandidates

func (token *Token) ReduceCandidates(pred CandidatePredicate)

ReduceCandidates restrict semantic candidates to those which don't satisfy the given CandidatePredicate

func (*Token) ReduceCandidatesWithScheme

func (token *Token) ReduceCandidatesWithScheme(scheme OptionScheme)

ReduceCandidatesWithScheme will restrict the set of token's semantic candidates to those which comply with the provided OptionScheme.

func (*Token) String

func (token *Token) String() string

type TokenList

type TokenList []*Token

TokenList is a list of tokens

func (TokenList) CheckEndOfOptions

func (tokens TokenList) CheckEndOfOptions()

CheckEndOfOptions will update token types for token met after an end-of-options token.

func (TokenList) MapToTypes

func (tokens TokenList) MapToTypes() []TokenType

MapToTypes returns a mapping of tokens' TokenTypes

func (TokenList) MatchOptionDescription

func (tokens TokenList) MatchOptionDescription(descriptionModel OptDescriptionModel)

MatchOptionDescription will update token types by matching each of them against the provided descriptionModel

func (TokenList) ReduceCandidatesWithScheme

func (tokens TokenList) ReduceCandidatesWithScheme(scheme OptionScheme)

ReduceCandidatesWithScheme will invoke Token#ReduceCandidatesWithScheme for each context-free token in the token list.

func (TokenList) When

func (tokens TokenList) When(predicate func(token *Token) bool) TokenList

When filter a token list with the given predicate and returns the filtered slice.

func (TokenList) WhenContextFree

func (tokens TokenList) WhenContextFree() TokenList

WhenContextFree filters the token lists retaining only those which are context-free.

type TokenType

type TokenType interface {
	PosModel() *PositionalModel
	IsSemantic() bool
	Name() string
	Equal(TokenType) bool
	Variant() *OptExpressionVariant
	fmt.Stringer
}

Jump to

Keyboard shortcuts

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