semantic

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2018 License: AGPL-3.0, AGPL-3.0-or-later Imports: 12 Imported by: 0

Documentation

Overview

The semantic package provides a graph structure that represents the meaning of an IFQL script. An AST is converted into a semantic graph for use with other systems. Using a semantic graph representation of the IFQL, enables highlevel meaning to be specified programatically.

The semantic structures are to be designed to facilitate the interpretation and compilation of IFQL.

For example since IFQL 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

This section is empty.

Variables

View Source
var EmptyArrayType = NewArrayType(Nil)
View Source
var EmptyObject = NewObjectType(nil)

Functions

func ApplyNewDeclarations

func ApplyNewDeclarations(n Node, declarations map[string]VariableDeclaration)

func Walk

func Walk(v Visitor, node Node)

Types

type ArrayExpression

type ArrayExpression struct {
	Elements []Expression `json:"elements"`
	// contains filtered or unexported fields
}

func (*ArrayExpression) Copy

func (e *ArrayExpression) Copy() Node

func (*ArrayExpression) MarshalJSON

func (e *ArrayExpression) MarshalJSON() ([]byte, error)

func (*ArrayExpression) NodeType

func (*ArrayExpression) NodeType() string

func (*ArrayExpression) Type

func (e *ArrayExpression) Type() Type

func (*ArrayExpression) UnmarshalJSON

func (e *ArrayExpression) UnmarshalJSON(data []byte) error

type BinaryExpression

type BinaryExpression struct {
	Operator ast.OperatorKind `json:"operator"`
	Left     Expression       `json:"left"`
	Right    Expression       `json:"right"`
}

func (*BinaryExpression) Copy

func (e *BinaryExpression) Copy() Node

func (*BinaryExpression) MarshalJSON

func (e *BinaryExpression) MarshalJSON() ([]byte, error)

func (*BinaryExpression) NodeType

func (*BinaryExpression) NodeType() string

func (*BinaryExpression) Type

func (e *BinaryExpression) Type() Type

func (*BinaryExpression) UnmarshalJSON

func (e *BinaryExpression) UnmarshalJSON(data []byte) error

type BlockStatement

type BlockStatement struct {
	Body []Statement `json:"body"`
}

func (*BlockStatement) Copy

func (s *BlockStatement) Copy() Node

func (*BlockStatement) MarshalJSON

func (s *BlockStatement) MarshalJSON() ([]byte, error)

func (*BlockStatement) NodeType

func (*BlockStatement) NodeType() string

func (*BlockStatement) ReturnStatement

func (s *BlockStatement) ReturnStatement() *ReturnStatement

func (*BlockStatement) UnmarshalJSON

func (s *BlockStatement) UnmarshalJSON(data []byte) error

type BooleanLiteral

type BooleanLiteral struct {
	Value bool `json:"value"`
}

func (*BooleanLiteral) Copy

func (l *BooleanLiteral) Copy() Node

func (*BooleanLiteral) MarshalJSON

func (l *BooleanLiteral) MarshalJSON() ([]byte, error)

func (*BooleanLiteral) NodeType

func (*BooleanLiteral) NodeType() string

func (*BooleanLiteral) Type

func (*BooleanLiteral) Type() Type

type CallExpression

type CallExpression struct {
	Callee    Expression        `json:"callee"`
	Arguments *ObjectExpression `json:"arguments"`
}

func (*CallExpression) Copy

func (e *CallExpression) Copy() Node

func (*CallExpression) MarshalJSON

func (e *CallExpression) MarshalJSON() ([]byte, error)

func (*CallExpression) NodeType

func (*CallExpression) NodeType() string

func (*CallExpression) Type

func (e *CallExpression) Type() Type

func (*CallExpression) UnmarshalJSON

func (e *CallExpression) UnmarshalJSON(data []byte) error

type ConditionalExpression

