Documentation ¶
Overview ¶
The teflon package implements all the system functionalities of Teflon.
Unfortunately this document is polluted with struct fields and methods generated by `protoc` during compilation. Method names starting with `XXX` and `Get` belong to this category, please ignore them, as we don't use them and we are not able to document them by `godoc`. Real Teflon getters' names are identical to the field they are getting, without the 'Get' prefix, so look for them for information. Also note that the source is not polluted.
Please see the glossary (https://github.com/gradient-images/teflon/wiki/Glossary) for the exact definition of terms used throughout the source code.
Index ¶
- Constants
- Variables
- func Exist(fspath string) bool
- func IsDir(fspath string) bool
- func Isl(v interface{}) []interface{}
- func Parse(filename string, b []byte, opts ...Option) (interface{}, error)
- func ParseFile(filename string, opts ...Option) (i interface{}, err error)
- func ParseReader(filename string, r io.Reader, opts ...Option) (interface{}, error)
- func Path(target string) (string, error)
- func ShowAbs(fspath string) string
- type AbsPath
- type AddNode
- type AllMetaNode
- type Cloner
- type Context
- type DivNode
- type ENode
- type Event
- type EventType
- type ExactName
- type Expr
- type MetaNode
- type MulNode
- type MultiName
- type NumberNode
- type ONode
- type Option
- func AllowInvalidUTF8(b bool) Option
- func Debug(b bool) Option
- func Entrypoint(ruleName string) Option
- func GlobalStore(key string, value interface{}) Option
- func InitState(key string, value interface{}) Option
- func MaxExpressions(maxExprCnt uint64) Option
- func Memoize(b bool) Option
- func Recover(b bool) Option
- func Statistics(stats *Stats, choiceNoMatch string) Option
- type RelPath
- type Stats
- type StringNode
- type SubNode
- type TeflonObject
- func (o *TeflonObject) Children() (ch []*TeflonObject)
- func (o *TeflonObject) ChildrenNames() (ch []string)
- func (o *TeflonObject) CreateObject(exs string, file bool) (oSl []*TeflonObject, err error)
- func (o *TeflonObject) CreateShow(exs string, protoName string) (oSl []*TeflonObject, err error)
- func (o *TeflonObject) DelMeta(key string)
- func (o *TeflonObject) Get(exs string) (res interface{}, err error)
- func (o *TeflonObject) GetPath() string
- func (o *TeflonObject) IMap() map[string]interface{}
- func (o TeflonObject) MarshalJSON() ([]byte, error)
- func (o *TeflonObject) MetaFile() string
- func (o *TeflonObject) SetContractPattern(exs string, pat string) (oSl []*TeflonObject, err error)
- func (o *TeflonObject) SetMeta(key, value string)
- func (o *TeflonObject) SyncMeta() error
Constants ¶
const (
ShowProtoDirName = "show_proto"
)
Variables ¶
var Done chan bool = make(chan bool)
var Events chan Event = make(chan Event)
var Objects = map[string]*TeflonObject{}
Objects associates teflon object pointers to absolute file-system paths.
var Shows = []*TeflonObject{}
Shows are a list of all the show obejcts that the process knows about.
var TeflonConf string
Full path to the configuration directory, which stores configuration and show prototypes for the system. The teflon command gets its value from the $TEFLONCONF environment variable.
Functions ¶
func ParseReader ¶
ParseReader parses the data from r using filename as information in the error messages.
Types ¶
type AbsPath ¶
type AbsPath struct {
// contains filtered or unexported fields
}
func (*AbsPath) GenerateAll ¶
func (*AbsPath) NextMatch ¶
func (apn *AbsPath) NextMatch(o *TeflonObject) (res *TeflonObject)
type AddNode ¶
type AddNode struct {
// contains filtered or unexported fields
}
Adds numbers numberically and concatenate strings
type AllMetaNode ¶
type AllMetaNode struct{}
AllMetaNode returns all metadata of an object
func (*AllMetaNode) Eval ¶
func (amn *AllMetaNode) Eval(c *Context) (interface{}, error)
type Cloner ¶
type Cloner interface {
Clone() interface{}
}
Cloner is implemented by any value that has a Clone method, which returns a copy of the value. This is mainly used for types which are not passed by value (e.g map, slice, chan) or structs that contain such types.
This is used in conjunction with the global state feature to create proper copies of the state to allow the parser to properly restore the state in the case of backtracking.
type Context ¶
type Context struct { IMap map[string]interface{} Dir *TeflonObject }
String addressable version of the meta hierarchy.
type DivNode ¶
type DivNode struct {
// contains filtered or unexported fields
}
Adds numbers numberically and concatenate strings
type ENode ¶
ENode is the building block of the AST. The meta selector and the object selector both implemeted as a chain of ENodes, only the evaluation is different. The meta selector part is evaluated bottom up as traditional C-like expressions do, while the object selector part is evaluated top down as traditional globbing does.
type Event ¶
type Event struct { Object *TeflonObject Type EventType Result chan *TeflonObject }
type ExactName ¶
type ExactName struct {
// contains filtered or unexported fields
}
func (*ExactName) GenerateAll ¶
func (*ExactName) NextMatch ¶
func (enn *ExactName) NextMatch(o *TeflonObject) (res *TeflonObject)
type Expr ¶
type Expr struct { MetaSelector ENode ObjectSelector ONode // contains filtered or unexported fields }
Expr is an object representing a Teflon expression.
func (*Expr) Eval ¶
Evaluation starts with the object selector, since it provides the context for the meta selection.
type MetaNode ¶
type MetaNode struct {
NameList []string
}
MetaNode represents a metadata identifier
type MulNode ¶
type MulNode struct {
// contains filtered or unexported fields
}
Adds numbers numberically and concatenate strings
type MultiName ¶
type MultiName struct {
// contains filtered or unexported fields
}
func (*MultiName) GenerateAll ¶
func (*MultiName) NextMatch ¶
func (mnn *MultiName) NextMatch(o *TeflonObject) (res *TeflonObject)
type NumberNode ¶
type NumberNode struct {
Value float64
}
NumberNode represents a number literal
func (*NumberNode) Eval ¶
func (N *NumberNode) Eval(c *Context) (interface{}, error)
func (NumberNode) String ¶
func (N NumberNode) String() string
NumberNode needs to be Stringer for string concatenation
type ONode ¶
type ONode interface { // Match(string) bool NextMatch(*TeflonObject) *TeflonObject GenerateAll([]string) []string SetNext(*ONode) }
ONode must be implemented by object selector nodes.
type Option ¶
type Option func(*parser) Option
Option is a function that can set an option on the parser. It returns the previous setting as an Option.
func AllowInvalidUTF8 ¶
AllowInvalidUTF8 creates an Option to allow invalid UTF-8 bytes. Every invalid UTF-8 byte is treated as a utf8.RuneError (U+FFFD) by character class matchers and is matched by the any matcher. The returned matched value, c.text and c.offset are NOT affected.
The default is false.
func Debug ¶
Debug creates an Option to set the debug flag to b. When set to true, debugging information is printed to stdout while parsing.
The default is false.
func Entrypoint ¶
Entrypoint creates an Option to set the rule name to use as entrypoint. The rule name must have been specified in the -alternate-entrypoints if generating the parser with the -optimize-grammar flag, otherwise it may have been optimized out. Passing an empty string sets the entrypoint to the first rule in the grammar.
The default is to start parsing at the first rule in the grammar.
func GlobalStore ¶
GlobalStore creates an Option to set a key to a certain value in the globalStore.
func InitState ¶
InitState creates an Option to set a key to a certain value in the global "state" store.
func MaxExpressions ¶
MaxExpressions creates an Option to stop parsing after the provided number of expressions have been parsed, if the value is 0 then the parser will parse for as many steps as needed (possibly an infinite number).
The default for maxExprCnt is 0.
func Memoize ¶
Memoize creates an Option to set the memoize flag to b. When set to true, the parser will cache all results so each expression is evaluated only once. This guarantees linear parsing time even for pathological cases, at the expense of more memory and slower times for typical cases.
The default is false.
func Recover ¶
Recover creates an Option to set the recover flag to b. When set to true, this causes the parser to recover from panics and convert it to an error. Setting it to false can be useful while debugging to access the full stack trace.
The default is true.
func Statistics ¶
Statistics adds a user provided Stats struct to the parser to allow the user to process the results after the parsing has finished. Also the key for the "no match" counter is set.
Example usage:
input := "input" stats := Stats{} _, err := Parse("input-file", []byte(input), Statistics(&stats, "no match")) if err != nil { log.Panicln(err) } b, err := json.MarshalIndent(stats.ChoiceAltCnt, "", " ") if err != nil { log.Panicln(err) } fmt.Println(string(b))
type RelPath ¶
type RelPath struct {
// contains filtered or unexported fields
}
func (*RelPath) GenerateAll ¶
func (*RelPath) NextMatch ¶
func (rpn *RelPath) NextMatch(o *TeflonObject) (res *TeflonObject)
type Stats ¶
type Stats struct { // ExprCnt counts the number of expressions processed during parsing // This value is compared to the maximum number of expressions allowed // (set by the MaxExpressions option). ExprCnt uint64 // ChoiceAltCnt is used to count for each ordered choice expression, // which alternative is used how may times. // These numbers allow to optimize the order of the ordered choice expression // to increase the performance of the parser // // The outer key of ChoiceAltCnt is composed of the name of the rule as well // as the line and the column of the ordered choice. // The inner key of ChoiceAltCnt is the number (one-based) of the matching alternative. // For each alternative the number of matches are counted. If an ordered choice does not // match, a special counter is incremented. The name of this counter is set with // the parser option Statistics. // For an alternative to be included in ChoiceAltCnt, it has to match at least once. ChoiceAltCnt map[string]map[string]int }
Stats stores some statistics, gathered during parsing
type StringNode ¶
type StringNode struct {
Value string
}
StringNode represents a string literal
func (*StringNode) Eval ¶
func (S *StringNode) Eval(c *Context) (interface{}, error)
type SubNode ¶
type SubNode struct {
// contains filtered or unexported fields
}
Adds numbers numberically and concatenate strings
type TeflonObject ¶
type TeflonObject struct { Path string Show *TeflonObject FileInfo meta.FileInfo Parent *TeflonObject meta.PersistentMeta }
TeflonObject is the main type of teflon. All Teflon objects are represented by this struct in RAM.
func NewTeflonObject ¶
func NewTeflonObject(target string) (*TeflonObject, error)
NewTeflonObject creates a new initialized Teflon object in memory, that represents a file-system object.
Initialization is always complete. It is not allowed to have half-baked objects in memory. Since it has to set the Show field to its correct value it first has to find the show root of the target. This is done recursively by creating all the parent objects until and including the show root. This means that not only the created object is fully initialized but there will be a complete chain of objects leading from the target to the show root.
If the target is show-absolute then the system first has to find the show root from the current directory to get the file-system path of the target. This means that the end result is two initialized chains to the same show root.
func (*TeflonObject) Children ¶
func (o *TeflonObject) Children() (ch []*TeflonObject)
Children() returns the child objects of the object.
func (*TeflonObject) ChildrenNames ¶
func (o *TeflonObject) ChildrenNames() (ch []string)
ChildrenNames() returns a slice of strings with the names of the children of the object.
func (*TeflonObject) CreateObject ¶
func (o *TeflonObject) CreateObject(exs string, file bool) (oSl []*TeflonObject, err error)
CreateObject() creates a new FS object and triggers a new event.
func (*TeflonObject) CreateShow ¶
func (o *TeflonObject) CreateShow(exs string, protoName string) (oSl []*TeflonObject, err error)
CreateShow() creates new Teflon show.
func (*TeflonObject) DelMeta ¶
func (o *TeflonObject) DelMeta(key string)
Deletes an entry from the user section of the metadata.
func (*TeflonObject) Get ¶
func (o *TeflonObject) Get(exs string) (res interface{}, err error)
Get() evaluates a Teflon expression and returns the result.
func (*TeflonObject) GetPath ¶
func (o *TeflonObject) GetPath() string
Helper function to get empty string for nil objects during JSON marshaling.
func (*TeflonObject) IMap ¶
func (o *TeflonObject) IMap() map[string]interface{}
GetContext returns the Context of the object. Currently it is implemented as a marshal and unmarshal sequence to and from JSON. It is rather primitive and uneffective (slow), but it has the benefits of being extremely simple to implement and it forces us to be compliant with the JSON standard.
func (TeflonObject) MarshalJSON ¶
func (o TeflonObject) MarshalJSON() ([]byte, error)
Marshaling JSON manually to avoid recursion. There is probably a more elegant way of doing this.
func (*TeflonObject) MetaFile ¶
func (o *TeflonObject) MetaFile() string
MetaFile returns the file path to the TeflonObject's meta file. In the case of a file it is:
$DIR/.teflon/$FILE._
In the case of a directory it is:
$DIR/.teflon/_
func (*TeflonObject) SetContractPattern ¶
func (o *TeflonObject) SetContractPattern(exs string, pat string) (oSl []*TeflonObject, err error)
func (*TeflonObject) SetMeta ¶
func (o *TeflonObject) SetMeta(key, value string)
Sets an entry in the user section of the metadata.
func (*TeflonObject) SyncMeta ¶
func (o *TeflonObject) SyncMeta() error
SincMeta() writes metadata to disk.