parse

package
v0.0.0-...-17f8324 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2021 License: BSD-3-Clause, MPL-2.0 Imports: 11 Imported by: 4

Documentation

Overview

Copyright (c) 2019-2020, AT&T Intellectual Property. All rights reserved.

Copyright (c) 2014 by Brocade Communications Systems, Inc. All rights reserved.

Copyright 2011 The Go Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

SPDX-License-Identifier: MPL-2.0 and BSD-3-Clause

Index

Constants

This section is empty.

Variables

View Source
var ErrCard = errors.New("cardinality mismatch")
View Source
var ErrNoShadow = errors.New("cannot shadow")

Functions

func GetModules

func GetModules(trees map[string]*Tree) map[string]*Module

func GetModulesAndSubmodules

func GetModulesAndSubmodules(
	mods map[string]*Tree,
) (
	map[string]*Module,
	map[string]*Module,
)

Types

type AbsoluteSchemaArg

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

func (*AbsoluteSchemaArg) Parse

func (a *AbsoluteSchemaArg) Parse() error

func (*AbsoluteSchemaArg) Path

func (a *AbsoluteSchemaArg) Path() []xml.Name

func (AbsoluteSchemaArg) String

func (a AbsoluteSchemaArg) String() string

func (AbsoluteSchemaArg) Validate

func (a AbsoluteSchemaArg) Validate(s string) bool

type ArgInterner

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

func NewArgInterner

func NewArgInterner() *ArgInterner

func (*ArgInterner) Intern

func (i *ArgInterner) Intern(nodeType NodeType, arg Argument) Argument

type Argument

type Argument interface {
	String() string
	Parse() error
	Validate(string) bool
	// contains filtered or unexported methods
}

type BoolArg

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

func (*BoolArg) Parse

func (a *BoolArg) Parse() error

func (BoolArg) String

func (a BoolArg) String() string

func (BoolArg) Validate

func (a BoolArg) Validate(s string) bool

type Cardinality

type Cardinality struct {
	Start, End rune
}

type DataDef

type DataDef interface {
	Node
	// contains filtered or unexported methods
}

type DateArg

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

func (*DateArg) Parse

func (a *DateArg) Parse() error

func (DateArg) String

func (a DateArg) String() string

func (DateArg) Validate

func (a DateArg) Validate(s string) bool

type DescendantSchemaArg

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

func (*DescendantSchemaArg) Parse

func (a *DescendantSchemaArg) Parse() error

func (*DescendantSchemaArg) Path

func (a *DescendantSchemaArg) Path() []xml.Name

func (DescendantSchemaArg) String

func (a DescendantSchemaArg) String() string

func (DescendantSchemaArg) Validate

func (a DescendantSchemaArg) Validate(s string) bool

type DeviateArg

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

func (*DeviateArg) Parse

func (a *DeviateArg) Parse() error

func (DeviateArg) String

func (a DeviateArg) String() string

func (DeviateArg) Validate

func (a DeviateArg) Validate(s string) bool

type EmptyArg

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

func (EmptyArg) Parse

func (a EmptyArg) Parse() error

func (EmptyArg) String

func (a EmptyArg) String() string

func (EmptyArg) Validate

func (a EmptyArg) Validate(s string) bool

type FractionDigitsArg

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

func (*FractionDigitsArg) Parse

func (a *FractionDigitsArg) Parse() error

func (FractionDigitsArg) String

func (a FractionDigitsArg) String() string

func (FractionDigitsArg) Validate

func (a FractionDigitsArg) Validate(s string) bool

type GEnv

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

func NewGEnv

func NewGEnv(p *GEnv) *GEnv

func (*GEnv) Copy

func (e *GEnv) Copy() *GEnv

func (*GEnv) Get

func (e *GEnv) Get(s string) (Node, bool)

func (*GEnv) Put

func (e *GEnv) Put(s string, sym Node) error

func (*GEnv) String

func (e *GEnv) String() string

type HasArgument

type HasArgument interface {
	Argument() Argument
	ArgBool() bool
	ArgDate() string
	ArgDescendantSchema() []xml.Name
	ArgFractionDigits() int
	ArgIdRef() xml.Name
	ArgId() string
	ArgInt() int
	ArgKey() []string
	ArgLength() []Lb
	ArgMax() uint
	ArgOrdBy() string
	ArgPattern() *regexp.Regexp
	ArgPrefix() string
	ArgRange() RangeArgBdrySlice
	ArgSchema() []xml.Name
	ArgStatus() string
	ArgString() string
	ArgUint() uint
	ArgUnique() [][]xml.Name
	ArgUri() string
	ArgWhen() string
	ArgMust() string
	ArgPath() string
	// contains filtered or unexported methods
}