type ConditionalExpression struct {
	Test       Expression `json:"test"`
	Alternate  Expression `json:"alternate"`
	Consequent Expression `json:"consequent"`
}

func (*ConditionalExpression) Copy

func (e *ConditionalExpression) Copy() Node

func (*ConditionalExpression) MarshalJSON

func (e *ConditionalExpression) MarshalJSON() ([]byte, error)

func (*ConditionalExpression) NodeType

func (*ConditionalExpression) NodeType() string

func (*ConditionalExpression) UnmarshalJSON

func (e *ConditionalExpression) UnmarshalJSON(data []byte) error

type DateTimeLiteral

type DateTimeLiteral struct {
	Value time.Time `json:"value"`
}

func (*DateTimeLiteral) Copy

func (l *DateTimeLiteral) Copy() Node

func (*DateTimeLiteral) MarshalJSON

func (l *DateTimeLiteral) MarshalJSON() ([]byte, error)

func (*DateTimeLiteral) NodeType

func (*DateTimeLiteral) NodeType() string

func (*DateTimeLiteral) Type

func (*DateTimeLiteral) Type() Type

type DeclarationScope

type DeclarationScope map[string]VariableDeclaration

func (DeclarationScope) Copy

type DurationLiteral

type DurationLiteral struct {
	Value time.Duration `json:"value"`
}

func (*DurationLiteral) Copy

func (l *DurationLiteral) Copy() Node

func (*DurationLiteral) MarshalJSON

func (l *DurationLiteral) MarshalJSON() ([]byte, error)

func (*DurationLiteral) NodeType

func (*DurationLiteral) NodeType() string

func (*DurationLiteral) Type

func (*DurationLiteral) Type() Type

func (*DurationLiteral) UnmarshalJSON

func (l *DurationLiteral) UnmarshalJSON(data []byte) error

type Expression

type Expression interface {
	Node
	Type() Type
	// contains filtered or unexported methods
}

type ExpressionStatement

type ExpressionStatement struct {
	Expression Expression `json:"expression"`
}

func (*ExpressionStatement) Copy

func (s *ExpressionStatement) Copy() Node

func (*ExpressionStatement) MarshalJSON

func (s *ExpressionStatement) MarshalJSON() ([]byte, error)

func (*ExpressionStatement) NodeType

func (*ExpressionStatement) NodeType() string

func (*ExpressionStatement) UnmarshalJSON

func (s *ExpressionStatement) UnmarshalJSON(data []byte) error

type ExternalVariableDeclaration

type ExternalVariableDeclaration struct {
	Identifier *Identifier `json:"identifier"`
	Type       Type        `json:"type"`
}

func NewExternalVariableDeclaration

func NewExternalVariableDeclaration(name string, typ Type) *ExternalVariableDeclaration

func (*ExternalVariableDeclaration) Copy

func (*ExternalVariableDeclaration) ID

func (*ExternalVariableDeclaration) InitType

func (d *ExternalVariableDeclaration) InitType() Type

func (*ExternalVariableDeclaration) MarshalJSON

func (d *ExternalVariableDeclaration) MarshalJSON() ([]byte, error)

func (*ExternalVariableDeclaration) NodeType

func (*ExternalVariableDeclaration) NodeType() string

type FloatLiteral

type FloatLiteral struct {
	Value float64 `json:"value"`
}

func (*FloatLiteral) Copy

func (l *FloatLiteral) Copy() Node

func (*FloatLiteral) MarshalJSON

func (l *FloatLiteral) MarshalJSON() ([]byte, error)

func (*FloatLiteral) NodeType

func (*FloatLiteral) NodeType() string

func (*FloatLiteral) Type

func (*FloatLiteral) Type() Type

type FunctionExpression

type FunctionExpression struct {
	Params []*FunctionParam `json:"params"`
	Body   Node             `json:"body"`
	// contains filtered or unexported fields
}

func (*FunctionExpression) Copy

