semantic

package
v0.146.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 13, 2021 License: MIT Imports: 11 Imported by: 21

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

View Source
var (
	BasicBool     = newBasicType(fbsemantic.TypeBool)
	BasicInt      = newBasicType(fbsemantic.TypeInt)
	BasicUint     = newBasicType(fbsemantic.TypeUint)
	BasicFloat    = newBasicType(fbsemantic.TypeFloat)
	BasicString   = newBasicType(fbsemantic.TypeString)
	BasicDuration = newBasicType(fbsemantic.TypeDuration)
	BasicTime     = newBasicType(fbsemantic.TypeTime)
	BasicRegexp   = newBasicType(fbsemantic.TypeRegexp)
	BasicBytes    = newBasicType(fbsemantic.TypeBytes)
)

Functions

func Formatted added in v0.50.0

func Formatted(n Node, opts ...FormatOption) fmt.Formatter

Formatted produces a Formatter object suitable for printing using the standard fmt package. Currently only works for some expressions.

func ToAST added in v0.68.0

func ToAST(n Node) ast.Node

ToAST will construct an AST from the semantic graph. The AST will not be preserved when going from AST -> semantic -> AST, but going from semantic -> AST -> semantic should result in the same graph.

func Walk

func Walk(v Visitor, node Node)

Types

type Argument added in v0.68.0

type Argument struct {
	*fbsemantic.Argument
}

Argument represents a function argument.

func (*Argument) TypeOf added in v0.68.0

func (a *Argument) TypeOf() (MonoType, error)

TypeOf returns the type of the function argument.

type ArgumentType added in v0.68.0

type ArgumentType struct {
	Name     []byte
	Type     MonoType
	Pipe     bool
	Optional bool
}

type ArrayExpression

type ArrayExpression struct {
	Loc

	Elements []Expression

	Type MonoType
}

func (*ArrayExpression) Copy

func (e *ArrayExpression) Copy() Node

func (*ArrayExpression) FromBuf added in v0.57.0

func (rcv *ArrayExpression) FromBuf(fb *fbsemantic.ArrayExpression) error

func (*ArrayExpression) NodeType

func (*ArrayExpression) NodeType() string

func (*ArrayExpression) TypeOf added in v0.58.0

func (e *ArrayExpression) TypeOf() MonoType

type Assignment added in v0.14.0

type Assignment interface {
	Statement
	// contains filtered or unexported methods
}

type BinaryExpression

type BinaryExpression struct {
	Loc

	Operator ast.OperatorKind
	Left     Expression
	Right    Expression
	// contains filtered or unexported fields
}

func (*BinaryExpression) Copy

func (e *BinaryExpression) Copy() Node

func (*BinaryExpression) FromBuf added in v0.57.0

func (*BinaryExpression) NodeType

func (*BinaryExpression) NodeType() string

func (*BinaryExpression) TypeOf added in v0.58.0

func (e *BinaryExpression) TypeOf() MonoType

type Block added in v0.8.0

type Block struct {
	Loc

	Body []Statement
}

func (*Block) Copy added in v0.8.0

func (s *Block) Copy() Node

func (*Block) FromBuf added in v0.57.0

func (rcv *Block) FromBuf(fb *fbsemantic.Block) error

func (*Block) NodeType added in v0.8.0

func (*Block) NodeType() string

func (*Block) ReturnStatement added in v0.8.0

func (s *Block) ReturnStatement() *ReturnStatement

type BooleanLiteral

type BooleanLiteral struct {
	Loc
	Value bool
}

func (*BooleanLiteral) Copy

func (l *BooleanLiteral) Copy() Node

func (*BooleanLiteral) FromBuf added in v0.57.0

func (rcv *BooleanLiteral) FromBuf(fb *fbsemantic.BooleanLiteral) error

func (*BooleanLiteral) NodeType

func (*BooleanLiteral) NodeType() string

func (*BooleanLiteral) TypeOf added in v0.58.0

func (e *BooleanLiteral) TypeOf() MonoType

type BuiltinStatement added in v0.14.0

type BuiltinStatement struct {
	Loc

	ID *Identifier
}

func (*BuiltinStatement) Copy added in v0.14.0

func (s *BuiltinStatement) Copy() Node

func (*BuiltinStatement) FromBuf added in v0.57.0

func (*BuiltinStatement) NodeType added in v0.14.0