type IdArg

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

func (*IdArg) Parse

func (a *IdArg) Parse() error

* Parse an identifier, validating it as specified in * RFC 6020; Sec 12 "YANG ABNF Grammar" * * ;; An identifier MUST NOT start with (('X'|'x') ('M'|'m') ('L'|'l')) * identifier = (ALPHA / "_") * *(ALPHA / DIGIT / "_" / "-" / ".")

func (IdArg) String

func (a IdArg) String() string

func (IdArg) Validate

func (a IdArg) Validate(s string) bool

type IdRefArg

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

func (*IdRefArg) Parse

func (a *IdRefArg) Parse() error

func (IdRefArg) String

func (a IdRefArg) String() string

func (IdRefArg) Validate

func (a IdRefArg) Validate(s string) bool

type IntArg

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

func (*IntArg) Parse

func (a *IntArg) Parse() error

func (IntArg) String

func (a IntArg) String() string

func (IntArg) Validate

func (a IntArg) Validate(s string) bool

type KeyArg

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

func (*KeyArg) Parse

func (a *KeyArg) Parse() error

func (KeyArg) String

func (a KeyArg) String() string

func (KeyArg) Validate

func (a KeyArg) Validate(s string) bool

type Lb

type Lb struct {
	Min, Max   bool
	Start, End uint64
}

type LengthArg

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

func (*LengthArg) Parse

func (a *LengthArg) Parse() error

func (LengthArg) String

func (a LengthArg) String() string

func (LengthArg) Validate

func (a LengthArg) Validate(s string) bool

type MaxValueArg

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

func (*MaxValueArg) Parse

func (a *MaxValueArg) Parse() error

func (MaxValueArg) String

func (a MaxValueArg) String() string

func (MaxValueArg) Validate

func (a MaxValueArg) Validate(s string) bool

type Module

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

func (*Module) GetModule

func (m *Module) GetModule() Node

func (*Module) GetSubmodules

func (m *Module) GetSubmodules() map[string]Node

func (*Module) GetTree

func (m *Module) GetTree() *Tree

func (*Module) Imports

func (m *Module) Imports() (imports map[string]string)

func (*Module) Prefix

func (m *Module) Prefix() string

type Namespace

type Namespace interface {
	GetNodeNamespace(mod Node, modules map[string]*Module) string
	GetNodeModulename(mod Node) string
	GetNodeSubmoduleName() string
	GetModuleByPrefix(
		pfx string,
		modules map[string]*Module,
		skipUnknown bool,
	) (Node, error)
	YangPrefixToNamespace(
		prefix string,
		modules map[string]*Module,
		skipUnknown bool,
	) (string, error)
}

type Node

type Node interface {
	Type() NodeType
	Statement() string
	Name() string
	String() string
	Clone(m Node) Node

	HasArgument
	Namespace

	Root() Node
	UsesRoot() Node
	Children() []Node
	ChildrenByType(t NodeType) []Node
	ChildByType(t NodeType) Node
	LookupChild(t NodeType, name string) Node

	// Needed to merge in imports and includes
	AddChildren(new ...Node)
	ReplaceChild(old Node, new ...Node)
	ReplaceChildByType(typ NodeType, new Node)

	// 'when' statements added directly under 'augment' need special handling.
	// We store them on the children, but run 'as parent'.  As we add the
	// children before we parse the 'when' statement, we have to store the
	// knowledge on the node.  As we might want this for other purposes,
	// 'AddedByAugment()' seems a reasonable name.
	AddWhenChildren(fromAugment bool, new ...Node)
	AddedByAugment() bool
	NotSupported() bool
	MarkNotSupported()
	GetCardinalityEnd(t NodeType) rune

	//
	// (agj) TODO - Combine environment types
	//
	Tenv() *TEnv
	LookupType(string) (Node, bool)
	Genv() *GEnv
	LookupGrouping(string) (Node, bool)

	// This is where file and line numbers are stored
	ErrorContext() (location, context string)

	// Shortcuts for child values. Possibly not needed
	Min() uint
	Max() uint
	OrdBy() string
	Desc() string
	Ref() string
	Presence() bool
	Keys() []string
	Def() string
	HasDef() bool
	Config() bool
	HasConfig() bool
	Units() string
	Mandatory() bool
	FracDigit() int
	Msg() string
	Cmsg() string
	Value() int
	Revision() string
	Prefix() string
	Ns() string
	Path() string
	Status() string
	OnEnter() string
	Privileged() bool
	Local() bool
	Secret() bool
	PassOpcArgs() bool
	AppTag() string
	// contains filtered or unexported methods
}

