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 ¶
- Constants
- Variables
- func SortNodes(nodes []Node)
- func Walk(v Visitor, node Node)
- type Addable
- type Annotator
- type ArrayExpression
- type ArrayKind
- type Assignment
- type BinaryExpression
- type Block
- type BooleanLiteral
- type BuiltinStatement
- 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 ExternalVariableAssignment
- type File
- type FloatLiteral
- type Fresher
- type FunctionBlock
- type FunctionExpression
- type FunctionParameter
- type FunctionParameters
- type FunctionPolySignature
- type FunctionSignature
- type Identifier
- type IdentifierExpression
- type ImportDeclaration
- type Importer
- type IndexExpression
- type IntegerLiteral
- type KClass
- type Kind
- type KindConstrainter
- type LabelSet
- type Literal
- type LogicalExpression
- type MemberAssignment
- type MemberExpression
- type NativeVariableAssignment
- 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 ObjectKind
- type OptionStatement
- type Package
- type PackageClause
- type PackageType
- type PolyType
- type Property
- type PropertyKey
- type RegexpLiteral
- type ReturnStatement
- type Scheme
- type ScopedVisitor
- type Solution
- type SolutionMap
- 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 ¶
const PackageMain = "main"
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 ArrayKind ¶ added in v0.7.1
type ArrayKind struct {
// contains filtered or unexported fields
}
type Assignment ¶ added in v0.14.0
type Assignment interface { Statement // contains filtered or unexported methods }
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 Block ¶ added in v0.8.0
type Block struct { Body []Statement `json:"body"` // contains filtered or unexported fields }
func (Block) Location ¶ added in v0.8.0
func (l Block) Location() ast.SourceLocation
func (*Block) MarshalJSON ¶ added in v0.8.0
func (*Block) ReturnStatement ¶ added in v0.8.0
func (s *Block) ReturnStatement() *ReturnStatement
func (*Block) UnmarshalJSON ¶ added in v0.8.0
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 BuiltinStatement ¶ added in v0.14.0
type BuiltinStatement struct { ID *Identifier `json:"id"` // contains filtered or unexported fields }
func (*BuiltinStatement) Copy ¶ added in v0.14.0
func (s *BuiltinStatement) Copy() Node
func (BuiltinStatement) Location ¶ added in v0.14.0
func (l BuiltinStatement) Location() ast.SourceLocation
func (*BuiltinStatement) MarshalJSON ¶ added in v0.14.0
func (s *BuiltinStatement) MarshalJSON() ([]byte, error)
func (*BuiltinStatement) NodeType ¶ added in v0.14.0
func (s *BuiltinStatement) 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, importer Importer) (*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 { Assignments []*ExternalVariableAssignment `json:"assignments"` Block *ExternBlock `json:"block"` // contains filtered or unexported fields }
Extern is a node that represents a node with a set of external assignments 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 ExternalVariableAssignment ¶ added in v0.8.0
type ExternalVariableAssignment struct { Identifier *Identifier `json:"identifier"` ExternType PolyType `json:""` // contains filtered or unexported fields }
ExternalVariableAssignment represents an externaly defined identifier and its type.
func (*ExternalVariableAssignment) Copy ¶ added in v0.8.0
func (s *ExternalVariableAssignment) Copy() Node
func (ExternalVariableAssignment) Location ¶ added in v0.8.0
func (l ExternalVariableAssignment) Location() ast.SourceLocation
func (*ExternalVariableAssignment) MarshalJSON ¶ added in v0.8.0
func (d *ExternalVariableAssignment) MarshalJSON() ([]byte, error)
func (*ExternalVariableAssignment) NodeType ¶ added in v0.8.0
func (*ExternalVariableAssignment) NodeType() string
type File ¶ added in v0.13.0
type File struct { Package *PackageClause `json:"package"` Imports []*ImportDeclaration `json:"imports"` Body []Statement `json:"body"` // contains filtered or unexported fields }
func (File) Location ¶ added in v0.13.0
func (l File) Location() ast.SourceLocation
func (*File) MarshalJSON ¶ added in v0.13.0
func (*File) UnmarshalJSON ¶ added in v0.13.0
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) Key ¶ added in v0.12.0
func (n *Identifier) Key() string
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 ImportDeclaration ¶ added in v0.8.0
type ImportDeclaration struct { As *Identifier `json:"as"` Path *StringLiteral `json:"path"` // contains filtered or unexported fields }
func (*ImportDeclaration) Copy ¶ added in v0.8.0
func (d *ImportDeclaration) Copy() Node
func (ImportDeclaration) Location ¶ added in v0.8.0
func (l ImportDeclaration) Location() ast.SourceLocation
func (*ImportDeclaration) MarshalJSON ¶ added in v0.8.0
func (p *ImportDeclaration) MarshalJSON() ([]byte, error)
func (*ImportDeclaration) NodeType ¶ added in v0.8.0
func (*ImportDeclaration) NodeType() string
type Importer ¶ added in v0.8.0
type Importer interface {
Import(path string) (PackageType, bool)
}
Importer produces a package given an import path.
type IndexExpression ¶ added in v0.7.1
type IndexExpression struct { Array Expression `json:"array"` Index Expression `json:"index"` // contains filtered or unexported fields }
func (*IndexExpression) Copy ¶ added in v0.7.1
func (e *IndexExpression) Copy() Node
func (IndexExpression) Location ¶ added in v0.7.1
func (l IndexExpression) Location() ast.SourceLocation
func (*IndexExpression) MarshalJSON ¶ added in v0.7.1
func (e *IndexExpression) MarshalJSON() ([]byte, error)
func (*IndexExpression) NodeType ¶ added in v0.7.1
func (*IndexExpression) NodeType() string
func (*IndexExpression) UnmarshalJSON ¶ added in v0.7.1
func (e *IndexExpression) UnmarshalJSON(data []byte) error
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 MemberAssignment ¶ added in v0.14.0
type MemberAssignment struct { Member *MemberExpression `json:"member"` Init Expression `json:"init"` // contains filtered or unexported fields }
func (*MemberAssignment) Copy ¶ added in v0.14.0
func (s *MemberAssignment) Copy() Node
func (MemberAssignment) Location ¶ added in v0.14.0
func (l MemberAssignment) Location() ast.SourceLocation
func (*MemberAssignment) MarshalJSON ¶ added in v0.14.0
func (s *MemberAssignment) MarshalJSON() ([]byte, error)
func (*MemberAssignment) NodeType ¶ added in v0.14.0
func (*MemberAssignment) NodeType() string
func (*MemberAssignment) UnmarshalJSON ¶ added in v0.14.0
func (s *MemberAssignment) 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 NativeVariableAssignment ¶ added in v0.8.0
type NativeVariableAssignment struct { Identifier *Identifier `json:"identifier"` Init Expression `json:"init"` // contains filtered or unexported fields }
func (*NativeVariableAssignment) Copy ¶ added in v0.8.0
func (s *NativeVariableAssignment) Copy() Node
func (NativeVariableAssignment) Location ¶ added in v0.8.0
func (l NativeVariableAssignment) Location() ast.SourceLocation
func (*NativeVariableAssignment) MarshalJSON ¶ added in v0.8.0
func (d *NativeVariableAssignment) MarshalJSON() ([]byte, error)
func (*NativeVariableAssignment) NodeType ¶ added in v0.8.0
func (*NativeVariableAssignment) NodeType() string
func (*NativeVariableAssignment) UnmarshalJSON ¶ added in v0.8.0
func (d *NativeVariableAssignment) 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 ObjectKind ¶ added in v0.7.1
type ObjectKind struct {
// contains filtered or unexported fields
}
func (ObjectKind) MonoType ¶ added in v0.7.1
func (k ObjectKind) MonoType() (Type, bool)
func (ObjectKind) String ¶ added in v0.7.1
func (k ObjectKind) String() string
type OptionStatement ¶
type OptionStatement struct { Assignment Assignment `json:"assignment"` // 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 Package ¶ added in v0.8.0
type Package struct { Package string `json:"package"` Files []*File `json:"files"` // contains filtered or unexported fields }
func (Package) Location ¶ added in v0.13.0
func (l Package) Location() ast.SourceLocation
func (*Package) MarshalJSON ¶ added in v0.13.0
type PackageClause ¶ added in v0.8.0
type PackageClause struct { Name *Identifier `json:"name"` // contains filtered or unexported fields }
func (*PackageClause) Copy ¶ added in v0.8.0
func (p *PackageClause) Copy() Node
func (PackageClause) Location ¶ added in v0.8.0
func (l PackageClause) Location() ast.SourceLocation
func (*PackageClause) MarshalJSON ¶ added in v0.8.0
func (p *PackageClause) MarshalJSON() ([]byte, error)
func (*PackageClause) NodeType ¶ added in v0.8.0
func (*PackageClause) NodeType() string
type PackageType ¶ added in v0.13.0
PackageType represents the type and name of a package.
func CreatePackage ¶ added in v0.8.0
func CreatePackage(n Node, importer Importer) (PackageType, error)
CreatePackage constructs a Package from the node. The node must contain a Program node with a valid PackageClause
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
func NewObjectPolyType ¶
NewObjectPolyType creates a PolyType representing an object. A map of properties and their types may be provided. Lower is a set of labels that must exist on the object, and upper is a set of labels that may exist on the object. Upper must be a superset of lower. The map must contain an entry for all lables in the lower set. Use AllLabels() to represent the infinite set of all possible labels.
type Property ¶
type Property struct { Key PropertyKey `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 PropertyKey ¶ added in v0.12.0
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 SolutionMap ¶ added in v0.16.0
SolutionMap represents a mapping of nodes to their poly types.
func CreateSolutionMap ¶ added in v0.16.0
func CreateSolutionMap(node Node, sol TypeSolution) SolutionMap
CreateSolutionMap constructs a new solution map from the nodes and type solution. Any type errors in the type solution are ignored.
func (SolutionMap) String ¶ added in v0.16.0
func (s SolutionMap) String() string
type StringLiteral ¶
type StringLiteral struct { Value string `json:"value"` // contains filtered or unexported fields }
func (*StringLiteral) Copy ¶
func (l *StringLiteral) Copy() Node
func (*StringLiteral) Key ¶ added in v0.12.0
func (n *StringLiteral) Key() string
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, importer Importer) (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. |