Documentation ¶
Index ¶
- func AddLibraryToContainer(lib Library, container *vit.ComponentContainer)
- func FormatError(err error) string
- func InstantiateComponent(def *vit.ComponentDefinition, fileCtx *vit.FileContext) (vit.Component, error)
- func LexAll(input io.Reader, filePath vpath.Path) ([]token, error)
- func NewLexer(input io.Reader, filePath vpath.Path) *lexer
- func NewLexerAtPosition(input io.Reader, position vit.Position) *lexer
- func NewTokenBuffer(source func() (token, error)) *tokenBuffer
- func ParseGroupDefinition(code string, position vit.Position) ([]vit.PropertyDefinition, error)
- func RegisterLibrary(name string, lib Library)
- type DocumentInstantiator
- type ImportStatement
- type LexError
- type Library
- type LibraryInstantiator
- type Manager
- func (m *Manager) AddImportPath(dir fs.ReadDirFS) error
- func (m *Manager) Initialize(environment vit.ExecutionEnvironment) error
- func (m *Manager) MainComponent() vit.Component
- func (m *Manager) SetSource(filePath vpath.Path) error
- func (m *Manager) SetVariable(name string, value interface{}) error
- func (m *Manager) UpdateFully() vit.ErrorGroup
- func (m *Manager) UpdateOnce() (int, vit.ErrorGroup)
- type ParseError
- type ReadError
- type VitDocument
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddLibraryToContainer ¶
func AddLibraryToContainer(lib Library, container *vit.ComponentContainer)
func FormatError ¶
FormatError takes an error that has been returned and formats it nicely for printing
func InstantiateComponent ¶
func InstantiateComponent(def *vit.ComponentDefinition, fileCtx *vit.FileContext) (vit.Component, error)
InstantiateComponent creates a component described by a componentDefinition.
func NewLexerAtPosition ¶
NewLexerAtPosition returns a new lexer that will already start at the given position. This can be used to improve error messages if a lexer only parses a small portion of a bigger file.
func NewTokenBuffer ¶
func NewTokenBuffer(source func() (token, error)) *tokenBuffer
func ParseGroupDefinition ¶
ParseGroupDefinition can be used externally to parse a group definition.
func RegisterLibrary ¶
Types ¶
type DocumentInstantiator ¶
type DocumentInstantiator struct {
// contains filtered or unexported fields
}
DocumentInstantiator implements the vit.AbstractComponent interface for a vit document.
func (*DocumentInstantiator) Instantiate ¶
func (i *DocumentInstantiator) Instantiate(id string, globalCtx *vit.GlobalContext) (vit.Component, error)
Instantiate this component with the given id. The componentContainer will be used to resolve components that are needed in the instantiation.
func (*DocumentInstantiator) Name ¶
func (i *DocumentInstantiator) Name() string
func (*DocumentInstantiator) ResolveVariable ¶
func (i *DocumentInstantiator) ResolveVariable(name string) (interface{}, bool)
ResolveVariable tries to find static attributes of the document's component. It implements the script.VariableSource interface.
type ImportStatement ¶
type ImportStatement struct { Namespace []string // fully qualified name of the module to import File string // file path that should be imported Version string // version string for namespace imports Qualifier string // optional qualifier that allows the user to refer to the import by a different name Position vit.PositionRange }
An ImportStatement can either import a module/namespace or a file namespaces have a version with major and minor part. Either namespace or file can be set, but not both.
func (ImportStatement) String ¶
func (s ImportStatement) String() string
String returns a human readable multiline string representation of the import
type LexError ¶
type LexError struct {
// contains filtered or unexported fields
}
LexError contains additional information about the error that occurred
type Library ¶
type Library interface { ComponentNames() []string NewComponent(string, string, *vit.GlobalContext) (vit.Component, bool) StaticAttribute(string, string) (interface{}, bool) }
A Library describes defines one or more components that can be used in other files
func ResolveLibrary ¶
ResolveLibrary takes a library identifier and returns the corresponding library or an error if the identifier is unknown. Currently this is hardcoded but should be made dynamic in the future.
type LibraryInstantiator ¶
type LibraryInstantiator struct {
// contains filtered or unexported fields
}
LibraryInstantiator implements the vit.AbstractComponent interface for a specific component defined in a vit library.
func (*LibraryInstantiator) Instantiate ¶
func (i *LibraryInstantiator) Instantiate(id string, globalCtx *vit.GlobalContext) (vit.Component, error)
Instantiate this component with the given id. The componentContainer will be used to resolve components that are needed in the instantiation.
func (*LibraryInstantiator) Name ¶
func (i *LibraryInstantiator) Name() string
func (*LibraryInstantiator) ResolveVariable ¶
func (i *LibraryInstantiator) ResolveVariable(name string) (interface{}, bool)
ResolveVariable tries to find static attributes of the libraries component.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
The Manager handles everything about loading files and instantiating them into a working component tree
func NewManager ¶
func NewManager() *Manager
func (*Manager) AddImportPath ¶
AddImportPath adds a folder to the list of folders to search for components
func (*Manager) Initialize ¶
func (m *Manager) Initialize(environment vit.ExecutionEnvironment) error
Initialize instantiates the primary component and reports any errors in doing so
func (*Manager) MainComponent ¶
MainComponent returns the instantiated primary component
func (*Manager) SetVariable ¶
func (*Manager) UpdateFully ¶
func (m *Manager) UpdateFully() vit.ErrorGroup
UpdateFully reevaluates all expressions whose dependencies have changed since the last update in a loop until no outstanding changes are left.
func (*Manager) UpdateOnce ¶
func (m *Manager) UpdateOnce() (int, vit.ErrorGroup)
UpdateOnce reevaluates all expressions whose dependencies have changed since the last update.
type ParseError ¶
type ParseError struct {
// contains filtered or unexported fields
}
ParseError describes an error that occurred during parsing. Tt contains the position in the file where the error occurred
func (ParseError) Error ¶
func (e ParseError) Error() string
func (ParseError) Is ¶
func (e ParseError) Is(subject error) bool
func (ParseError) Report ¶
func (e ParseError) Report() string
func (ParseError) Unwrap ¶
func (e ParseError) Unwrap() error
type VitDocument ¶
type VitDocument struct { Name string // Name of the file without extension. Usually the name of the component this file describes. Imports []ImportStatement // all imported libraries and files Components []*vit.ComponentDefinition }
VitDocument contains everything there is to know about a parsed vit file
func Parse ¶
func Parse(tokens *tokenBuffer) (file *VitDocument, err error)
Parse takes a tokenBuffer from a single vit file and returns a parsed document. The returned error will always be of type LexError, ReadError or ParseError.
func (VitDocument) String ¶
func (d VitDocument) String() string
String creates a human readable string representation of the vit document