func (s *BuiltinStatement) NodeType() string

type CallExpression

type CallExpression struct {
	Loc

	Callee    Expression
	Arguments *ObjectExpression
	Pipe      Expression
	// contains filtered or unexported fields
}

func (*CallExpression) Copy

func (e *CallExpression) Copy() Node

func (*CallExpression) FromBuf added in v0.57.0

func (rcv *CallExpression) FromBuf(fb *fbsemantic.CallExpression) error

func (*CallExpression) NodeType

func (*CallExpression) NodeType() string

func (*CallExpression) TypeOf added in v0.58.0

func (e *CallExpression) TypeOf() MonoType

type ConditionalExpression

type ConditionalExpression struct {
	Loc

	Test       Expression
	Alternate  Expression
	Consequent Expression
}

func (*ConditionalExpression) Copy

func (e *ConditionalExpression) Copy() Node

func (*ConditionalExpression) FromBuf added in v0.57.0

func (*ConditionalExpression) NodeType

func (*ConditionalExpression) NodeType() string

func (*ConditionalExpression) TypeOf added in v0.58.0

func (e *ConditionalExpression) TypeOf() MonoType

type DateTimeLiteral

type DateTimeLiteral struct {
	Loc
	Value time.Time
}

func (*DateTimeLiteral) Copy

func (l *DateTimeLiteral) Copy() Node

func (*DateTimeLiteral) FromBuf added in v0.57.0

func (rcv *DateTimeLiteral) FromBuf(fb *fbsemantic.DateTimeLiteral) error

func (*DateTimeLiteral) NodeType

func (*DateTimeLiteral) NodeType() string

func (*DateTimeLiteral) TypeOf added in v0.58.0

func (e *DateTimeLiteral) TypeOf() MonoType

type DictExpression added in v0.99.0

type DictExpression struct {
	Loc

	Elements []struct {
		Key Expression
		Val Expression
	}

	Type MonoType
}

func (*DictExpression) Copy added in v0.99.0

func (e *DictExpression) Copy() Node

func (*DictExpression) FromBuf added in v0.99.0

func (rcv *DictExpression) FromBuf(fb *fbsemantic.DictExpression) error

func (*DictExpression) NodeType added in v0.99.0

func (*DictExpression) NodeType() string

func (*DictExpression) TypeOf added in v0.99.0

func (e *DictExpression) TypeOf() MonoType

type DurationLiteral

type DurationLiteral struct {
	Loc
	Values []ast.Duration
}

func (*DurationLiteral) Copy

func (l *DurationLiteral) Copy() Node

func (*DurationLiteral) FromBuf added in v0.57.0

func (rcv *DurationLiteral) FromBuf(fb *fbsemantic.DurationLiteral) error

func (*DurationLiteral) NodeType

func (*DurationLiteral) NodeType() string

func (*DurationLiteral) TypeOf added in v0.58.0

func (e *DurationLiteral) TypeOf() MonoType

type Expression

type Expression interface {
	Node

	TypeOf() MonoType
	// 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 {
	Loc

	Expression Expression
}

func (*ExpressionStatement) Copy

func (s *ExpressionStatement) Copy() Node

func (*ExpressionStatement) FromBuf added in v0.57.0

func (*ExpressionStatement) NodeType

func (*ExpressionStatement) NodeType() string

type File added in v0.13.0

type File struct {
	Loc

	Package *PackageClause
	Imports []*ImportDeclaration
	Body    []Statement
}

func (*File) Copy added in v0.13.0

func (p *File) Copy() Node

func (*File) FromBuf added in v0.57.0

func (rcv *File) FromBuf(fb *fbsemantic.File) error

func (*File) NodeType added in v0.13.0

func (*File) NodeType() string

type FloatLiteral

type FloatLiteral struct {
	Loc
	Value float64
}

func (*FloatLiteral) Copy

func (l *FloatLiteral) Copy() Node

func (*FloatLiteral) FromBuf added in v0.57.0

func (rcv *FloatLiteral) FromBuf(fb *fbsemantic.FloatLiteral) error

func (*FloatLiteral) NodeType

func (*FloatLiteral) NodeType() string

func (*FloatLiteral) TypeOf added in v0.58.0

func (e *FloatLiteral) TypeOf() MonoType

type FormatOption added in v0.50.0

type FormatOption func(*formatter)