func (e *FunctionExpression) Copy() Node

func (*FunctionExpression) MarshalJSON

func (e *FunctionExpression) MarshalJSON() ([]byte, error)

func (*FunctionExpression) NodeType

func (*FunctionExpression) NodeType() string

func (*FunctionExpression) Type

func (e *FunctionExpression) Type() Type

func (*FunctionExpression) UnmarshalJSON

func (e *FunctionExpression) UnmarshalJSON(data []byte) error

type FunctionParam

type FunctionParam struct {
	Key     *Identifier `json:"key"`
	Default Expression  `json:"default"`
	Piped   bool        `json:"piped,omitempty"`
	// contains filtered or unexported fields
}

func (*FunctionParam) Copy

func (p *FunctionParam) Copy() Node

func (*FunctionParam) MarshalJSON

func (e *FunctionParam) MarshalJSON() ([]byte, error)

func (*FunctionParam) NodeType

func (*FunctionParam) NodeType() string

func (*FunctionParam) Type

func (f *FunctionParam) Type() Type

func (*FunctionParam) UnmarshalJSON

func (e *FunctionParam) UnmarshalJSON(data []byte) error

type FunctionSignature

type FunctionSignature struct {
	Params       map[string]Type
	ReturnType   Type
	PipeArgument string
}

type Identifier

type Identifier struct {
	Name string `json:"name"`
}

func (*Identifier) Copy

func (i *Identifier) Copy() Node

func (*Identifier) MarshalJSON

func (i *Identifier) MarshalJSON() ([]byte, error)

func (*Identifier) NodeType

func (*Identifier) NodeType() string

type IdentifierExpression

type IdentifierExpression struct {
	Name string `json:"name"`
	// contains filtered or unexported fields
}

func (*IdentifierExpression) Copy

func (e *IdentifierExpression) Copy() Node

func (*IdentifierExpression) MarshalJSON

func (e *IdentifierExpression) MarshalJSON() ([]byte, error)

func (*IdentifierExpression) NodeType

func (*IdentifierExpression) NodeType() string

func (*IdentifierExpression) Type

func (e *IdentifierExpression) Type() Type

type IntegerLiteral

type IntegerLiteral struct {
	Value int64 `json:"value"`
}

func (*IntegerLiteral) Copy

func (l *IntegerLiteral) Copy() Node

func (*IntegerLiteral) MarshalJSON

func (l *IntegerLiteral) MarshalJSON() ([]byte, error)

func (*IntegerLiteral) NodeType

func (*IntegerLiteral) NodeType() string

func (*IntegerLiteral) Type

func (*IntegerLiteral) Type() Type

func (*IntegerLiteral) UnmarshalJSON

func (l *IntegerLiteral) UnmarshalJSON(data []byte) error

type Kind

type Kind int
const (
	Invalid Kind = iota
	Nil
	String
	Int
	UInt
	Float
	Bool
	Time
	Duration
	Regexp
	Array
	Object
	Function
)

func (Kind) ElementType

func (k Kind) ElementType() Type

func (Kind) Kind

func (k Kind) Kind() Kind

func (Kind) PipeArgument

func (k Kind) PipeArgument() string

func (Kind) Properties

func (k Kind) Properties() map[string]Type

func (Kind) PropertyType

func (k Kind) PropertyType(name string) Type

func (Kind) ReturnType

func (k Kind) ReturnType() Type

func (Kind) String

func (k Kind) String() string

type Literal

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

type LogicalExpression

type LogicalExpression struct {
	Operator ast.LogicalOperatorKind `json:"operator"`
	Left     Expression              `json:"left"`
	Right    Expression              `json:"right"`
}

func (*LogicalExpression) Copy

func (e *LogicalExpression) Copy() Node

func (*LogicalExpression) MarshalJSON

func (e *LogicalExpression) MarshalJSON() ([]byte, error)

