Documentation
¶
Index ¶
- Constants
- Variables
- func ExecutePythonTemplate(pytemplate string, vars_map map[string]interface{}) (string, error)
- func FindIndex(arr []string, elem string) int
- func GetGroupNames(r string) ([]string, error)
- func GetNamedMatches(r *regexp.Regexp, s string) map[string]string
- func TrimRightSpace(str string) string
- type ON_RECORD_TYPE
- type ParserOutput
- func (t *ParserOutput) ParseTextReader(reader *strings.Reader, fsm TextFSM, eof bool) error
- func (t *ParserOutput) ParseTextScanner(scanner *bufio.Scanner, fsm TextFSM, eof bool) error
- func (t *ParserOutput) ParseTextString(text string, fsm TextFSM, eof bool) error
- func (t *ParserOutput) Reset(fsm TextFSM)
- type TextFSM
- type TextFSMRule
- type TextFSMState
- type TextFSMValue
Constants ¶
const MAX_NAME_LENG = 48
Variables ¶
var LINE_OPERATORS = []string{"Continue", "Next", "Error"}
var RECORD_OPERATORS = []string{"Clear", "Clearall", "Record", "NoRecord"}
Functions ¶
func ExecutePythonTemplate ¶
ExecutePythonTemplate converts a python template into a golang template and executes against the given variable map. This is a quick hack and not does not support all comprehensive list of Python Template package. It does the following:
- replace all ${varname} to {{.varname}}
- replace all $varname to {{.varname}} (By sorting the varnames with the longest name first)
- replace all $$ with $
- escape all literal {{ and }} with {{"{{"}} and {{"}}"}}
Assumes it is a valid python Template. No validations done to validate the python template syntax. Assumes all the variables are proper variable identifiers Then executes the resulting golang template on the map passed.
func GetGroupNames ¶
Given a regular expression with named groups ex. (?P<name>\w+)\s+(?P<age>\d+) Return the names e.g. ["name", "age"]
func TrimRightSpace ¶
Types ¶
type ON_RECORD_TYPE ¶
type ON_RECORD_TYPE int
const ( SKIP_RECORD ON_RECORD_TYPE = iota SKIP_VALUE CONTINUE )
type ParserOutput ¶
type ParserOutput struct {
Dict []map[string]interface{}
// contains filtered or unexported fields
}
Dict contains a slice of maps. Each element in the slice holds the value of a record. Each record is represented as map of (name,value)
Note that type of value is interface{}. But the concrete type is either 'string' or '[]string'
func (*ParserOutput) ParseTextReader ¶
func (*ParserOutput) ParseTextScanner ¶
func (*ParserOutput) ParseTextString ¶
func (t *ParserOutput) ParseTextString(text string, fsm TextFSM, eof bool) error
ParseTextString passes CLI output (provided as string) through FSM and
Args:
text: (string), Text to parse with embedded newlines.
fsm: (TextFSM), TextFSM object as a result of parsing the text fsm template
eof: (bool), Set to False if we are parsing only part of the file.
Suppresses triggering EOF state.
Returns:
error if there is any error in parsing
func (*ParserOutput) Reset ¶
func (t *ParserOutput) Reset(fsm TextFSM)
type TextFSM ¶
type TextFSM struct {
COMMENT_RE *regexp.Regexp
STATE_RE *regexp.Regexp
MAX_STATE_NAME_LEN int
Values map[string]TextFSMValue
States map[string]TextFSMState
// contains filtered or unexported fields
}
func (*TextFSM) ParseString ¶
Parses the string passed, into a TextFSM structure.
Args: input string: Valid template as a string. Retruns: error if there is any error. nil otherwise
type TextFSMRule ¶
type TextFSMRule struct {
Regex string
CompiledRegex *regexp.Regexp
Match string
LineOp string
RecordOp string
NewState string
LineNum int
}
func (*TextFSMRule) Parse ¶
func (r *TextFSMRule) Parse(line string, lineNum int, var_map map[string]interface{}) error
func (*TextFSMRule) String ¶
func (t *TextFSMRule) String() string
type TextFSMState ¶
type TextFSMState struct {
// contains filtered or unexported fields
}
type TextFSMValue ¶
type TextFSMValue struct {
Regex string
Template string
Name string
Options []string
// contains filtered or unexported fields
}
func (*TextFSMValue) String ¶
func (v *TextFSMValue) String() string
String() returns a string representation of the value