Documentation
¶
Overview ¶
Package compiler implements parsing, type checking and emitting of sources.
A program can be compiled using
CompileProgram
while a template is compiled through
CompileTemplate
Index ¶
- Variables
- func Disassemble(main *runtime.Function, globals []Global) (assembler map[string]string, err error)
- func DisassembleFunction(w io.Writer, fn *runtime.Function, globals []Global) (int64, error)
- func ParsePackageLessProgram(src io.Reader, loader PackageLoader, shebang bool) (*ast.Tree, error)
- func ParseProgram(packages PackageLoader) (*ast.Tree, error)
- func ParseSource(src []byte, isPackageLessProgram, shebang bool) (tree *ast.Tree, err error)
- func ParseTemplate(path string, reader FileReader, lang ast.Language, relaxedBoolean bool, ...) (*ast.Tree, error)
- func ParseTemplateSource(src []byte, lang ast.Language, relaxedBoolean bool) (tree *ast.Tree, err error)
- func ValidTemplatePath(path string) bool
- type CSSEnvStringer
- type CSSStringer
- type CheckingError
- type Code
- type Declarations
- type EnvStringer
- type FileReader
- type Global
- type HTMLEnvStringer
- type HTMLStringer
- type JavaScriptEnvStringer
- type JavaScriptStringer
- type LimitExceededError
- type Options
- type PackageLoader
- type SyntaxError
- type SyntaxType
- type UntypedBooleanConst
- type UntypedNumericConst
- type UntypedStringConst
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidPath is returned from the ParseTemplate function when the path // argument is not valid. ErrInvalidPath = errors.New("scriggo: invalid path") // ErrNotExist is returned from the ParseTemplate function when when the path // argument does not exist. ErrNotExist = errors.New("scriggo: path does not exist") )
Functions ¶
func Disassemble ¶
func DisassembleFunction ¶
func ParsePackageLessProgram ¶
ParsePackageLessProgram parses a package-less program reading its source from src and the imported packages form the loader. shebang reports whether the package-less program can have the shebang as first line.
func ParseProgram ¶
func ParseProgram(packages PackageLoader) (*ast.Tree, error)
ParseProgram parses a program reading its sources from loaders.
func ParseSource ¶
ParseSource parses a program or a package-less program and returns its tree. isPackageLessProgram reports whether it is a package-less program and shebang reports whether a package-less program can have the shebang as first line.
func ParseTemplate ¶
func ParseTemplate(path string, reader FileReader, lang ast.Language, relaxedBoolean bool, loader PackageLoader) (*ast.Tree, error)
ParseTemplate parses the template file with the given path and written in language lang, reading the template files from the reader. path, if not absolute, is relative to the root of the template. lang can be Text, HTML, CSS or JavaScript.
ParseTemplate expands the nodes Extends, Import and Include parsing the relative trees.
relaxedBoolean reports whether the operators 'and', 'or' and 'not' as well as non-boolean conditions in the if statement are allowed.
The parsed trees are cached so only one call per combination of path and context is made to the reader.
func ParseTemplateSource ¶
func ParseTemplateSource(src []byte, lang ast.Language, relaxedBoolean bool) (tree *ast.Tree, err error)
ParseTemplateSource parses a template with source src written in the language lang and returns its tree. language can be Text, HTML, CSS or JavaScript.
ParseTemplateSource does not expand the nodes Extends, Include and Import.
relaxedBoolean reports whether the operators 'and', 'or' and 'not' as well as non-boolean conditions in the if statement are allowed.
func ValidTemplatePath ¶
ValidTemplatePath indicates whether path is a valid template path.
Types ¶
type CSSEnvStringer ¶
These interfaces are like HTMLStringer, CSSStringer and JavaScriptStringer, but their method accepts a runtime.Env parameter that can be used inside the method's body to access some environment information.
type CSSStringer ¶
type CSSStringer interface{ CSS() string }
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
}
Code is the result of a package emitting process.
func CompileProgram ¶
CompileProgram compiles a program. Any error related to the compilation itself is returned as a CompilerError.
func CompileTemplate ¶
CompileTemplate compiles the template file with the given path and written in language lang. It reads the template files from the reader. path, if not absolute, is relative to the root of the template. lang can be Text, HTML, CSS or JavaScript. Any error related to the compilation itself is returned as a CompilerError.
type EnvStringer ¶
EnvStringer is like fmt.Stringer, but its method accepts a runtime.Env as parameter.
type FileReader ¶
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 HTMLEnvStringer ¶
These interfaces are like HTMLStringer, CSSStringer and JavaScriptStringer, but their method accepts a runtime.Env parameter that can be used inside the method's body to access some environment information.
type HTMLStringer ¶
type HTMLStringer interface{ HTML() string }
type JavaScriptEnvStringer ¶
These interfaces are like HTMLStringer, CSSStringer and JavaScriptStringer, but their method accepts a runtime.Env parameter that can be used inside the method's body to access some environment information.
type JavaScriptStringer ¶
type JavaScriptStringer interface{ JavaScript() string }
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
PackageLess bool
Builtins Declarations
// Loader loads Scriggo packages and precompiled packages.
//
// For template files, Loader only loads precompiled packages; the template
// files are read from the FileReader.
Loader PackageLoader
TemplateFailOnTODO bool
RelaxedBoolean bool
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 SyntaxType ¶
type SyntaxType int8
https://github.com/open2b/scriggo/issues/364
const ( // https://github.com/open2b/scriggo/issues/364 TemplateSyntax SyntaxType = iota + 1 ProgramSyntax )
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_cache.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. |
|
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. |