Documentation
¶
Overview ¶
Package file provides structs that represent the structure of a corgi file.
Package file provides an AST for corgi files.
Index ¶
- Variables
- type And
- type AndPlaceholder
- type ArrowBlock
- type Attribute
- type AttributeCollection
- type AttributeList
- type BadItem
- type Block
- type BlockExpansion
- type BlockType
- type Case
- type ChainExpression
- type ChainExpressionItem
- type ClassShorthand
- type Code
- type CodeLine
- type CommandFilter
- type CommandFilterArg
- type CorgiComment
- type CorgiCommentLine
- type CorgiInclude
- type DivShorthand
- type Doctype
- type DotIdentExpression
- type Element
- type ElementInterpolation
- type Else
- type ElseIf
- type ElseIfBlock
- type Expression
- type ExpressionInterpolationValue
- type ExpressionItem
- type Extend
- type File
- type Filter
- type FilterLine
- type For
- type Func
- type FuncParam
- type GoExpression
- type GoIdent
- type GoType
- type HTMLComment
- type HTMLCommentLine
- type IDShorthand
- type Ident
- type If
- type IfBlock
- type Import
- type ImportSpec
- type Include
- type IncludeFile
- type IndexExpression
- type InlineText
- type Interpolation
- type InterpolationValue
- type LibDependency
- type Library
- type LinkedMixin
- type Mixin
- type MixinArg
- type MixinBlockInfo
- type MixinCall
- type MixinCallAttribute
- type MixinCallInterpolation
- type MixinDependency
- type MixinInfo
- type MixinMainBlockShorthand
- type MixinParam
- type OtherInclude
- type ParenExpression
- type Poser
- type Position
- type PrecompiledCode
- type PrecompiledMixin
- type RangeExpression
- type RawCommandFilterArg
- type RawFilter
- type RawFilterType
- type Return
- type Scope
- type ScopeItem
- type SimpleAttribute
- type SimpleInterpolation
- type String
- type StringCommandFilterArg
- type StringExpression
- type StringExpressionInterpolation
- type StringExpressionItem
- type StringExpressionText
- type Switch
- type TernaryExpression
- type Text
- type TextInterpolationValue
- type TextItem
- type TextLine
- type Type
- type TypeAssertionExpression
- type Use
- type UseSpec
Constants ¶
This section is empty.
Variables ¶
var InvalidPosition = Position{0, 0}
Functions ¶
This section is empty.
Types ¶
type And ¶
type And struct { Attributes []AttributeCollection Position }
And represents an '&' expression.
type AndPlaceholder ¶
type AndPlaceholder struct {
Position
}
AndPlaceholder is an attribute 'named' `&` that is used as a placeholder for the attributes attached to a mixin call.
mixin foo() div: span(&) foo
It may only be used inside a mixin definition.
type ArrowBlock ¶
type AttributeCollection ¶
type AttributeCollection interface { Poser // contains filtered or unexported methods }
type AttributeList ¶
func (AttributeList) Pos ¶
func (l AttributeList) Pos() Position
type Block ¶
type Block struct { // Type is the type of block. Type BlockType // Name is the name of the block. Name Ident Body Scope Position }
Block represents a block with content. It is used for blocks from extendable templates as well as blocks in MixinCalls.
type BlockExpansion ¶
type Case ¶
type Case struct { // Expression is the expression written behind 'case'. // // Nil for the default case. Expression *Expression // Then is the scope of the code that is executed if the condition // evaluates to true. Then Scope Position }
type ChainExpression ¶
type ChainExpression struct { // Root is the root expression that is checked. Root GoExpression // CheckRoot specifies whether to check if the root is non-zero. CheckRoot bool // Chain is a list of GoExpression that yield the desired value. Chain []ChainExpressionItem // DerefCount is the number of leading *, used to dereference the chain // expression value DerefCount int // DefaultOpPos is the position of the '?!' operator. // // Only set, if Default is. DefaultOpPos *Position // Default represents the optional default value. Default *Expression // not a ChainExpression Position }
ChainExpression is an expression that checks if elements in the chain are not zero, and if indexes exist.
type ChainExpressionItem ¶
type ChainExpressionItem interface { Poser // contains filtered or unexported methods }
ChainExpressionItem represents an expression that can be chained.
It is either a IndexExpression, or a DotIdentExpression.
type ClassShorthand ¶
type CommandFilter ¶
type CommandFilter struct { Name string Args []CommandFilterArg Body []FilterLine Position }
type CommandFilterArg ¶
type CommandFilterArg interface { Poser // contains filtered or unexported methods }
type CorgiComment ¶
type CorgiComment struct { // Lines are the lines of the comment. // // Empty lines may be excluded. Lines []CorgiCommentLine Position }
CorgiComment represents a corgi comment, i.e. a comment that is not printed.
type CorgiCommentLine ¶
type CorgiInclude ¶
type CorgiInclude struct {
File *File
}
type DivShorthand ¶
type DivShorthand struct { // Attributes are the attributes of the element. // // It contains at least one item. // // Attributes[0] will be either of type ClassShorthand or IDShorthand. Attributes []AttributeCollection Body Scope Position }
type Doctype ¶
type Doctype struct {
Position
}
Doctype represents a doctype directive (`doctype html`).
type DotIdentExpression ¶
DotIdentExpression represents a dot followed by a Go identifier.
type Element ¶
type Element struct { Name string Attributes []AttributeCollection Void bool Body Scope Position }
Element represents a single HTML element.
type ElementInterpolation ¶
type ElementInterpolation struct { Element Element Value InterpolationValue // nil for void elems Position }
type ElseIf ¶
type ElseIf struct { // Condition is the condition of the else if statement. Condition Expression // Then is scope of the code that is executed if the condition evaluates // to true. Then Scope Position }
ElseIf represents an 'else if' statement.
type ElseIfBlock ¶
type Expression ¶
type Expression struct {
Expressions []ExpressionItem
}
Expression represents a chain of ExpressionItem elements.
func (Expression) Pos ¶
func (e Expression) Pos() Position
type ExpressionInterpolationValue ¶
type ExpressionInterpolationValue struct { LBracePos Position FormatDirective string // a Sprintf formatting placeholder, w/o preceding '%' Expression Expression RBracePos Position }
func (ExpressionInterpolationValue) Pos ¶
func (interp ExpressionInterpolationValue) Pos() Position
type ExpressionItem ¶
type ExpressionItem interface { Poser // contains filtered or unexported methods }
type File ¶
type File struct { Type Type // Name is the name of the file. // // If this is the main file, it will be just the file's name. // // If this is an extended, included, or used file, this will be the path // of the specified file in its source. Name string // Module is the path/name of the Go module providing this file. // // This won't be set for main and include files. Module string // PathInModule is the path to the file in the Go module, relative to the // module root. // // It is always specified as a forward slash separated path. // // This won't be set for main and include files. PathInModule string // AbsolutePath is the resolved absolute path to the file. // // It is specified using the system's separator. AbsolutePath string // Library is the library this file belongs to, if any. Library *Library // DirLibrary provides the library files located in the same directory as // this main, include, or template file. // // Not filled for library files. DirLibrary *Library // Raw contains the raw input file, as it was parsed. Raw string // Lines are the lines of Raw, stripped of their CRLF/LF line endings. Lines []string // TopLevelComments contains all comments made before the first scope item. TopLevelComments []CorgiComment // Extend is the file that this file extends, if any. Extend *Extend // Imports is a list of imports made by this file, in the order they // appear. Imports []Import // Uses is a list of used libraries, in the order they appear. Uses []Use // GlobalCode is the code that is written above the output function. GlobalCode []Code // Func is the function header. // It is always present for main files, i.e. those files that are given // to the corgi command. Func *Func // Scope is the global scope. Scope Scope }
File represents a parsed corgi file.
type FilterLine ¶
type For ¶
type For struct { // Expression is the expression written in the head of the for, or nil if // this is an infinite loop. Expression *Expression Body Scope Position }
For represents a for loop.
type Func ¶
type Func struct { // Name is the name of the function. Name GoIdent LParenPos Position Params []FuncParam RParenPos Position Position }
Func is the function header for the generated function.
type GoExpression ¶
GoExpression is a raw Go expression.
type HTMLComment ¶
type HTMLComment struct { Lines []HTMLCommentLine Position }
HTMLComment represents a comment.
type HTMLCommentLine ¶
type IDShorthand ¶
type If ¶
type If struct { // Condition is the condition of the if statement. Condition Expression // Then is scope of the code that is executed if the condition evaluates // to true. Then Scope // ElseIfs are the else if statements, if this If has any. ElseIfs []ElseIf // Else is the scope of the Else statement, if this If has one. Else *Else Position }
If represents an 'if' statement.
type IfBlock ¶
type IfBlock struct { // Name is the name of the block, whose existence is checked. Name Ident // Then is the scope of the code that is executed if the block exists. Then Scope // ElseIfs are the else if statements, if this IfBlock has any. ElseIfs []ElseIfBlock // Else is the scope of the code that is executed if the block does not // exist. Else *Else Position }
IfBlock represents an 'if block' directive.
type Import ¶
type Import struct { Imports []ImportSpec // Position is the position of the import keyword. // Hence, multiple imports may share the same position, if they are // grouped in a block. Position }
Import represents a single import.
type ImportSpec ¶
type Include ¶
type Include struct { // Path is the path to the file to include. Path String // Include is the included file. // It is populated by the linker. Include IncludeFile Position }
type IncludeFile ¶
type IncludeFile interface {
// contains filtered or unexported methods
}
IncludeFile is the type used to represent an included file.
Its concrete type is either a CorgiInclude or a OtherInclude.
type IndexExpression ¶
type IndexExpression struct { LBracePos Position Index Expression RBracePos Position CheckIndex bool CheckValue bool }
IndexExpression represents either a map or slice index expression.
func (IndexExpression) Pos ¶
func (e IndexExpression) Pos() Position
type InlineText ¶
type Interpolation ¶
type Interpolation interface { Poser // contains filtered or unexported methods }
type InterpolationValue ¶
type InterpolationValue interface { Poser // contains filtered or unexported methods }
type LibDependency ¶
type LibDependency struct { // Module is the path/name of the Go module providing this library. Module string // PathInModule is the path to the library in the Go module, relative to the // module root. // // It is always specified as a forward slash separated path. PathInModule string // Library is the linked library. Library *Library Mixins []MixinDependency }
type Library ¶
type Library struct { // Module is the path/name of the Go module providing this library. Module string // PathInModule is the path to the library in the Go module, relative to the // module root. // // It is always specified as a forward slash separated path. PathInModule string // AbsolutePath is the resolved absolute path to the library. // // It is specified using the system's separator. AbsolutePath string // Precompiled indicates whether this library was precompiled. // // If true, the files in this library will only have Type, Name, Module, // and PathInModule set. // // Additionally, Imports will be set, Precompiled bool // Files are the files this library consists of. // // If the library is precompiled, only Name, Module, PathInModule, and // Imports will be set. Files []*File Dependencies []LibDependency GlobalCode []PrecompiledCode Mixins []PrecompiledMixin }
type LinkedMixin ¶
type Mixin ¶
type Mixin struct { // Name is the name of the mixin. Name Ident LParenPos *Position // nil if params were omitted // Params is a list of the parameters of the mixin. Params []MixinParam RParenPos *Position // Body is the scope of the mixin. Body Scope // Precompiled is the precompiled function literal. // Its args start with the mixins args, followed by func()s for each of // the Blocks, and lastly, if HasAndPlaceholders is true, a final func() // called each time that the mixin's &s are supposed to be placed. // // It is only present, if this mixin was precompiled. Precompiled []byte *MixinInfo Position }
type MixinArg ¶
type MixinArg struct { // Name is the name of the argument. Name Ident // Value is the expression that yields the value of the argument. Value Expression Position }
MixinArg represents a single argument given to a mixin.
type MixinBlockInfo ¶
type MixinBlockInfo struct { Name string TopLevel bool // writes directly to the element it is called in // CanAttributes specifies whether &-directives can be used in this block. CanAttributes bool DefaultWritesBody bool DefaultWritesElements bool DefaultWritesTopLevelAttributes bool DefaultTopLevelAndPlaceholder bool }
type MixinCall ¶
type MixinCall struct { // Namespace is the namespace of the mixin, if any. Namespace *Ident // Name is the name of the mixin. Name Ident // Mixin is a pointer to the called mixin. // // It is set by the linker. Mixin *LinkedMixin LParenPos *Position // Args is a list of the arguments of given to the mixin. Args []MixinArg RParenPos *Position // Body is the body of the mixin call. // // It will only consist of If, IfBlock, Switch, And, and Block items. Body Scope Position }
MixinCall represents the call to a mixin.
type MixinCallAttribute ¶
type MixinCallAttribute struct { Name string AssignPos Position MixinCall MixinCall Value InterpolationValue Position }
type MixinCallInterpolation ¶
type MixinCallInterpolation struct { MixinCall MixinCall Value InterpolationValue // may be nil Position }
type MixinDependency ¶
type MixinInfo ¶
type MixinInfo struct { // WritesBody indicates whether the mixin writes to the body of an element. // Blocks including block defaults are ignored. WritesBody bool // WritesElements indicates whether the mixin writes elements. // // Only true, if WritesBody is as well. WritesElements bool // WritesTopLevelAttributes indicates whether the mixin writes any top-level // attributes, except &-placeholders. WritesTopLevelAttributes bool // TopLevelAndPlaceholder indicates whether the mixin has any top-level // &-placeholders. TopLevelAndPlaceholder bool // Blocks is are the blocks used in the mixin in the order they appear in, // and in the order they appear in the functions' signature. Blocks []MixinBlockInfo HasAndPlaceholders bool }
type MixinMainBlockShorthand ¶
type MixinParam ¶
type MixinParam struct { // Name is the name of the parameter. Name Ident // Type is the name of the type of the parameter, or nil if the type is // inferred from the default. Type *GoType // InferredType is the type inferred from the Default, if Type is nil. // // It will be set by package typeinfer before linking. // // An empty string indicates the type could not be inferred. InferredType string AssignPos *Position // Default is the optional default value of the parameter. Default *Expression // never a chain expression Position }
MixinParam represents a parameter of a mixin.
type OtherInclude ¶
type OtherInclude struct {
Contents string
}
OtherInclude represents an included file other than a Corgi file.
type ParenExpression ¶
type ParenExpression struct { LParenPos Position Args []Expression RParenPos Position // Check indicates whether to check the return value. Check bool }
ParenExpression represents a function call or the paren part of a type cast.
func (ParenExpression) Pos ¶
func (e ParenExpression) Pos() Position
type PrecompiledCode ¶
type PrecompiledMixin ¶
type PrecompiledMixin struct { // File is the file in which the mixin appears. File *File MachineComments []string // Mixin is the mixin itself. // // Its body is empty. Mixin Mixin // Var is the variable used by the depending mixins to call this mixin. Var string // RequiredBy are the names of the depending mixins. RequiredBy []string }
type RangeExpression ¶
type RangeExpression struct {
Var1, Var2 *GoIdent
EqPos Position // Position of the '=' or ':='
Declares bool // true if the range expression declares new variables (':=')
Ordered bool // true if the range expression is ordered ('= ordered range')
// RangeExpression is the expression that is being iterated over.
RangeExpression Expression
Position
}
RangeExpression represents a range expression as used for for-loops.
Hence, it is only present on for For items.
type RawCommandFilterArg ¶
type RawFilter ¶
type RawFilter struct { Type RawFilterType Body []FilterLine Position }
type RawFilterType ¶
type RawFilterType string
const ( RawHTML RawFilterType = "html" RawSVG RawFilterType = "svg" RawJS RawFilterType = "js" RawCSS RawFilterType = "css" )
type Return ¶
type Return struct { Err *Expression Position }
type Scope ¶
type Scope []ScopeItem
A Scope represents a level of indentation. Every mixin available inside a scope is also available in its child scopes.
type ScopeItem ¶
type ScopeItem interface { Poser // contains filtered or unexported methods }
ScopeItem represents an item in a scope.
type SimpleAttribute ¶
type SimpleAttribute struct { Name string AssignPos *Position // pos of '=' or '!='; nil for boolean attributes Value *Expression // nil for boolean attributes Position }
type SimpleInterpolation ¶
type SimpleInterpolation struct { NoEscape bool Value InterpolationValue Position }
type StringCommandFilterArg ¶
type StringCommandFilterArg String
type StringExpression ¶
type StringExpression struct { Quote byte // either " or ` Contents []StringExpressionItem // Position is the position of the quote. Position }
StringExpression represents a sequence of characters enclosed in double quotes or backticks.
type StringExpressionInterpolation ¶
type StringExpressionInterpolation struct { FormatDirective string // a Sprintf formatting placeholder, w/o preceding '%' Expression Expression LBracePos, RBracePos Position Position }
type StringExpressionItem ¶
type StringExpressionItem interface {
// contains filtered or unexported methods
}
type StringExpressionText ¶
type Switch ¶
type Switch struct { // Comparator is the expression that is compared against. // // It may be nil, in which case the cases will contain boolean // expressions. Comparator *Expression // Cases are the cases of the Switch. Cases []Case // Default is the default case, if there is one. Default *Case Position }
Switch represents a 'switch' statement.
type TernaryExpression ¶
type TernaryExpression struct { // Condition is the Expression yielding the condition that is being // evaluated. Condition Expression // not a ChainExpression // IfTrue is the Expression used if the condition is true. IfTrue Expression // not a ChainExpression // IfFalse is the Expression used if the condition is false. IfFalse Expression // not a ChainExpression RParenPos Position // LParenPos is Position.Col+1 Position }
TernaryExpression represents a ternary expression.
type TextInterpolationValue ¶
func (TextInterpolationValue) Pos ¶
func (interp TextInterpolationValue) Pos() Position
type TypeAssertionExpression ¶
type TypeAssertionExpression struct { PointerCount int Package *GoIdent Type GoIdent RParenPos Position // Check indicates whether to check if the assertion was successful. Check bool Position // of the dot }
TypeAssertionExpression represents a type assertion.
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
Package fileutil provides utilities for interacting with a corgi AST and its contents.
|
Package fileutil provides utilities for interacting with a corgi AST and its contents. |
Package precomp allows encoding and decoding of precompiled libraries.
|
Package precomp allows encoding and decoding of precompiled libraries. |