Documentation
¶
Overview ¶
Package compiler implements parsing, type checking and emitting of sources.
A program can be compiled using
BuildProgram
while a template is compiled through
BuildTemplate
Index ¶
- func Disassemble(main *runtime.Function, globals []Global, n int) map[string][]byte
- func DisassembleFunction(fn *runtime.Function, globals []Global, n int) []byte
- func ParseProgram(packages PackageLoader) (*ast.Tree, error)
- func ParseScript(src io.Reader, packages PackageLoader, shebang bool) (*ast.Tree, error)
- func ParseTemplate(fsys fs.FS, name string, packages PackageLoader) (*ast.Tree, error)
- func ParseTemplateSource(src []byte, format ast.Format, imported bool) (tree *ast.Tree, unexpanded []ast.Node, err error)
- func ValidTemplatePath(path string) bool
- type CheckingError
- type Code
- type CycleError
- type Declarations
- type FormatFS
- type Global
- type LimitExceededError
- type Options
- type PackageLoader
- type SyntaxError
- type UntypedBooleanConst
- type UntypedNumericConst
- type UntypedStringConst
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Disassemble ¶
Disassemble disassembles the main function fn with the given globals, returning the assembly code for each package. The returned map has a package path as key and its assembly as value.
n determines the maximum length, in runes, of the disassembled text in a Text instruction:
n > 0: at most n runes; leading and trailing white space are removed n == 0: no text n < 0: all text
func DisassembleFunction ¶
DisassembleFunction disassembles the function fn with the given globals.
n determines the maximum length, in runes, of the disassembled text in a Text instruction:
n > 0: at most n runes; leading and trailing white space are removed n == 0: no text n < 0: all text
func ParseProgram ¶
func ParseProgram(packages PackageLoader) (*ast.Tree, error)
ParseProgram parses a program reading its sources from loaders.
func ParseScript ¶ added in v0.29.0
ParseScript parses a script reading its source from src and the imported packages form the loader. shebang reports whether the script can have the shebang as first line.
func ParseTemplate ¶
ParseTemplate parses the named template file rooted at the given file system. If fsys implements FormatFS, the file format is read from its Format method, otherwise it depends on the extension of the file name. Any error related to the compilation itself is returned as a CompilerError.
ParseTemplate expands the nodes Extends, Import and Render parsing the relative trees.
func ParseTemplateSource ¶
func ParseTemplateSource(src []byte, format ast.Format, imported bool) (tree *ast.Tree, unexpanded []ast.Node, err error)
ParseTemplateSource parses a template with content src in the given format and returns its tree and the unexpanded Extends, Import, Render and Assignment nodes.
format can be Text, HTML, CSS, JavaScript, JSON and Markdown. imported indicates whether it is imported.
func ValidTemplatePath ¶
ValidTemplatePath indicates whether path is a valid template path. A valid template path is a valid file system path but "." is not valid and it can start with '/' or alternatively can start with one o more ".." elements.
Types ¶
type CheckingError ¶
type CheckingError struct {
// contains filtered or unexported fields
}
CheckingError records a type checking error with the path and the position where the error occurred.
func (*CheckingError) Error ¶
func (e *CheckingError) Error() string
Error returns a string representation of the type checking error.
func (*CheckingError) Message ¶
func (e *CheckingError) Message() string
Message returns the message of the type checking error, without position and path.
func (*CheckingError) Path ¶
func (e *CheckingError) Path() string
Path returns the path of the type checking error.
func (*CheckingError) Position ¶
func (e *CheckingError) Position() ast.Position
Position returns the position of the checking error.
type Code ¶
type Code struct {
// Globals is a slice of all globals used in Code.
Globals []Global
// Functions is a map of exported functions indexed by name.
Functions map[string]*runtime.Function
// Main is the Code entry point.
Main *runtime.Function
// Types allows to manipulate types, including new types defined in code.
Types runtime.Types
}
Code is the result of a package emitting process.
func BuildProgram ¶ added in v0.31.0
BuildProgram builds a program. Any error related to the compilation itself is returned as a CompilerError.
func BuildScript ¶ added in v0.31.0
BuildScript builds a script. Any error related to the compilation itself is returned as a CompilerError.
func BuildTemplate ¶ added in v0.31.0
BuildTemplate builds the named template file rooted at the given file system. If fsys implements FormatFS, the file format is read from its Format method, otherwise it depends on the extension of the file name. Any error related to the compilation itself is returned as a CompilerError.
type CycleError ¶ added in v0.18.0
type CycleError struct {
// contains filtered or unexported fields
}
CycleError implements an error indicating the presence of a cycle.
func (*CycleError) Error ¶ added in v0.18.0
func (e *CycleError) Error() string
func (*CycleError) Message ¶ added in v0.18.0
func (e *CycleError) Message() string
Message returns the message of cycle error, without position and path.
func (*CycleError) Path ¶ added in v0.18.0
func (e *CycleError) Path() string
Path returns the path of the first referenced file in the cycle.
func (*CycleError) Position ¶ added in v0.18.0
func (e *CycleError) Position() ast.Position
Position returns the position of the statements extends and import or the expression render referring the second file in the cycle.
type FormatFS ¶ added in v0.33.0
FormatFS is the interface implemented by a file system that can determine the file format from a path name.
type Global ¶
Global represents a global variable with a package, name, type (only for not predefined globals) and value (only for predefined globals). Value, if present, must be a pointer to the variable value.
type LimitExceededError ¶
type LimitExceededError struct {
// contains filtered or unexported fields
}
A LimitExceededError is an error returned by the compiler reporting that the compilation has exceeded a limit imposed by the implementation.
func (*LimitExceededError) Error ¶
func (e *LimitExceededError) Error() string
Error implements the interface error for the LimitError.
func (*LimitExceededError) Message ¶
func (e *LimitExceededError) Message() string
Message returns the error message of the LimitError.
func (*LimitExceededError) Path ¶
func (e *LimitExceededError) Path() string
Path returns the path of the source code that caused the LimitError.
func (*LimitExceededError) Position ¶
func (e *LimitExceededError) Position() ast.Position
Position returns the position of the function that caused the LimitError.
type Options ¶
type Options struct {
AllowShebangLine bool
DisallowGoStmt bool
FormatTypes map[ast.Format]reflect.Type
Globals Declarations
Renderer runtime.Renderer
// Packages loads Scriggo packages and precompiled packages.
//
// For template files, Packages only loads precompiled packages; the template
// files are read from a file system.
Packages PackageLoader
TreeTransformer func(*ast.Tree) error
}
Options represents a set of options used during the compilation.
type PackageLoader ¶
PackageLoader is implemented by package loaders. Load returns a predefined package as *Package or the source of a non predefined package as an io.Reader.
If the package does not exist it returns nil and nil. If the package exists but there was an error while loading the package, it returns nil and the error.
type SyntaxError ¶
type SyntaxError struct {
// contains filtered or unexported fields
}
SyntaxError records a parsing error with the path and the position where the error occurred.
func (*SyntaxError) Error ¶
func (e *SyntaxError) Error() string
Error returns a string representing the syntax error.
func (*SyntaxError) Message ¶
func (e *SyntaxError) Message() string
Message returns the message of the syntax error, without position and path.
func (*SyntaxError) Path ¶
func (e *SyntaxError) Path() string
Path returns the path of the syntax error.
func (*SyntaxError) Position ¶
func (e *SyntaxError) Position() ast.Position
Position returns the position of the syntax error.
type UntypedBooleanConst ¶
type UntypedBooleanConst bool
UntypedBooleanConst represents an untyped boolean constant.
type UntypedNumericConst ¶
type UntypedNumericConst string
UntypedNumericConst represents an untyped numeric constant.
type UntypedStringConst ¶
type UntypedStringConst string
UntypedStringConst represents an untyped string constant.
Source Files
¶
- builder.go
- builder_instructions.go
- checker.go
- checker_assignment.go
- checker_dependencies.go
- checker_expressions.go
- checker_obsolete_for_range_assignment.go
- checker_package.go
- checker_statements.go
- checker_util.go
- commented_error.go
- compilation.go
- compiler.go
- constant.go
- disassembler.go
- emitter.go
- emitter_assignment.go
- emitter_expressions.go
- emitter_func_store.go
- emitter_statements.go
- emitter_util.go
- emitter_var_store.go
- lexer.go
- limit_exceeded_error.go
- parser.go
- parser_expressions.go
- parser_func.go
- parser_program.go
- parser_switch.go
- parser_template.go
- path.go
- tokens.go
- typeinfo.go
Directories
¶
| Path | Synopsis |
|---|---|
|
Package ast declares the types used to define the template trees.
|
Package ast declares the types used to define the template trees. |
|
astutil
Package astutil implements methods to walk and dump a tree.
|
Package astutil implements methods to walk and dump a tree. |
|
internal
|
|
|
package types implements functions and types to represent and work with Scriggo types.
|
package types implements functions and types to represent and work with Scriggo types. |