type FunctionExpression

type FunctionExpression struct {
	Loc

	Parameters *FunctionParameters
	Defaults   *ObjectExpression
	Block      *Block

	Vectorized *FunctionExpression
	// contains filtered or unexported fields
}

FunctionExpression represents the definition of a function

func (*FunctionExpression) Copy

func (e *FunctionExpression) Copy() Node

func (*FunctionExpression) FromBuf added in v0.57.0

func (*FunctionExpression) GetFunctionBodyExpression added in v0.68.0

func (e *FunctionExpression) GetFunctionBodyExpression() (Expression, bool)

GetFunctionBodyExpression will return the return value expression from the function block. This will only return an expression if there is exactly one expression in the block. It will return false as the second argument if the statement is more complex.

func (*FunctionExpression) NodeType

func (*FunctionExpression) NodeType() string

func (*FunctionExpression) TypeOf added in v0.58.0

func (e *FunctionExpression) TypeOf() MonoType

type FunctionParameter

type FunctionParameter struct {
	Loc

	Key *Identifier
}

FunctionParameter represents a function parameter.

func (*FunctionParameter) Copy

func (p *FunctionParameter) Copy() Node

func (*FunctionParameter) FromBuf added in v0.57.0

func (*FunctionParameter) NodeType

func (*FunctionParameter) NodeType() string

type FunctionParameters

type FunctionParameters struct {
	Loc

	List []*FunctionParameter
	Pipe *Identifier
}

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) NodeType

func (*FunctionParameters) NodeType() string

type Identifier

type Identifier struct {
	Loc

	Name string
}

func (*Identifier) Copy

func (i *Identifier) Copy() Node

func (*Identifier) FromBuf added in v0.57.0

func (rcv *Identifier) FromBuf(fb *fbsemantic.Identifier) error

func (*Identifier) Key added in v0.12.0

func (n *Identifier) Key() string

func (*Identifier) NodeType

func (*Identifier) NodeType() string

type IdentifierExpression

type IdentifierExpression struct {
	Loc

	Name string
	// contains filtered or unexported fields
}

func (*IdentifierExpression) Copy

func (e *IdentifierExpression) Copy() Node

func (*IdentifierExpression) FromBuf added in v0.57.0

func (*IdentifierExpression) NodeType

func (*IdentifierExpression) NodeType() string

func (*IdentifierExpression) TypeOf added in v0.58.0

func (e *IdentifierExpression) TypeOf() MonoType

type ImportDeclaration added in v0.8.0

type ImportDeclaration struct {
	Loc

	As   *Identifier
	Path *StringLiteral
}

func (*ImportDeclaration) Copy added in v0.8.0

func (d *ImportDeclaration) Copy() Node

func (*ImportDeclaration) FromBuf added in v0.57.0

func (*ImportDeclaration) NodeType added in v0.8.0

func (*ImportDeclaration) NodeType() string

type IndexExpression added in v0.7.1

type IndexExpression struct {
	Loc

	Array Expression
	Index Expression
	// contains filtered or unexported fields
}

func (*IndexExpression) Copy added in v0.7.1

func (e *IndexExpression) Copy() Node

func (*IndexExpression) FromBuf added in v0.57.0

func (rcv *IndexExpression) FromBuf(fb *fbsemantic.IndexExpression) error

func (*IndexExpression) NodeType added in v0.7.1

func (*IndexExpression) NodeType() string

func (*IndexExpression) TypeOf added in v0.58.0

func (e *IndexExpression) TypeOf() MonoType

type IntegerLiteral

type IntegerLiteral struct {
	Loc
	Value int64
}

func (*IntegerLiteral) Copy

func (l *IntegerLiteral) Copy() Node

func (*IntegerLiteral) FromBuf added in v0.57.0

func (rcv *IntegerLiteral) FromBuf(fb *fbsemantic.IntegerLiteral) error

func (*IntegerLiteral) NodeType

func (*IntegerLiteral) NodeType() string

func (*IntegerLiteral) TypeOf added in v0.58.0

func (e *IntegerLiteral) TypeOf() MonoType

type InterpolatedPart added in v0.41.0

type InterpolatedPart struct {
	Loc
	Expression Expression
}

func (*InterpolatedPart) Copy added in v0.41.0

func (p *InterpolatedPart) Copy() Node