func (*LogicalExpression) NodeType

func (*LogicalExpression) NodeType() string

func (*LogicalExpression) Type

func (*LogicalExpression) Type() Type

func (*LogicalExpression) UnmarshalJSON

func (e *LogicalExpression) UnmarshalJSON(data []byte) error

type MemberExpression

type MemberExpression struct {
	Object   Expression `json:"object"`
	Property string     `json:"property"`
}

func (*MemberExpression) Copy

func (e *MemberExpression) Copy() Node

func (*MemberExpression) MarshalJSON

func (e *MemberExpression) MarshalJSON() ([]byte, error)

func (*MemberExpression) NodeType

func (*MemberExpression) NodeType() string

func (*MemberExpression) Type

func (e *MemberExpression) Type() Type

func (*MemberExpression) UnmarshalJSON

func (e *MemberExpression) UnmarshalJSON(data []byte) error

type NativeVariableDeclaration

type NativeVariableDeclaration struct {
	Identifier *Identifier `json:"identifier"`
	Init       Expression  `json:"init"`
}

func (*NativeVariableDeclaration) Copy

func (s *NativeVariableDeclaration) Copy() Node

func (*NativeVariableDeclaration) ID

func (*NativeVariableDeclaration) InitType

func (d *NativeVariableDeclaration) InitType() Type

func (*NativeVariableDeclaration) MarshalJSON

func (d *NativeVariableDeclaration) MarshalJSON() ([]byte, error)

func (*NativeVariableDeclaration) NodeType

func (*NativeVariableDeclaration) NodeType() string

func (*NativeVariableDeclaration) UnmarshalJSON

func (d *NativeVariableDeclaration) UnmarshalJSON(data []byte) error

type Node

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

	json.Marshaler
	// contains filtered or unexported methods
}

func UnmarshalNode

func UnmarshalNode(data []byte) (Node, error)

type ObjectExpression

type ObjectExpression struct {
	Properties []*Property `json:"properties"`
	// contains filtered or unexported fields
}

func (*ObjectExpression) Copy

func (e *ObjectExpression) Copy() Node

func (*ObjectExpression) MarshalJSON

func (e *ObjectExpression) MarshalJSON() ([]byte, error)

func (*ObjectExpression) NodeType

func (*ObjectExpression) NodeType() string

func (*ObjectExpression) Type

func (e *ObjectExpression) Type() Type

type Program

type Program struct {
	Body []Statement `json:"body"`
}

func New

func New(prog *ast.Program, declarations map[string]VariableDeclaration) (*Program, error)

New creates a semantic graph from the provided AST and builtin declarations The declarations will be modified for any variable declaration found in the program.

func (*Program) Copy

func (p *Program) Copy() Node

func (*Program) MarshalJSON

func (p *Program) MarshalJSON() ([]byte, error)

func (*Program) NodeType

func (*Program) NodeType() string

func (*Program) UnmarshalJSON

func (p *Program) UnmarshalJSON(data []byte) error

type Property

type Property struct {
	Key   *Identifier `json:"key"`
	Value Expression  `json:"value"`
}

func (*Property) Copy

func (p *Property) Copy() Node

func (*Property) MarshalJSON

func (p *Property) MarshalJSON() ([]byte, error)

func (*Property) NodeType

func (*Property) NodeType() string

func (*Property) UnmarshalJSON

func (p *Property) UnmarshalJSON(data []byte) error

type RegexpLiteral

type RegexpLiteral struct {
	Value *regexp.Regexp `json:"value"`
}

func (*RegexpLiteral) Copy

func (l *RegexpLiteral) Copy() Node

func (*RegexpLiteral) MarshalJSON

func (l *RegexpLiteral) MarshalJSON() ([]byte, error)

func (*RegexpLiteral) NodeType

func (*RegexpLiteral) NodeType() string

func (*RegexpLiteral) Type

