Documentation
¶
Overview ¶
The semantic package provides a graph structure that represents the meaning of a Flux script. An AST is converted into a semantic graph for use with other systems. Using a semantic graph representation of the Flux, enables highlevel meaning to be specified programatically.
The semantic structures are to be designed to facilitate the interpretation and compilation of Flux.
For example since Flux uses the javascript AST structures, arguments to a function are represented as a single positional argument that is always an object expression. The semantic graph validates that the AST correctly follows these semantics, and use structures that are strongly typed for this expectation.
Index ¶
- Variables
- func ApplyNewDeclarations(n Node, declarations map[string]VariableDeclaration)
- func SolveTypes(n Node, declarations DeclarationScope)
- func Walk(v Visitor, node Node)
- type ArrayExpression
- type BinaryExpression
- type BlockStatement
- type BooleanLiteral
- type CallExpression
- type ConditionalExpression
- type DateTimeLiteral
- type DeclarationScope
- type DurationLiteral
- type Expression
- type ExpressionStatement
- type ExternalVariableDeclaration
- type FloatLiteral
- type FunctionExpression
- type FunctionParam
- type FunctionSignature
- type Identifier
- type IdentifierExpression
- type IntegerLiteral
- type Kind
- type Literal
- type LogicalExpression
- type MemberExpression
- type NativeVariableDeclaration
- func (s *NativeVariableDeclaration) Copy() Node
- func (d *NativeVariableDeclaration) ID() *Identifier
- func (d *NativeVariableDeclaration) InitType() Type
- func (d *NativeVariableDeclaration) MarshalJSON() ([]byte, error)
- func (*NativeVariableDeclaration) NodeType() string
- func (d *NativeVariableDeclaration) UnmarshalJSON(data []byte) error
- type Node
- type ObjectExpression
- type OptionStatement
- type Program
- type Property
- type RegexpLiteral
- type ReturnStatement
- type Statement
- type StringLiteral
- type Type
- type UnaryExpression
- type UnsignedIntegerLiteral
- type VariableDeclaration
- type Visitor
Constants ¶
This section is empty.
Variables ¶
var EmptyArrayType = NewArrayType(Nil)
var EmptyObject = NewObjectType(nil)
Functions ¶
func ApplyNewDeclarations ¶
func ApplyNewDeclarations(n Node, declarations map[string]VariableDeclaration)
func SolveTypes ¶
func SolveTypes(n Node, declarations DeclarationScope)
SolveTypes inspects the expression and ensures that all sub expressions konw their type
Types ¶
type ArrayExpression ¶
type ArrayExpression struct {
Elements []Expression `json:"elements"`
// contains filtered or unexported fields
}
func (*ArrayExpression) Copy ¶
func (e *ArrayExpression) Copy() Node
func (*ArrayExpression) MarshalJSON ¶
func (e *ArrayExpression) MarshalJSON() ([]byte, error)
func (*ArrayExpression) NodeType ¶
func (*ArrayExpression) NodeType() string
func (*ArrayExpression) Type ¶
func (e *ArrayExpression) Type() Type
func (*ArrayExpression) UnmarshalJSON ¶
func (e *ArrayExpression) UnmarshalJSON(data []byte) error
type BinaryExpression ¶
type BinaryExpression struct {
Operator ast.OperatorKind `json:"operator"`
Left Expression `json:"left"`
Right Expression `json:"right"`
}
func (*BinaryExpression) Copy ¶
func (e *BinaryExpression) Copy() Node
func (*BinaryExpression) MarshalJSON ¶
func (e *BinaryExpression) MarshalJSON() ([]byte, error)
func (*BinaryExpression) NodeType ¶
func (*BinaryExpression) NodeType() string
func (*BinaryExpression) Type ¶
func (e *BinaryExpression) Type() Type
func (*BinaryExpression) UnmarshalJSON ¶
func (e *BinaryExpression) UnmarshalJSON(data []byte) error
type BlockStatement ¶
type BlockStatement struct {
Body []Statement `json:"body"`
}
func (*BlockStatement) Copy ¶
func (s *BlockStatement) Copy() Node
func (*BlockStatement) MarshalJSON ¶
func (s *BlockStatement) MarshalJSON() ([]byte, error)
func (*BlockStatement) NodeType ¶
func (*BlockStatement) NodeType() string
func (*BlockStatement) ReturnStatement ¶
func (s *BlockStatement) ReturnStatement() *ReturnStatement
func (*BlockStatement) UnmarshalJSON ¶
func (s *BlockStatement) UnmarshalJSON(data []byte) error
type BooleanLiteral ¶
type BooleanLiteral struct {
Value bool `json:"value"`
}
func (*BooleanLiteral) Copy ¶
func (l *BooleanLiteral) Copy() Node
func (*BooleanLiteral) MarshalJSON ¶
func (l *BooleanLiteral) MarshalJSON() ([]byte, error)
func (*BooleanLiteral) NodeType ¶
func (*BooleanLiteral) NodeType() string
func (*BooleanLiteral) Type ¶
func (*BooleanLiteral) Type() Type
type CallExpression ¶
type CallExpression struct {
Callee Expression `json:"callee"`
Arguments *ObjectExpression `json:"arguments"`
}
func (*CallExpression) Copy ¶
func (e *CallExpression) Copy() Node
func (*CallExpression) MarshalJSON ¶
func (e *CallExpression) MarshalJSON() ([]byte, error)
func (*CallExpression) NodeType ¶
func (*CallExpression) NodeType() string
func (*CallExpression) Type ¶
func (e *CallExpression) Type() Type
func (*CallExpression) UnmarshalJSON ¶
func (e *CallExpression) UnmarshalJSON(data []byte) error
type ConditionalExpression ¶
type ConditionalExpression struct {
Test Expression `json:"test"`
Alternate Expression `json:"alternate"`
Consequent Expression `json:"consequent"`
}
func (*ConditionalExpression) Copy ¶
func (e *ConditionalExpression) Copy() Node
func (*ConditionalExpression) MarshalJSON ¶
func (e *ConditionalExpression) MarshalJSON() ([]byte, error)
func (*ConditionalExpression) NodeType ¶
func (*ConditionalExpression) NodeType() string
func (*ConditionalExpression) UnmarshalJSON ¶
func (e *ConditionalExpression) UnmarshalJSON(data []byte) error
type DateTimeLiteral ¶
func (*DateTimeLiteral) Copy ¶
func (l *DateTimeLiteral) Copy() Node
func (*DateTimeLiteral) MarshalJSON ¶
func (l *DateTimeLiteral) MarshalJSON() ([]byte, error)
func (*DateTimeLiteral) NodeType ¶
func (*DateTimeLiteral) NodeType() string
func (*DateTimeLiteral) Type ¶
func (*DateTimeLiteral) Type() Type
type DeclarationScope ¶
type DeclarationScope map[string]VariableDeclaration
func (DeclarationScope) Copy ¶
func (s DeclarationScope) Copy() DeclarationScope
type DurationLiteral ¶
func (*DurationLiteral) Copy ¶
func (l *DurationLiteral) Copy() Node
func (*DurationLiteral) MarshalJSON ¶
func (l *DurationLiteral) MarshalJSON() ([]byte, error)
func (*DurationLiteral) NodeType ¶
func (*DurationLiteral) NodeType() string
func (*DurationLiteral) Type ¶
func (*DurationLiteral) Type() Type
func (*DurationLiteral) UnmarshalJSON ¶
func (l *DurationLiteral) UnmarshalJSON(data []byte) error
type Expression ¶
type ExpressionStatement ¶
type ExpressionStatement struct {
Expression Expression `json:"expression"`
}
func (*ExpressionStatement) Copy ¶
func (s *ExpressionStatement) Copy() Node
func (*ExpressionStatement) MarshalJSON ¶
func (s *ExpressionStatement) MarshalJSON() ([]byte, error)
func (*ExpressionStatement) NodeType ¶
func (*ExpressionStatement) NodeType() string
func (*ExpressionStatement) UnmarshalJSON ¶
func (s *ExpressionStatement) UnmarshalJSON(data []byte) error
type ExternalVariableDeclaration ¶
type ExternalVariableDeclaration struct {
Identifier *Identifier `json:"identifier"`
Type Type `json:"type"`
}
func NewExternalVariableDeclaration ¶
func NewExternalVariableDeclaration(name string, typ Type) *ExternalVariableDeclaration
func (*ExternalVariableDeclaration) Copy ¶
func (s *ExternalVariableDeclaration) Copy() Node
func (*ExternalVariableDeclaration) ID ¶
func (d *ExternalVariableDeclaration) ID() *Identifier
func (*ExternalVariableDeclaration) InitType ¶
func (d *ExternalVariableDeclaration) InitType() Type
func (*ExternalVariableDeclaration) MarshalJSON ¶
func (d *ExternalVariableDeclaration) MarshalJSON() ([]byte, error)
func (*ExternalVariableDeclaration) NodeType ¶
func (*ExternalVariableDeclaration) NodeType() string
type FloatLiteral ¶
type FloatLiteral struct {
Value float64 `json:"value"`
}
func (*FloatLiteral) Copy ¶
func (l *FloatLiteral) Copy() Node
func (*FloatLiteral) MarshalJSON ¶
func (l *FloatLiteral) MarshalJSON() ([]byte, error)
func (*FloatLiteral) NodeType ¶
func (*FloatLiteral) NodeType() string
func (*FloatLiteral) Type ¶
func (*FloatLiteral) Type() Type
type FunctionExpression ¶
type FunctionExpression struct {
Params []*FunctionParam `json:"params"`
Body Node `json:"body"`
// contains filtered or unexported fields
}
func (*FunctionExpression) Copy ¶
func (e *FunctionExpression) Copy() Node
func (*FunctionExpression) MarshalJSON ¶
func (e *FunctionExpression) MarshalJSON() ([]byte, error)
func (*FunctionExpression) NodeType ¶
func (*FunctionExpression) NodeType() string
func (*FunctionExpression) Type ¶
func (e *FunctionExpression) Type() Type
func (*FunctionExpression) UnmarshalJSON ¶
func (e *FunctionExpression) UnmarshalJSON(data []byte) error
type FunctionParam ¶
type FunctionParam struct {
Key *Identifier `json:"key"`
Default Expression `json:"default"`
Piped bool `json:"piped,omitempty"`
// contains filtered or unexported fields
}
func (*FunctionParam) Copy ¶
func (p *FunctionParam) Copy() Node
func (*FunctionParam) MarshalJSON ¶
func (e *FunctionParam) MarshalJSON() ([]byte, error)
func (*FunctionParam) NodeType ¶
func (*FunctionParam) NodeType() string
func (*FunctionParam) Type ¶
func (f *FunctionParam) Type() Type
func (*FunctionParam) UnmarshalJSON ¶
func (e *FunctionParam) UnmarshalJSON(data []byte) error
type FunctionSignature ¶
type Identifier ¶
type Identifier struct {
Name string `json:"name"`
}
func (*Identifier) Copy ¶
func (i *Identifier) Copy() Node
func (*Identifier) MarshalJSON ¶
func (i *Identifier) MarshalJSON() ([]byte, error)
func (*Identifier) NodeType ¶
func (*Identifier) NodeType() string
type IdentifierExpression ¶
type IdentifierExpression struct {
Name string `json:"name"`
// contains filtered or unexported fields
}
func (*IdentifierExpression) Copy ¶
func (e *IdentifierExpression) Copy() Node
func (*IdentifierExpression) MarshalJSON ¶
func (e *IdentifierExpression) MarshalJSON() ([]byte, error)
func (*IdentifierExpression) NodeType ¶
func (*IdentifierExpression) NodeType() string
func (*IdentifierExpression) Type ¶
func (e *IdentifierExpression) Type() Type
type IntegerLiteral ¶
type IntegerLiteral struct {
Value int64 `json:"value"`
}
func (*IntegerLiteral) Copy ¶
func (l *IntegerLiteral) Copy() Node
func (*IntegerLiteral) MarshalJSON ¶
func (l *IntegerLiteral) MarshalJSON() ([]byte, error)
func (*IntegerLiteral) NodeType ¶
func (*IntegerLiteral) NodeType() string
func (*IntegerLiteral) Type ¶
func (*IntegerLiteral) Type() Type
func (*IntegerLiteral) UnmarshalJSON ¶
func (l *IntegerLiteral) UnmarshalJSON(data []byte) error
type Kind ¶
type Kind int
func (Kind) ElementType ¶
func (Kind) PipeArgument ¶
func (Kind) Properties ¶
func (Kind) PropertyType ¶
func (Kind) ReturnType ¶
type Literal ¶
type Literal interface {
Expression
// contains filtered or unexported methods
}
type LogicalExpression ¶
type LogicalExpression struct {
Operator ast.LogicalOperatorKind `json:"operator"`
Left Expression `json:"left"`
Right Expression `json:"right"`
}
func (*LogicalExpression) Copy ¶
func (e *LogicalExpression) Copy() Node
func (*LogicalExpression) MarshalJSON ¶
func (e *LogicalExpression) MarshalJSON() ([]byte, error)
func (*LogicalExpression) NodeType ¶
func (*LogicalExpression) NodeType() string
func (*LogicalExpression) Type ¶
func (*LogicalExpression) Type() Type
func (*LogicalExpression) UnmarshalJSON ¶
func (e *LogicalExpression) UnmarshalJSON(data []byte) error
type MemberExpression ¶
type MemberExpression struct {
Object Expression `json:"object"`
Property string `json:"property"`
}
func (*MemberExpression) Copy ¶
func (e *MemberExpression) Copy() Node
func (*MemberExpression) MarshalJSON ¶
func (e *MemberExpression) MarshalJSON() ([]byte, error)
func (*MemberExpression) NodeType ¶
func (*MemberExpression) NodeType() string
func (*MemberExpression) Type ¶
func (e *MemberExpression) Type() Type
func (*MemberExpression) UnmarshalJSON ¶
func (e *MemberExpression) UnmarshalJSON(data []byte) error
type NativeVariableDeclaration ¶
type NativeVariableDeclaration struct {
Identifier *Identifier `json:"identifier"`
Init Expression `json:"init"`
}
func (*NativeVariableDeclaration) Copy ¶
func (s *NativeVariableDeclaration) Copy() Node
func (*NativeVariableDeclaration) ID ¶
func (d *NativeVariableDeclaration) ID() *Identifier
func (*NativeVariableDeclaration) InitType ¶
func (d *NativeVariableDeclaration) InitType() Type
func (*NativeVariableDeclaration) MarshalJSON ¶
func (d *NativeVariableDeclaration) MarshalJSON() ([]byte, error)
func (*NativeVariableDeclaration) NodeType ¶
func (*NativeVariableDeclaration) NodeType() string
func (*NativeVariableDeclaration) UnmarshalJSON ¶
func (d *NativeVariableDeclaration) UnmarshalJSON(data []byte) error
type Node ¶
type Node interface {
NodeType() string
Copy() Node
json.Marshaler
// contains filtered or unexported methods
}
func UnmarshalNode ¶
type ObjectExpression ¶
type ObjectExpression struct {
Properties []*Property `json:"properties"`
// contains filtered or unexported fields
}
func (*ObjectExpression) Copy ¶
func (e *ObjectExpression) Copy() Node
func (*ObjectExpression) MarshalJSON ¶
func (e *ObjectExpression) MarshalJSON() ([]byte, error)
func (*ObjectExpression) NodeType ¶
func (*ObjectExpression) NodeType() string
func (*ObjectExpression) Type ¶
func (e *ObjectExpression) Type() Type
type OptionStatement ¶
type OptionStatement struct {
Declaration VariableDeclaration `json:"declaration"`
}
func (*OptionStatement) Copy ¶
func (s *OptionStatement) Copy() Node
func (*OptionStatement) MarshalJSON ¶
func (s *OptionStatement) MarshalJSON() ([]byte, error)
func (*OptionStatement) NodeType ¶
func (s *OptionStatement) NodeType() string
func (*OptionStatement) UnmarshalJSON ¶
func (s *OptionStatement) UnmarshalJSON(data []byte) error
type Program ¶
type Program struct {
Body []Statement `json:"body"`
}
func New ¶
New creates a semantic graph from the provided AST and builtin declarations The declarations will be modified for any variable declaration found in the program.
func (*Program) MarshalJSON ¶
func (*Program) UnmarshalJSON ¶
type Property ¶
type Property struct {
Key *Identifier `json:"key"`
Value Expression `json:"value"`
}
func (*Property) MarshalJSON ¶
func (*Property) UnmarshalJSON ¶
type RegexpLiteral ¶
func (*RegexpLiteral) Copy ¶
func (l *RegexpLiteral) Copy() Node
func (*RegexpLiteral) MarshalJSON ¶
func (l *RegexpLiteral) MarshalJSON() ([]byte, error)
func (*RegexpLiteral) NodeType ¶
func (*RegexpLiteral) NodeType() string
func (*RegexpLiteral) Type ¶
func (*RegexpLiteral) Type() Type
func (*RegexpLiteral) UnmarshalJSON ¶
func (l *RegexpLiteral) UnmarshalJSON(data []byte) error
type ReturnStatement ¶
type ReturnStatement struct {
Argument Expression `json:"argument"`
}
func (*ReturnStatement) Copy ¶
func (s *ReturnStatement) Copy() Node
func (*ReturnStatement) MarshalJSON ¶
func (s *ReturnStatement) MarshalJSON() ([]byte, error)
func (*ReturnStatement) NodeType ¶
func (*ReturnStatement) NodeType() string
func (*ReturnStatement) UnmarshalJSON ¶
func (s *ReturnStatement) UnmarshalJSON(data []byte) error
type StringLiteral ¶
type StringLiteral struct {
Value string `json:"value"`
}
func (*StringLiteral) Copy ¶
func (l *StringLiteral) Copy() Node
func (*StringLiteral) MarshalJSON ¶
func (l *StringLiteral) MarshalJSON() ([]byte, error)
func (*StringLiteral) NodeType ¶
func (*StringLiteral) NodeType() string
func (*StringLiteral) Type ¶
func (*StringLiteral) Type() Type
type Type ¶
type Type interface {
// Kind returns the specific kind of this type.
Kind() Kind
// PropertyType returns the type of a given property.
// It panics if the type's Kind is not Object
PropertyType(name string) Type
// Properties returns a map of all property types.
// It panics if the type's Kind is not Object
Properties() map[string]Type
// ElementType return the type of elements in the array.
// It panics if the type's Kind is not Array.
ElementType() Type
// Params reports the parameters of a function type.
// It panics if the type's Kind is not Function.
Params() map[string]Type
// PipeArgument reports the name of the argument that can be pipe into.
// It panics if the type's Kind is not Function.
PipeArgument() string
// ReturnType reports the return type of the function
// It panics if the type's Kind is not Function.
ReturnType() Type
// contains filtered or unexported methods
}
Type is the representation of a Flux type.
Type values are comparable and as such can be used as map keys and directly comparison using the == operator. Two types are equal if they represent identical types.
DO NOT embed this type into other interfaces or structs as that will invalidate the comparison properties of the interface.
func NewArrayType ¶
func NewFunctionType ¶
func NewFunctionType(sig FunctionSignature) Type
func NewObjectType ¶
type UnaryExpression ¶
type UnaryExpression struct {
Operator ast.OperatorKind `json:"operator"`
Argument Expression `json:"argument"`
}
func (*UnaryExpression) Copy ¶
func (e *UnaryExpression) Copy() Node
func (*UnaryExpression) MarshalJSON ¶
func (e *UnaryExpression) MarshalJSON() ([]byte, error)
func (*UnaryExpression) NodeType ¶
func (*UnaryExpression) NodeType() string
func (*UnaryExpression) Type ¶
func (e *UnaryExpression) Type() Type
func (*UnaryExpression) UnmarshalJSON ¶
func (e *UnaryExpression) UnmarshalJSON(data []byte) error
type UnsignedIntegerLiteral ¶
type UnsignedIntegerLiteral struct {
Value uint64 `json:"value"`
}
func (*UnsignedIntegerLiteral) Copy ¶
func (l *UnsignedIntegerLiteral) Copy() Node
func (*UnsignedIntegerLiteral) MarshalJSON ¶
func (l *UnsignedIntegerLiteral) MarshalJSON() ([]byte, error)
func (*UnsignedIntegerLiteral) NodeType ¶
func (*UnsignedIntegerLiteral) NodeType() string
func (*UnsignedIntegerLiteral) Type ¶
func (*UnsignedIntegerLiteral) Type() Type
func (*UnsignedIntegerLiteral) UnmarshalJSON ¶
func (l *UnsignedIntegerLiteral) UnmarshalJSON(data []byte) error
type VariableDeclaration ¶
type VariableDeclaration interface {
Statement
ID() *Identifier
InitType() Type
}
Directories
¶
| Path | Synopsis |
|---|---|
|
Package semantictest contains utilities for testing the semantic package.
|
Package semantictest contains utilities for testing the semantic package. |