func (*InterpolatedPart) NodeType added in v0.41.0

func (*InterpolatedPart) NodeType() string

type Kind

type Kind fbsemantic.MonoType

Kind specifies a particular kind of monotype.

type Literal

type Literal interface {
	Expression
	// contains filtered or unexported methods
}

type Loc added in v0.68.0

type Loc ast.SourceLocation

func (*Loc) FromBuf added in v0.68.0

func (l *Loc) FromBuf(fb *fbsemantic.SourceLocation) error

func (Loc) Location added in v0.68.0

func (l Loc) Location() ast.SourceLocation

type LogicalExpression

type LogicalExpression struct {
	Loc

	Operator ast.LogicalOperatorKind
	Left     Expression
	Right    Expression
}

func (*LogicalExpression) Copy

func (e *LogicalExpression) Copy() Node

func (*LogicalExpression) FromBuf added in v0.57.0

func (*LogicalExpression) NodeType

func (*LogicalExpression) NodeType() string

func (*LogicalExpression) TypeOf added in v0.58.0

func (e *LogicalExpression) TypeOf() MonoType

type MemberAssignment added in v0.14.0

type MemberAssignment struct {
	Loc

	Member *MemberExpression
	Init   Expression
}

func (*MemberAssignment) Copy added in v0.14.0

func (s *MemberAssignment) Copy() Node

func (*MemberAssignment) FromBuf added in v0.57.0

func (*MemberAssignment) NodeType added in v0.14.0

func (*MemberAssignment) NodeType() string

type MemberExpression

type MemberExpression struct {
	Loc

	Object   Expression
	Property string
	// contains filtered or unexported fields
}

func (*MemberExpression) Copy

func (e *MemberExpression) Copy() Node

func (*MemberExpression) FromBuf added in v0.57.0

func (*MemberExpression) NodeType

func (*MemberExpression) NodeType() string

func (*MemberExpression) TypeOf added in v0.58.0

func (e *MemberExpression) TypeOf() MonoType

type MonoType added in v0.68.0

type MonoType struct {
	// contains filtered or unexported fields
}

MonoType represents a monotype. This struct is a thin wrapper around Go code generated by the FlatBuffers compiler.

func ExtendObjectType added in v0.68.0

func ExtendObjectType(properties []PropertyType, extends *uint64) MonoType

func NewArrayType

func NewArrayType(elemType MonoType) MonoType

NewArrayType will construct a new Array MonoType where the inner element for the array is elemType.

func NewDictType added in v0.96.0

func NewDictType(keyType, valueType MonoType) MonoType

NewDictType will construct a new Dict MonoType where the key element for the dict is keyType and the value element for the dict is valueType.

func NewFunctionType

func NewFunctionType(retn MonoType, args []ArgumentType) MonoType

NewFunctionType will construct a new Function MonoType that has a return value that matches retn and arguments for each of the values in ArgumentType.

func NewMonoType added in v0.68.0

func NewMonoType(tbl flatbuffers.Table, t fbsemantic.MonoType) (MonoType, error)

NewMonoType constructs a new monotype from a FlatBuffers table and the given kind of monotype.

func NewObjectType

func NewObjectType(properties []PropertyType) MonoType

NewObjectType will construct a new Object MonoType with the properties in properties.

The MonoType will be constructed with the properties in the same order as they appear in the array.

func (MonoType) Argument added in v0.68.0

func (mt MonoType) Argument(i int) (*Argument, error)

Argument returns the argument give an ordinal position if this monotype is a function, and an error otherwise.

func (MonoType) Basic added in v0.68.0

func (mt MonoType) Basic() (fbsemantic.Type, error)

Basic returns the basic type for this monotype if it is a basic type, and an error otherwise.

func (MonoType) CanonicalString added in v0.68.0

func (mt MonoType) CanonicalString() string

CanonicalString returns a string representation of this monotype where the tvar numbers are contiguous and indexed starting at zero.

func (MonoType) ElemType added in v0.68.0

func (mt MonoType) ElemType() (MonoType, error)

ElemType returns the element type if this monotype is an array, and an error otherise.

func (MonoType) Equal added in v0.68.0

func (l MonoType) Equal(r MonoType) bool

func (MonoType) Extends added in v0.68.0

func (mt MonoType) Extends() (MonoType, bool, error)

Extends returns the extending type variable if this monotype is a record, and an error otherwise. If the type is a record but does not extend anything a false is returned.