func (*RegexpLiteral) Type() Type

func (*RegexpLiteral) UnmarshalJSON

func (l *RegexpLiteral) UnmarshalJSON(data []byte) error

type ReturnStatement

type ReturnStatement struct {
	Argument Expression `json:"argument"`
}

func (*ReturnStatement) Copy

func (s *ReturnStatement) Copy() Node

func (*ReturnStatement) MarshalJSON

func (s *ReturnStatement) MarshalJSON() ([]byte, error)

func (*ReturnStatement) NodeType

func (*ReturnStatement) NodeType() string

func (*ReturnStatement) UnmarshalJSON

func (s *ReturnStatement) UnmarshalJSON(data []byte) error

type Statement

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

type StringLiteral

type StringLiteral struct {
	Value string `json:"value"`
}

func (*StringLiteral) Copy

func (l *StringLiteral) Copy() Node

func (*StringLiteral) MarshalJSON

func (l *StringLiteral) MarshalJSON() ([]byte, error)

func (*StringLiteral) NodeType

func (*StringLiteral) NodeType() string

func (*StringLiteral) Type

func (*StringLiteral) Type() Type

type Type

type Type interface {
	// Kind returns the specific kind of this type.
	Kind() Kind

	// PropertyType returns the type of a given property.
	// It panics if the type's Kind is not Object
	PropertyType(name string) Type

	// Properties returns a map of all property types.
	// It panics if the type's Kind is not Object
	Properties() map[string]Type

	// ElementType return the type of elements in the array.
	// It panics if the type's Kind is not Array.
	ElementType() Type

	// PipeArgument reports the name of the argument that can be pipe into.
	// It panics if the type's Kind is not Function.
	PipeArgument() string

	// ReturnType reports the return type of the function
	// It panics if the type's Kind is not Function.
	ReturnType() Type
	// contains filtered or unexported methods
}

Type is the representation of an IFQL type.

Type values are comparable and as such can be used as map keys and directly comparison using the == operator. Two types are equal if they represent identical types.

DO NOT embed this type into other interfaces or structs as that will invalidate the comparison properties of the interface.

func NewArrayType

func NewArrayType(elementType Type) Type

func NewFunctionType

func NewFunctionType(sig FunctionSignature) Type

func NewObjectType

func NewObjectType(propertyTypes map[string]Type) Type

type UnaryExpression

type UnaryExpression struct {
	Operator ast.OperatorKind `json:"operator"`
	Argument Expression       `json:"argument"`
}

func (*UnaryExpression) Copy

func (e *UnaryExpression) Copy() Node

func (*UnaryExpression) MarshalJSON

func (e *UnaryExpression) MarshalJSON() ([]byte, error)

func (*UnaryExpression) NodeType

func (*UnaryExpression) NodeType() string

func (*UnaryExpression) Type

func (e *UnaryExpression) Type() Type

func (*UnaryExpression) UnmarshalJSON

func (e *UnaryExpression) UnmarshalJSON(data []byte) error

type UnsignedIntegerLiteral

type UnsignedIntegerLiteral struct {
	Value uint64 `json:"value"`
}

func (*UnsignedIntegerLiteral) Copy

func (l *UnsignedIntegerLiteral) Copy() Node

func (*UnsignedIntegerLiteral) MarshalJSON

func (l *UnsignedIntegerLiteral) MarshalJSON() ([]byte, error)

func (*UnsignedIntegerLiteral) NodeType

func (*UnsignedIntegerLiteral) NodeType() string

func (*UnsignedIntegerLiteral) Type

func (*UnsignedIntegerLiteral) Type() Type

func (*UnsignedIntegerLiteral) UnmarshalJSON

func (l *UnsignedIntegerLiteral) UnmarshalJSON(data []byte) error

type VariableDeclaration

type VariableDeclaration interface {
	Node
	ID() *Identifier
	InitType() Type
}

type Visitor

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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