func NewFakeNodeByType

func NewFakeNodeByType(extCard NodeCardinality, ntype NodeType, name string) Node

type NodeCardinality

type NodeCardinality func(NodeType) map[NodeType]Cardinality

type NodeType

type NodeType int
const (
	NodeUnknown NodeType = iota //Unknown node (yang extension)
	NodeModule
	NodeImport
	NodeInclude
	NodeRevision
	NodeSubmodule
	NodeBelongsTo
	NodeTypedef
	//Special purpose nodes according to RFC
	NodeDataDef
	NodeContainer
	NodeLeaf
	NodeLeafList
	NodeList
	NodeChoice
	NodeUses
	NodeAnyxml
	NodeCase
	NodeDataDefEnd
	//Additional node for augment data-def
	NodeGrouping
	NodeMust
	NodeRpc
	NodeInput
	NodeOutput
	NodeNotification
	NodeAugment
	NodeIdentity
	NodeExtension
	NodeArgument
	NodeFeature
	NodeDeviation
	NodeDeviate
	NodeDeviateAdd
	NodeDeviateDelete
	NodeDeviateReplace
	NodeDeviateNotSupported
	NodeDeviateEnd
	// Start of Type Restrictions
	NodeTypeRestrictionStart
	NodeTyp
	NodeRange
	NodeLength
	NodePattern
	NodeEnum
	NodeBit
	NodePath
	NodeFractionDigits
	NodeRequireInstance
	NodeTypeRestrictionEnd
	// End of Type Restrictions
	NodeContact
	NodeDescription
	NodeNamespace
	NodeOrganization
	NodePrefix
	NodeReference
	NodeYangVersion
	NodeRevisionDate
	NodeDefault
	NodeStatus
	NodeUnits
	NodeConfig
	NodeIfFeature
	NodePresence
	NodeWhen
	NodeErrorAppTag
	NodeErrorMessage
	NodeMandatory
	NodeMinElements
	NodeMaxElements
	NodeOrderedBy
	NodeKey
	NodeUnique
	NodeRefine
	NodeBase
	NodeYinElement
	NodeValue
	NodePosition
	NodeConfigdStart
	NodeConfigdHelp
	NodeConfigdValidate
	NodeConfigdNormalize
	NodeConfigdSyntax
	NodeConfigdPriority
	NodeConfigdAllowed
	NodeConfigdBegin
	NodeConfigdEnd
	NodeConfigdCreate
	NodeConfigdDelete
	NodeConfigdUpdate
	NodeConfigdSubst
	NodeConfigdSecret
	NodeConfigdErrMsg
	NodeConfigdPHelp
	NodeConfigdCallRpc
	NodeConfigdGetState
	NodeConfigdDeferActions
	NodeConfigdMust
	NodeConfigdStop
	NodeOpdDef
	NodeOpdArgument
	NodeOpdAugment
	NodeOpdCommand
	NodeOpdOption
	NodeOpdDefEnd
	NodeOpdInherit
	NodeOpdRepeatable
	NodeOpdPassOpcArgs
	NodeOpdPrivileged
	NodeOpdLocal
	NodeOpdSecret
	// OPD extensions which can extend non-opd nodes
	NodeOpdExtensionStart
	NodeOpdHelp
	NodeOpdAllowed
	NodeOpdOnEnter
	NodeOpdPatternHelp
	NodeOpdExtensionEnd
	NodeTypeIndexSize // MUST BE LAST. NOT A VALID NODE TYPE
)

func NodeTypeFromName

func NodeTypeFromName(name, arg string) NodeType

func (NodeType) IsConfigdNode

func (t NodeType) IsConfigdNode() bool

func (NodeType) IsDataNode

func (t NodeType) IsDataNode() bool

func (NodeType) IsDeviateNode

func (t NodeType) IsDeviateNode() bool

func (NodeType) IsExtensionNode

func (t NodeType) IsExtensionNode() bool

func (NodeType) IsOpdDefNode

func (t NodeType) IsOpdDefNode() bool

func (NodeType) IsOpdExtension

func (t NodeType) IsOpdExtension() bool

func (NodeType) IsTypeRestriction

func (t NodeType) IsTypeRestriction() bool

func (NodeType) String

func (t NodeType) String() string

func (NodeType) Type

func (t NodeType) Type() NodeType

type OrdByArg

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

func (*OrdByArg) Parse

func (a *OrdByArg) Parse() error

func (OrdByArg) String

func (a OrdByArg) String() string

func (OrdByArg) Validate

func (a OrdByArg) Validate(s string) bool

type PatternArg

