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 Walk(v Visitor, node Node)
- type Addable
- type Annotator
- type ArrayExpression
- type BinaryExpression
- type BlockStatement
- func (s *BlockStatement) Copy() Node
- func (l BlockStatement) Location() ast.SourceLocation
- func (s *BlockStatement) MarshalJSON() ([]byte, error)
- func (*BlockStatement) NodeType() string
- func (s *BlockStatement) ReturnStatement() *ReturnStatement
- func (s *BlockStatement) UnmarshalJSON(data []byte) error
- type BooleanLiteral
- type CallExpression
- type Comparable
- type ConditionalExpression
- type ConstraintGenerator
- type Constraints
- type DateTimeLiteral
- type DurationLiteral
- type Env
- type Expression
- type ExpressionStatement
- type Extern
- type ExternBlock
- type ExternalVariableDeclaration
- type FloatLiteral
- type Fresher
- type FunctionBlock
- type FunctionExpression
- type FunctionParameter
- type FunctionParameters
- type FunctionPolySignature
- type FunctionSignature
- type Identifier
- type IdentifierExpression
- type IntegerLiteral
- type KClass
- type KRecord
- type Kind
- type KindConstrainter
- type LabelSet
- type Literal
- type LogicalExpression
- type MemberExpression
- type NativeVariableDeclaration
- func (s *NativeVariableDeclaration) Copy() Node
- func (d *NativeVariableDeclaration) ID() *Identifier
- func (l NativeVariableDeclaration) Location() ast.SourceLocation
- func (d *NativeVariableDeclaration) MarshalJSON() ([]byte, error)
- func (*NativeVariableDeclaration) NodeType() string
- func (d *NativeVariableDeclaration) UnmarshalJSON(data []byte) error
- type Nature
- func (n Nature) ElementType() Type
- func (n Nature) Equal(t PolyType) bool
- func (n Nature) FunctionSignature() FunctionSignature
- func (n Nature) MonoType() (Type, bool)
- func (n Nature) Nature() Nature
- func (n Nature) PolyType() PolyType
- func (n Nature) Properties() map[string]Type
- func (n Nature) PropertyType(name string) Type
- func (n Nature) String() string
- type NestingVisitor
- type Node
- type Number
- type ObjectExpression
- type OptionStatement
- type PolyType
- type Program
- type Property
- type RegexpLiteral
- type ReturnStatement
- type Scheme
- type ScopedVisitor
- type Solution
- type Statement
- type StringLiteral
- type Substitution
- func (s Substitution) ApplyEnv(env *Env) *Env
- func (s Substitution) ApplyKind(k Kind) Kind
- func (s Substitution) ApplyScheme(ts Scheme) Scheme
- func (s Substitution) ApplyTvar(tv Tvar) Tvar
- func (s Substitution) ApplyType(t PolyType) PolyType
- func (l Substitution) Merge(r Substitution)
- func (s Substitution) String() string
- type Tvar
- type TvarSet
- type Type
- type TypeConstraint
- type TypeExpression
- type TypeSolution
- type UnaryExpression
- type UnsignedIntegerLiteral
- type Visitor
Constants ¶
This section is empty.
Variables ¶
var EmptyArrayType = NewArrayType(Nil)
TODO(nathanielc): Make empty array types polymorphic over element type?
var EmptyObject = NewObjectType(nil)
Functions ¶
Types ¶
type Annotator ¶
type Annotator struct {
// contains filtered or unexported fields
}
Annotator implements Visitor to walk the graph.
type ArrayExpression ¶
type ArrayExpression struct { Elements []Expression `json:"elements"` // contains filtered or unexported fields }
func (*ArrayExpression) Copy ¶
func (e *ArrayExpression) Copy() Node
func (ArrayExpression) Location ¶
func (l ArrayExpression) Location() ast.SourceLocation
func (*ArrayExpression) MarshalJSON ¶
func (e *ArrayExpression) MarshalJSON() ([]byte, error)
func (*ArrayExpression) NodeType ¶
func (*ArrayExpression) NodeType() string
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"` // contains filtered or unexported fields }
func (*BinaryExpression) Copy ¶
func (e *BinaryExpression) Copy() Node
func (BinaryExpression) Location ¶
func (l BinaryExpression) Location() ast.SourceLocation
func (*BinaryExpression) MarshalJSON ¶
func (e *BinaryExpression) MarshalJSON() ([]byte, error)
func (*BinaryExpression) NodeType ¶
func (*BinaryExpression) NodeType() string
func (*BinaryExpression) UnmarshalJSON ¶
func (e *BinaryExpression) UnmarshalJSON(data []byte) error
type BlockStatement ¶
type BlockStatement struct { Body []Statement `json:"body"` // contains filtered or unexported fields }
func (*BlockStatement) Copy ¶
func (s *BlockStatement) Copy() Node
func (BlockStatement) Location ¶
func (l BlockStatement) Location() ast.SourceLocation
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"` // contains filtered or unexported fields }
func (*BooleanLiteral) Copy ¶
func (l *BooleanLiteral) Copy() Node
func (BooleanLiteral) Location ¶
func (l BooleanLiteral) Location() ast.SourceLocation
func (*BooleanLiteral) MarshalJSON ¶
func (l *BooleanLiteral) MarshalJSON() ([]byte, error)
func (*BooleanLiteral) NodeType ¶
func (*BooleanLiteral) NodeType() string
type CallExpression ¶
type CallExpression struct { Callee Expression `json:"callee"` Arguments *ObjectExpression `json:"arguments"` Pipe Expression `json:"pipe,omitempty"` // contains filtered or unexported fields }
func (*CallExpression) Copy ¶
func (e *CallExpression) Copy() Node
func (CallExpression) Location ¶
func (l CallExpression) Location() ast.SourceLocation
func (*CallExpression) MarshalJSON ¶
func (e *CallExpression) MarshalJSON() ([]byte, error)
func (*CallExpression) NodeType ¶
func (*CallExpression) NodeType() string
func (*CallExpression) UnmarshalJSON ¶
func (e *CallExpression) UnmarshalJSON(data []byte) error
type Comparable ¶
type Comparable struct{}
type ConditionalExpression ¶
type ConditionalExpression struct { Test Expression `json:"test"` Alternate Expression `json:"alternate"` Consequent Expression `json:"consequent"` // contains filtered or unexported fields }
func (*ConditionalExpression) Copy ¶
func (e *ConditionalExpression) Copy() Node
func (ConditionalExpression) Location ¶
func (l ConditionalExpression) Location() ast.SourceLocation
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 ConstraintGenerator ¶
type ConstraintGenerator struct {
// contains filtered or unexported fields
}
ConstraintGenerator implements NestingVisitor and generates constraints as it walks the graph.
func (ConstraintGenerator) Done ¶
func (v ConstraintGenerator) Done(node Node)
Done visits nodes after all children of the node have been visited.
func (ConstraintGenerator) Nest ¶
func (v ConstraintGenerator) Nest() NestingVisitor
Nest nests the internal type environment to obey scoping rules.
func (ConstraintGenerator) Visit ¶
func (v ConstraintGenerator) Visit(node Node) Visitor
Visit visits each node, the algorithm is depth first so nothing is performed in Visit except for an error check.
type Constraints ¶
type Constraints struct {
// contains filtered or unexported fields
}
Constraints is a set of constraints.
func GenerateConstraints ¶
func GenerateConstraints(node Node, annotator Annotator) (*Constraints, error)
GenerateConstraints walks the graph and generates constraints between type vairables provided in the annotations.
func (*Constraints) AddKindConst ¶
func (c *Constraints) AddKindConst(tv Tvar, k Kind)
func (*Constraints) AddTypeConst ¶
func (c *Constraints) AddTypeConst(l, r PolyType, loc ast.SourceLocation)
func (*Constraints) Copy ¶
func (c *Constraints) Copy() *Constraints
func (*Constraints) Instantiate ¶
func (c *Constraints) Instantiate(s Scheme, loc ast.SourceLocation) (t PolyType)
Instantiate produces a new poly type where the free variables from the scheme have been made fresh. This way each new instantiation of a scheme is independent of the other but all have the same constraint structure.
func (*Constraints) String ¶
func (c *Constraints) String() string
type DateTimeLiteral ¶
type DateTimeLiteral struct { Value time.Time `json:"value"` // contains filtered or unexported fields }
func (*DateTimeLiteral) Copy ¶
func (l *DateTimeLiteral) Copy() Node
func (DateTimeLiteral) Location ¶
func (l DateTimeLiteral) Location() ast.SourceLocation
func (*DateTimeLiteral) MarshalJSON ¶
func (l *DateTimeLiteral) MarshalJSON() ([]byte, error)
func (*DateTimeLiteral) NodeType ¶
func (*DateTimeLiteral) NodeType() string
type DurationLiteral ¶
type DurationLiteral struct { Value time.Duration `json:"value"` // contains filtered or unexported fields }
func (*DurationLiteral) Copy ¶
func (l *DurationLiteral) Copy() Node
func (DurationLiteral) Location ¶
func (l DurationLiteral) Location() ast.SourceLocation
func (*DurationLiteral) MarshalJSON ¶
func (l *DurationLiteral) MarshalJSON() ([]byte, error)
func (*DurationLiteral) NodeType ¶
func (*DurationLiteral) NodeType() string
func (*DurationLiteral) UnmarshalJSON ¶
func (l *DurationLiteral) UnmarshalJSON(data []byte) error
type Env ¶
type Env struct {
// contains filtered or unexported fields
}
Env is a type environment mapping identifiers in scope to their type schemes.
func (*Env) LocalLookup ¶
LocalLookup search for the identifier in the local scope only, it does not recurse to parents.
type Expression ¶
type Expression interface { Node // contains filtered or unexported methods }
func ConjunctionsToExprSlice ¶
func ConjunctionsToExprSlice(expr Expression) []Expression
ConjunctionsToExprSlice finds all children of AndOperators that are not themselves AndOperators, and returns them in a slice. If the root node of expr is not an AndOperator, just returns expr.
AND / \ AND r => {p, q, r} / \ p q
func ExprsToConjunction ¶
func ExprsToConjunction(exprs ...Expression) Expression
ExprsToConjunction accepts a variable number of expressions and ANDs them together into a single expression.
AND / \ {p, q, r} => AND r / \ p q
func PartitionPredicates ¶
func PartitionPredicates(expr Expression, partitionFn func(expression Expression) (bool, error)) (passExpr, failExpr Expression, err error)
PartitionPredicates accepts a predicate expression, separates it into components that have been logically ANDed together, and applies partitionFn to them. Returns two expressions: one AND tree of the expressions for which partitionFn returned true, and an AND tree of expressions for which partitionFn returned false.
Suppose partitonFn returns true for p and r, and false for q:
AND passExpr failExpr / \ AND r => AND q / \ / \ p q p r
type ExpressionStatement ¶
type ExpressionStatement struct { Expression Expression `json:"expression"` // contains filtered or unexported fields }
func (*ExpressionStatement) Copy ¶
func (s *ExpressionStatement) Copy() Node
func (ExpressionStatement) Location ¶
func (l ExpressionStatement) Location() ast.SourceLocation
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 Extern ¶
type Extern struct { Declarations []*ExternalVariableDeclaration `json:"declarations"` Block *ExternBlock `json:"block"` // contains filtered or unexported fields }
Extern is a node that represents a node with a set of external declarations defined.
func (Extern) Location ¶
func (l Extern) Location() ast.SourceLocation
func (*Extern) MarshalJSON ¶
type ExternBlock ¶
type ExternBlock struct { Node Node // contains filtered or unexported fields }
ExternBlock is a node that represents a node with a set of external declarations defined.
func (*ExternBlock) Copy ¶
func (e *ExternBlock) Copy() Node
func (ExternBlock) Location ¶
func (l ExternBlock) Location() ast.SourceLocation
func (*ExternBlock) MarshalJSON ¶
func (e *ExternBlock) MarshalJSON() ([]byte, error)
func (*ExternBlock) NodeType ¶
func (*ExternBlock) NodeType() string
func (*ExternBlock) UnmarshalJSON ¶
func (e *ExternBlock) UnmarshalJSON(data []byte) error
type ExternalVariableDeclaration ¶
type ExternalVariableDeclaration struct { Identifier *Identifier `json:"identifier"` ExternType PolyType `json:""` // contains filtered or unexported fields }
ExternalVariableDeclaration represents an externaly defined identifier and its type.
func (*ExternalVariableDeclaration) Copy ¶
func (s *ExternalVariableDeclaration) Copy() Node
func (ExternalVariableDeclaration) Location ¶
func (l ExternalVariableDeclaration) Location() ast.SourceLocation
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"` // contains filtered or unexported fields }
func (*FloatLiteral) Copy ¶
func (l *FloatLiteral) Copy() Node
func (FloatLiteral) Location ¶
func (l FloatLiteral) Location() ast.SourceLocation
func (*FloatLiteral) MarshalJSON ¶
func (l *FloatLiteral) MarshalJSON() ([]byte, error)
func (*FloatLiteral) NodeType ¶
func (*FloatLiteral) NodeType() string
type Fresher ¶
type Fresher interface { // Fresh produces a new unused type variable. Fresh() Tvar }
Fresher produces fresh type variables.
func NewFresher ¶
func NewFresher() Fresher
type FunctionBlock ¶
type FunctionBlock struct { Parameters *FunctionParameters `json:"parameters"` Body Node `json:"body"` // contains filtered or unexported fields }
FunctionBlock represents the function parameters and the function body.
func (*FunctionBlock) Copy ¶
func (b *FunctionBlock) Copy() Node
func (FunctionBlock) Location ¶
func (l FunctionBlock) Location() ast.SourceLocation
func (*FunctionBlock) MarshalJSON ¶
func (e *FunctionBlock) MarshalJSON() ([]byte, error)
func (*FunctionBlock) NodeType ¶
func (*FunctionBlock) NodeType() string
func (*FunctionBlock) UnmarshalJSON ¶
func (e *FunctionBlock) UnmarshalJSON(data []byte) error
type FunctionExpression ¶
type FunctionExpression struct { Defaults *ObjectExpression `json:"defaults,omitempty"` Block *FunctionBlock `json:"block"` // contains filtered or unexported fields }
FunctionExpression represents the definition of a function
func (*FunctionExpression) Copy ¶
func (e *FunctionExpression) Copy() Node
func (FunctionExpression) Location ¶
func (l FunctionExpression) Location() ast.SourceLocation
func (*FunctionExpression) MarshalJSON ¶
func (e *FunctionExpression) MarshalJSON() ([]byte, error)
func (*FunctionExpression) NodeType ¶
func (*FunctionExpression) NodeType() string
type FunctionParameter ¶
type FunctionParameter struct { Key *Identifier `json:"key"` // contains filtered or unexported fields }
FunctionParameter represents a function parameter.
func (*FunctionParameter) Copy ¶
func (p *FunctionParameter) Copy() Node
func (FunctionParameter) Location ¶
func (l FunctionParameter) Location() ast.SourceLocation
func (*FunctionParameter) MarshalJSON ¶
func (e *FunctionParameter) MarshalJSON() ([]byte, error)
func (*FunctionParameter) NodeType ¶
func (*FunctionParameter) NodeType() string
type FunctionParameters ¶
type FunctionParameters struct { List []*FunctionParameter `json:"list"` Pipe *Identifier `json:"pipe"` // contains filtered or unexported fields }
FunctionParameters represents the list of function parameters and which if any parameter is the pipe parameter.
func (*FunctionParameters) Copy ¶
func (p *FunctionParameters) Copy() Node
func (FunctionParameters) Location ¶
func (l FunctionParameters) Location() ast.SourceLocation
func (*FunctionParameters) MarshalJSON ¶
func (e *FunctionParameters) MarshalJSON() ([]byte, error)
func (*FunctionParameters) NodeType ¶
func (*FunctionParameters) NodeType() string
type FunctionPolySignature ¶
type FunctionSignature ¶
type Identifier ¶
type Identifier struct { Name string `json:"name"` // contains filtered or unexported fields }
func (*Identifier) Copy ¶
func (i *Identifier) Copy() Node
func (Identifier) Location ¶
func (l Identifier) Location() ast.SourceLocation
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) Location ¶
func (l IdentifierExpression) Location() ast.SourceLocation
func (*IdentifierExpression) MarshalJSON ¶
func (e *IdentifierExpression) MarshalJSON() ([]byte, error)
func (*IdentifierExpression) NodeType ¶
func (*IdentifierExpression) NodeType() string
type IntegerLiteral ¶
type IntegerLiteral struct { Value int64 `json:"value"` // contains filtered or unexported fields }
func (*IntegerLiteral) Copy ¶
func (l *IntegerLiteral) Copy() Node
func (IntegerLiteral) Location ¶
func (l IntegerLiteral) Location() ast.SourceLocation
func (*IntegerLiteral) MarshalJSON ¶
func (l *IntegerLiteral) MarshalJSON() ([]byte, error)
func (*IntegerLiteral) NodeType ¶
func (*IntegerLiteral) NodeType() string
func (*IntegerLiteral) UnmarshalJSON ¶
func (l *IntegerLiteral) UnmarshalJSON(data []byte) error
type Kind ¶
type Kind interface { TypeExpression // contains filtered or unexported methods }
Kind is a constraint in the kind domain.
type KindConstrainter ¶
type KindConstrainter interface {
KindConstraint() Kind
}
type LabelSet ¶
type LabelSet []string
LabelSet is a set of string labels.
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"` // contains filtered or unexported fields }
func (*LogicalExpression) Copy ¶
func (e *LogicalExpression) Copy() Node
func (LogicalExpression) Location ¶
func (l LogicalExpression) Location() ast.SourceLocation
func (*LogicalExpression) MarshalJSON ¶
func (e *LogicalExpression) MarshalJSON() ([]byte, error)
func (*LogicalExpression) NodeType ¶
func (*LogicalExpression) NodeType() string
func (*LogicalExpression) UnmarshalJSON ¶
func (e *LogicalExpression) UnmarshalJSON(data []byte) error
type MemberExpression ¶
type MemberExpression struct { Object Expression `json:"object"` Property string `json:"property"` // contains filtered or unexported fields }
func (*MemberExpression) Copy ¶
func (e *MemberExpression) Copy() Node
func (MemberExpression) Location ¶
func (l MemberExpression) Location() ast.SourceLocation
func (*MemberExpression) MarshalJSON ¶
func (e *MemberExpression) MarshalJSON() ([]byte, error)
func (*MemberExpression) NodeType ¶
func (*MemberExpression) NodeType() string
func (*MemberExpression) UnmarshalJSON ¶
func (e *MemberExpression) UnmarshalJSON(data []byte) error
type NativeVariableDeclaration ¶
type NativeVariableDeclaration struct { Identifier *Identifier `json:"identifier"` Init Expression `json:"init"` // contains filtered or unexported fields }
func (*NativeVariableDeclaration) Copy ¶
func (s *NativeVariableDeclaration) Copy() Node
func (*NativeVariableDeclaration) ID ¶
func (d *NativeVariableDeclaration) ID() *Identifier
func (NativeVariableDeclaration) Location ¶
func (l NativeVariableDeclaration) Location() ast.SourceLocation
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 Nature ¶
type Nature int
Nature is the primitive description of a type.
func (Nature) ElementType ¶
func (Nature) FunctionSignature ¶
func (n Nature) FunctionSignature() FunctionSignature
func (Nature) Properties ¶
func (Nature) PropertyType ¶
type NestingVisitor ¶
type NestingVisitor interface { Visitor Nest() NestingVisitor }
type Node ¶
type Node interface { NodeType() string Copy() Node Location() ast.SourceLocation 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) Location ¶
func (l ObjectExpression) Location() ast.SourceLocation
func (*ObjectExpression) MarshalJSON ¶
func (e *ObjectExpression) MarshalJSON() ([]byte, error)
func (*ObjectExpression) NodeType ¶
func (*ObjectExpression) NodeType() string
type OptionStatement ¶
type OptionStatement struct { // Declaration represents the declaration of the option. // Must be one of *ExternalVariableDeclaration or *NativeVariableDeclaration. Declaration Node `json:"declaration"` // contains filtered or unexported fields }
func (*OptionStatement) Copy ¶
func (s *OptionStatement) Copy() Node
func (OptionStatement) Location ¶
func (l OptionStatement) Location() ast.SourceLocation
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 PolyType ¶
type PolyType interface { TypeExpression // Equal reports if two types are the same. Equal(PolyType) bool // Nature reports the primitive description of the type. Nature() Nature // contains filtered or unexported methods }
PolyType represents a polymorphic type, meaning that the type may have multiple free type variables.
func NewArrayPolyType ¶
func NewEmptyObjectPolyType ¶
func NewEmptyObjectPolyType() PolyType
func NewFunctionPolyType ¶
func NewFunctionPolyType(sig FunctionPolySignature) PolyType
type Program ¶
type Program struct { Body []Statement `json:"body"` // contains filtered or unexported fields }
func (Program) Location ¶
func (l Program) Location() ast.SourceLocation
func (*Program) MarshalJSON ¶
func (*Program) UnmarshalJSON ¶
type Property ¶
type Property struct { Key *Identifier `json:"key"` Value Expression `json:"value"` // contains filtered or unexported fields }
func (Property) Location ¶
func (l Property) Location() ast.SourceLocation
func (*Property) MarshalJSON ¶
func (*Property) UnmarshalJSON ¶
type RegexpLiteral ¶
type RegexpLiteral struct { Value *regexp.Regexp `json:"value"` // contains filtered or unexported fields }
func (*RegexpLiteral) Copy ¶
func (l *RegexpLiteral) Copy() Node
func (RegexpLiteral) Location ¶
func (l RegexpLiteral) Location() ast.SourceLocation
func (*RegexpLiteral) MarshalJSON ¶
func (l *RegexpLiteral) MarshalJSON() ([]byte, error)
func (*RegexpLiteral) NodeType ¶
func (*RegexpLiteral) NodeType() string
func (*RegexpLiteral) UnmarshalJSON ¶
func (l *RegexpLiteral) UnmarshalJSON(data []byte) error
type ReturnStatement ¶
type ReturnStatement struct { Argument Expression `json:"argument"` // contains filtered or unexported fields }
func (*ReturnStatement) Copy ¶
func (s *ReturnStatement) Copy() Node
func (ReturnStatement) Location ¶
func (l ReturnStatement) Location() ast.SourceLocation
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 ScopedVisitor ¶
type ScopedVisitor struct {
// contains filtered or unexported fields
}
ScopedVisitor will nest the given visitor when the scope changes.
func NewScopedVisitor ¶
func NewScopedVisitor(v NestingVisitor) ScopedVisitor
func (ScopedVisitor) Done ¶
func (v ScopedVisitor) Done(node Node)
func (ScopedVisitor) Visit ¶
func (v ScopedVisitor) Visit(node Node) Visitor
type Solution ¶
type Solution struct {
// contains filtered or unexported fields
}
Solution implement TypeSolution and solves the unification problem.
func (*Solution) AddConstraint ¶
func (*Solution) FreshSolution ¶
func (s *Solution) FreshSolution() TypeSolution
type StringLiteral ¶
type StringLiteral struct { Value string `json:"value"` // contains filtered or unexported fields }
func (*StringLiteral) Copy ¶
func (l *StringLiteral) Copy() Node
func (StringLiteral) Location ¶
func (l StringLiteral) Location() ast.SourceLocation
func (*StringLiteral) MarshalJSON ¶
func (l *StringLiteral) MarshalJSON() ([]byte, error)
func (*StringLiteral) NodeType ¶
func (*StringLiteral) NodeType() string
type Substitution ¶
Substitution is a maping of type variables to a poly type.
func (Substitution) ApplyEnv ¶
func (s Substitution) ApplyEnv(env *Env) *Env
func (Substitution) ApplyKind ¶
func (s Substitution) ApplyKind(k Kind) Kind
func (Substitution) ApplyScheme ¶
func (s Substitution) ApplyScheme(ts Scheme) Scheme
func (Substitution) ApplyTvar ¶
func (s Substitution) ApplyTvar(tv Tvar) Tvar
func (Substitution) ApplyType ¶
func (s Substitution) ApplyType(t PolyType) PolyType
func (Substitution) String ¶
func (s Substitution) String() string
type Tvar ¶
type Tvar int
Tvar represents a type variable meaning its type could be any possible type.
type Type ¶
type Type interface { // Nature returns the specific primitive description of this type. Nature() Nature // 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 // FunctionSignature returns the function signature of this type. // It panics if the type's Kind is not Function. FunctionSignature() FunctionSignature PolyType() PolyType // contains filtered or unexported methods }
Type is the representation of a Flux type. Type is a monomorphic, meaning that it represents a single type and is not polymorphic. See PolyType for polymorphic types.
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) (t Type)
func NewObjectType ¶
type TypeConstraint ¶
type TypeConstraint struct {
// contains filtered or unexported fields
}
TypeConstraint states that the left and right types must be equal.
func (TypeConstraint) String ¶
func (tc TypeConstraint) String() string
type TypeExpression ¶
type TypeExpression interface { // MonoType produces a monotype of the expression. MonoType() (Type, bool) // contains filtered or unexported methods }
TypeExpression represents an expression describing a type.
type TypeSolution ¶
type TypeSolution interface { // TypeOf reports the monotype of the node or an error. TypeOf(n Node) (Type, error) // TypeOf reports the polytype of the node or an error. PolyTypeOf(n Node) (PolyType, error) // FreshSolution creates a copy of the solution with fresh type variables FreshSolution() TypeSolution // Fresh creates a new type variable within the solution. Fresh() Tvar // AddConstraint adds a new constraint and solves again reporting any errors. AddConstraint(l, r PolyType) error }
TypeSolution is a mapping of Nodes to their types.
func InferTypes ¶
func InferTypes(n Node) (TypeSolution, error)
InferTypes produces a solution to type inference for a given semantic graph.
func SolveConstraints ¶
func SolveConstraints(cs *Constraints) (TypeSolution, error)
SolveConstraints solves the type inference problem defined by the constraints.
type UnaryExpression ¶
type UnaryExpression struct { Operator ast.OperatorKind `json:"operator"` Argument Expression `json:"argument"` // contains filtered or unexported fields }
func (*UnaryExpression) Copy ¶
func (e *UnaryExpression) Copy() Node
func (UnaryExpression) Location ¶
func (l UnaryExpression) Location() ast.SourceLocation
func (*UnaryExpression) MarshalJSON ¶
func (e *UnaryExpression) MarshalJSON() ([]byte, error)
func (*UnaryExpression) NodeType ¶
func (*UnaryExpression) NodeType() string
func (*UnaryExpression) UnmarshalJSON ¶
func (e *UnaryExpression) UnmarshalJSON(data []byte) error
type UnsignedIntegerLiteral ¶
type UnsignedIntegerLiteral struct { Value uint64 `json:"value"` // contains filtered or unexported fields }
func (*UnsignedIntegerLiteral) Copy ¶
func (l *UnsignedIntegerLiteral) Copy() Node
func (UnsignedIntegerLiteral) Location ¶
func (l UnsignedIntegerLiteral) Location() ast.SourceLocation
func (*UnsignedIntegerLiteral) MarshalJSON ¶
func (l *UnsignedIntegerLiteral) MarshalJSON() ([]byte, error)
func (*UnsignedIntegerLiteral) NodeType ¶
func (*UnsignedIntegerLiteral) NodeType() string
func (*UnsignedIntegerLiteral) UnmarshalJSON ¶
func (l *UnsignedIntegerLiteral) UnmarshalJSON(data []byte) error
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package semantictest contains utilities for testing the semantic package.
|
Package semantictest contains utilities for testing the semantic package. |