func (MonoType) KeyType added in v0.96.0

func (mt MonoType) KeyType() (MonoType, error)

KeyType returns the type for the key in a Dictionary.

func (MonoType) Kind added in v0.68.0

func (mt MonoType) Kind() Kind

Kind returns what kind of monotype the receiver is.

func (MonoType) Nature added in v0.68.0

func (mt MonoType) Nature() Nature

func (MonoType) NumArguments added in v0.68.0

func (mt MonoType) NumArguments() (int, error)

NumArguments returns the number of arguments if this monotype is a function, and an error otherwise.

func (MonoType) NumProperties added in v0.68.0

func (mt MonoType) NumProperties() (int, error)

NumProperties returns the number of properties if this monotype is a record, and an error otherwise.

func (MonoType) PipeArgument added in v0.81.0

func (mt MonoType) PipeArgument() (*Argument, error)

PipeArgument will return the pipe argument if this monotype is a function and it has a pipe argument. If this monotype is a function with no pipe argument, nil will be returned. If this monotype is not a function, an error will be returned.

func (MonoType) RecordProperty added in v0.81.0

func (mt MonoType) RecordProperty(i int) (*RecordProperty, error)

RecordProperty returns a property given its ordinal position if this monotype is a record, and an error otherwise.

func (MonoType) ReturnType added in v0.68.0

func (mt MonoType) ReturnType() (MonoType, error)

func (MonoType) SortedArguments added in v0.68.0

func (mt MonoType) SortedArguments() ([]*Argument, error)

SortedArguments returns a slice of function arguments, sorted by argument name, if this monotype is a function.

func (MonoType) SortedProperties added in v0.68.0

func (mt MonoType) SortedProperties() ([]*RecordProperty, error)

SortedProperties returns the properties for a Record monotype, sorted by key. It's possible that there are duplicate keys with different types, in this case, this function preserves their order.

func (MonoType) String added in v0.68.0

func (mt MonoType) String() string

String returns a string representation of this monotype.

func (MonoType) ValueType added in v0.96.0

func (mt MonoType) ValueType() (MonoType, error)

ValueType returns the type for the value in a Dictionary.

func (MonoType) VarNum added in v0.68.0

func (mt MonoType) VarNum() (uint64, error)

VarNum returns the type variable number if this monotype is a type variable, and an error otherwise.

type NativeVariableAssignment added in v0.8.0

type NativeVariableAssignment struct {
	Loc

	Identifier *Identifier
	Init       Expression

	Typ PolyType
}

func (*NativeVariableAssignment) Copy added in v0.8.0

func (s *NativeVariableAssignment) Copy() Node

func (*NativeVariableAssignment) FromBuf added in v0.57.0

func (*NativeVariableAssignment) NodeType added in v0.8.0

func (*NativeVariableAssignment) NodeType() string

type Nature

type Nature int

Nature is the primitive description of a type.

const (
	Invalid Nature = iota
	String
	Bytes
	Int
	UInt
	Float
	Bool
	Time
	Duration
	Regexp
	Array
	Object
	Function
	Dictionary
	Vector
)

func (Nature) String

func (n Nature) String() string

type NestingVisitor

type NestingVisitor interface {
	Visitor
	Nest() NestingVisitor
}

type Node

type Node interface {
	NodeType() string
	Copy() Node

	Location() ast.SourceLocation
	// contains filtered or unexported methods
}

type ObjectExpression

type ObjectExpression struct {
	Loc

	With       *IdentifierExpression
	Properties []*Property
	// contains filtered or unexported fields
}

func (*ObjectExpression) Copy

func (e *ObjectExpression) Copy() Node

func (*ObjectExpression) FromBuf added in v0.57.0

func (*ObjectExpression) NodeType

func (*ObjectExpression) NodeType() string

func (*ObjectExpression) TypeOf added in v0.58.0

func (e *ObjectExpression) TypeOf() MonoType

type OptionStatement

type OptionStatement struct {
	Loc

	Assignment Assignment
}

func (*OptionStatement) Copy

func (s *OptionStatement) Copy() Node

func (*OptionStatement) FromBuf added in v0.57.0

func (rcv *OptionStatement) FromBuf(fb *fbsemantic.OptionStatement) error

func (*OptionStatement) NodeType