type PatternArg struct {
	*regexp.Regexp
	// contains filtered or unexported fields
}

func (*PatternArg) Parse

func (a *PatternArg) Parse() error

Go's regexp engine doesn't anchor regexps to start and end of line, whereas YANG pattern statements use XSD regexps that do this implicitly. So, we need to explicitly anchor pattern regexps to get the correct behaviour. As these patterns may be branched (contain '|' (or)), we need to parenthesise the pattern before anchoring it.

func (*PatternArg) String

func (a *PatternArg) String() string

func (*PatternArg) Validate

func (a *PatternArg) Validate(s string) bool

type Pos

type Pos int

type PrefixArg

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

func (*PrefixArg) Parse

func (a *PrefixArg) Parse() error

func (PrefixArg) String

func (a PrefixArg) String() string

func (PrefixArg) Validate

func (a PrefixArg) Validate(s string) bool

type RangeArg

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

func (*RangeArg) Parse

func (a *RangeArg) Parse() error

func (RangeArg) String

func (a RangeArg) String() string

func (RangeArg) Validate

func (a RangeArg) Validate(s string) bool

type RangeArgBdrySlice

type RangeArgBdrySlice []argRb

type SchemaArg

type SchemaArg interface {
	Argument
	Path() []xml.Name
}

type Scope

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

func OpenScope

func OpenScope(p *Scope) *Scope

type StatusArg

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

func (*StatusArg) Parse

func (a *StatusArg) Parse() error

func (*StatusArg) String

func (a *StatusArg) String() string

func (StatusArg) Validate

func (a StatusArg) Validate(s string) bool

type StringArg

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

func (StringArg) Parse

func (a StringArg) Parse() error

func (StringArg) String

func (a StringArg) String() string

func (StringArg) Validate

func (a StringArg) Validate(s string) bool

type StringInterner

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

func NewStringInterner

func NewStringInterner() *StringInterner

func (*StringInterner) Intern

func (i *StringInterner) Intern(in string) string

type TEnv

type TEnv struct {
	// contains filtered or unexported fields
}
var BuiltinTenv *TEnv

func NewTEnv

func NewTEnv(p *TEnv) *TEnv

func (*TEnv) Copy

func (e *TEnv) Copy() *TEnv

func (*TEnv) Get

func (e *TEnv) Get(s string) (Node, bool)

func (*TEnv) Put

func (e *TEnv) Put(s string, sym Node) error

type Tree

type Tree struct {
	Root      Node // top-level root of the tree.
	ParseName string
	// contains filtered or unexported fields
}

Tree is the representation of a single parsed template.

func New

func New(name string, card NodeCardinality) *Tree

Parsing. New allocates a new parse tree with the given name.

func NewWithInterners

func NewWithInterners(
	name string,
	card NodeCardinality,
	stringInterner *StringInterner,
	argInterner *ArgInterner,
) *Tree

func Parse

func Parse(name, text string, extCard NodeCardinality) (*Tree, error)

func ParseWithInterners

func ParseWithInterners(
	name, text string,
	extCard NodeCardinality,
	stringInterner *StringInterner,
	argInterner *ArgInterner,
) (*Tree, error)

func (*Tree) ErrorContextPosition

func (t *Tree) ErrorContextPosition(pos int, ctx string) (location, context string)

func (*Tree) NewNode

func (tree *Tree) NewNode(id item, arg string, children []Node, s *Scope) Node

func (*Tree) Parse

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

func (*Tree) String

func (t *Tree) String() string

type TypeDef

type TypeDef interface {
	Node
	// contains filtered or unexported methods
}

type TypeRestriction

type TypeRestriction interface {
	Node
	// contains filtered or unexported methods
}

type UintArg

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

func (*UintArg) Parse

func (a *UintArg) Parse() error

func (UintArg) String

func (a UintArg) String() string

func (UintArg) Validate

func (a UintArg) Validate(s string) bool

type UniqueArg

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

func (*UniqueArg) Parse

func (a *UniqueArg) Parse() error

func (UniqueArg) String

func (a UniqueArg) String() string

func (UniqueArg) Validate

func (a UniqueArg) Validate(s string) bool

type UriArg

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

func (*UriArg) Parse

func (a *UriArg) Parse() error

func (UriArg) String

func (a UriArg) String() string

func (UriArg) Validate

func (a UriArg) Validate(s string) bool

type YangVersionArg

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

func (*YangVersionArg) Parse

func (a *YangVersionArg) Parse() error

func (YangVersionArg) String

func (a YangVersionArg) String() string

func (YangVersionArg) Validate

func (a YangVersionArg) Validate(s string) bool

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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