parse

package
v0.0.0-...-6d0822f Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddLibraryToContainer

func AddLibraryToContainer(lib Library, container *vit.ComponentContainer)

func FormatError

func FormatError(err error) string

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 LexAll

func LexAll(input io.Reader, filePath vpath.Path) ([]token, error)

func NewLexer

func NewLexer(input io.Reader, filePath vpath.Path) *lexer

func NewLexerAtPosition

func NewLexerAtPosition(input io.Reader, position vit.Position) *lexer

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

func ParseGroupDefinition(code string, position vit.Position) ([]vit.PropertyDefinition, error)

ParseGroupDefinition can be used externally to parse a group definition.

func RegisterLibrary

func RegisterLibrary(name string, lib Library)

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

func (LexError) Error

func (e LexError) Error() string

func (LexError) Is

func (e LexError) Is(subject error) bool

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

func ResolveLibrary(namespace []string) (Library, error)

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

func (m *Manager) AddImportPath(dir fs.ReadDirFS) error

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

func (m *Manager) MainComponent() vit.Component

MainComponent returns the instantiated primary component

func (*Manager) SetSource

func (m *Manager) SetSource(filePath vpath.Path) error

SetSource sets the primary component that should be instantiated

func (*Manager) SetVariable

func (m *Manager) SetVariable(name string, value interface{}) error

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 ReadError

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

func (ReadError) Error

func (e ReadError) Error() string

func (ReadError) Is

func (e ReadError) Is(subject error) bool

func (ReadError) Unwrap

func (e ReadError) 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

Jump to

Keyboard shortcuts

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