func (s *OptionStatement) NodeType() string

type Package added in v0.8.0

type Package struct {
	Loc

	Package string
	Files   []*File
}

func DeserializeFromFlatBuffer added in v0.57.0

func DeserializeFromFlatBuffer(buf []byte) (*Package, error)

func New

func New(pkg *ast.Package) (*Package, error)

New creates a semantic graph from the provided AST

func (*Package) Copy added in v0.13.0

func (p *Package) Copy() Node

func (*Package) FromBuf added in v0.57.0

func (rcv *Package) FromBuf(fb *fbsemantic.Package) error

func (*Package) NodeType added in v0.13.0

func (*Package) NodeType() string

type PackageClause added in v0.8.0

type PackageClause struct {
	Loc

	Name *Identifier
}

func (*PackageClause) Copy added in v0.8.0

func (p *PackageClause) Copy() Node

func (*PackageClause) FromBuf added in v0.57.0

func (rcv *PackageClause) FromBuf(fb *fbsemantic.PackageClause) error

func (*PackageClause) NodeType added in v0.8.0

func (*PackageClause) NodeType() string

type PolyType

type PolyType struct {
	// contains filtered or unexported fields
}

PolyType represents a polytype. This struct is a thin wrapper around Go code generated by the FlatBuffers compiler.

func NewPolyType added in v0.68.0

func NewPolyType(fb *fbsemantic.PolyType) (PolyType, error)

NewPolyType returns a new polytype given a flatbuffers polytype.

func (PolyType) CanonicalString added in v0.68.0

func (pt PolyType) CanonicalString() string

CanonicalString returns a string representation for this polytype, where the tvar numbers are contiguous and indexed starting at zero. Tvar numbers are ordered by the order they appear in the monotype expression.

func (PolyType) Constraint added in v0.68.0

func (pt PolyType) Constraint(i int) (*fbsemantic.Constraint, error)

Constraint returns the constraint at ordinal position i.

func (PolyType) Expr added in v0.68.0

func (pt PolyType) Expr() (MonoType, error)

Expr returns the monotype expression for this polytype.

func (PolyType) IsNil added in v0.68.0

func (pt PolyType) IsNil() bool

For testing we need an exported method that checks whether PolyType.fb is nil.

func (PolyType) NumConstraints added in v0.68.0

func (pt PolyType) NumConstraints() int

NumConstraints returns the number of kind constraints in this polytype.

func (PolyType) NumVars added in v0.68.0

func (pt PolyType) NumVars() int

NumVars returns the number of type variables in this polytype.

func (*PolyType) SortedConstraints added in v0.68.0

func (pt *PolyType) SortedConstraints() ([]*fbsemantic.Constraint, error)

SortedConstraints returns the constraints for this polytype sorted by type variable and constraint kind.

func (PolyType) SortedVars added in v0.68.0

func (pt PolyType) SortedVars() ([]*fbsemantic.Var, error)

func (PolyType) String added in v0.68.0

func (pt PolyType) String() string

String returns a string representation for this polytype.

func (PolyType) Var added in v0.68.0

func (pt PolyType) Var(i int) (*fbsemantic.Var, error)

Var returns the type variable at ordinal position i.

type Property

type Property struct {
	Loc

	Key   PropertyKey
	Value Expression
}

func (*Property) Copy

func (p *Property) Copy() Node

func (*Property) FromBuf added in v0.57.0

func (rcv *Property) FromBuf(fb *fbsemantic.Property) error

func (*Property) NodeType

func (*Property) NodeType() string

type PropertyKey added in v0.12.0

type PropertyKey interface {
	Node
	Key() string
}

type PropertyType added in v0.68.0

type PropertyType struct {
	Key   []byte
	Value MonoType
}

type RecordProperty added in v0.81.0

type RecordProperty struct {
	// contains filtered or unexported fields
}

Property represents a property of a record.

func (*RecordProperty) Name added in v0.81.0

func (p *RecordProperty) Name() string

Name returns the name of the property.

func (*RecordProperty) TypeOf added in v0.81.0

func (p *RecordProperty) TypeOf() (MonoType, error)

TypeOf returns the type of the property.

type RegexpLiteral

type RegexpLiteral struct {
	Loc
	Value *regexp.Regexp
}

func (*RegexpLiteral) Copy

func (l *RegexpLiteral) Copy() Node

func (*RegexpLiteral) FromBuf added in v0.57.0

func (rcv *RegexpLiteral) FromBuf(fb *fbsemantic.RegexpLiteral) error

func (*RegexpLiteral) NodeType

func (*RegexpLiteral) NodeType() string

func (*RegexpLiteral) TypeOf added in v0.58.0

func (e *RegexpLiteral) TypeOf() MonoType

type ReturnStatement

type ReturnStatement struct {
	Loc

	Argument Expression
}

func (*ReturnStatement) Copy

func (s *ReturnStatement) Copy() Node

func (*ReturnStatement) FromBuf added in v0.57.0

func (rcv *ReturnStatement) FromBuf(fb *fbsemantic.ReturnStatement) error

func (*ReturnStatement) NodeType

func (*ReturnStatement) NodeType() string

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 Statement

type Statement interface {
	Node
	// contains filtered or unexported methods
}

type StringExpression added in v0.41.0

type StringExpression struct {
	Loc
	Parts []StringExpressionPart
}

func (*StringExpression) Copy added in v0.41.0

func (e *StringExpression) Copy() Node

func (*StringExpression) FromBuf added in v0.57.0

func (*StringExpression) NodeType added in v0.41.0

func (*StringExpression) NodeType() string

func (*StringExpression) TypeOf added in v0.58.0

func (e *StringExpression) TypeOf() MonoType

type StringExpressionPart added in v0.41.0

type StringExpressionPart interface {
	Node
	// contains filtered or unexported methods
}

type StringLiteral

type StringLiteral struct {
	Loc
	Value string
}

func (*StringLiteral) Copy

func (l *StringLiteral) Copy() Node

func (*StringLiteral) FromBuf added in v0.57.0

func (rcv *StringLiteral) FromBuf(fb *fbsemantic.StringLiteral) error

func (*StringLiteral) Key added in v0.12.0

func (n *StringLiteral) Key() string

func (*StringLiteral) NodeType

func (*StringLiteral) NodeType() string

func (*StringLiteral) TypeOf added in v0.58.0

func (e *StringLiteral) TypeOf() MonoType

type TestStatement added in v0.19.0

type TestStatement struct {
	Loc

	Assignment *NativeVariableAssignment
}

func (*TestStatement) Copy added in v0.19.0

func (s *TestStatement) Copy() Node

func (*TestStatement) FromBuf added in v0.57.0

func (rcv *TestStatement) FromBuf(fb *fbsemantic.TestStatement) error

func (*TestStatement) NodeType added in v0.19.0

func (s *TestStatement) NodeType() string

type TextPart added in v0.41.0

type TextPart struct {
	Loc
	Value string
}

func (*TextPart) Copy added in v0.41.0

func (p *TextPart) Copy() Node

func (*TextPart) NodeType added in v0.41.0

func (*TextPart) NodeType() string

type UnaryExpression

type UnaryExpression struct {
	Loc

	Operator ast.OperatorKind
	Argument Expression
	// contains filtered or unexported fields
}

func (*UnaryExpression) Copy

func (e *UnaryExpression) Copy() Node

func (*UnaryExpression) FromBuf added in v0.57.0

func (rcv *UnaryExpression) FromBuf(fb *fbsemantic.UnaryExpression) error

func (*UnaryExpression) NodeType

func (*UnaryExpression) NodeType() string

func (*UnaryExpression) TypeOf added in v0.58.0

func (e *UnaryExpression) TypeOf() MonoType

type UnsignedIntegerLiteral

type UnsignedIntegerLiteral struct {
	Loc
	Value uint64
}

func (*UnsignedIntegerLiteral) Copy

func (l *UnsignedIntegerLiteral) Copy() Node

func (*UnsignedIntegerLiteral) FromBuf added in v0.57.0

func (*UnsignedIntegerLiteral) NodeType

func (*UnsignedIntegerLiteral) NodeType() string

func (*UnsignedIntegerLiteral) TypeOf added in v0.58.0

func (e *UnsignedIntegerLiteral) TypeOf() MonoType

type Visitor

type Visitor interface {
	Visit(node Node) Visitor
	Done(node Node)
}

func CreateVisitor

func CreateVisitor(f func(Node)) Visitor

Directories

Path Synopsis
Package semantictest contains utilities for testing the semantic package.
Package semantictest contains utilities for testing the semantic package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL