ast

package
v0.0.0-...-c3230fc Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AtomNode

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

func (*AtomNode) NextPos

func (node *AtomNode) NextPos() lexer.TokenPos

func (*AtomNode) Pos

func (node *AtomNode) Pos() lexer.TokenPos

The Node's position can be inferred from its TokenPos value. Its NextPos() is specific to the actual backing struct, it may depend on child nodes.

func (*AtomNode) SetType

func (nb *AtomNode) SetType(NodeType)

Provide default implementations in the base type that panic or return nil.

func (*AtomNode) SetValue

func (nb *AtomNode) SetValue(v constant.Value)

func (*AtomNode) State

func (node *AtomNode) State() NodeState

func (*AtomNode) String

func (node *AtomNode) String() string

func (*AtomNode) Type

func (node *AtomNode) Type() NodeType

The NodeType for a node determines how tree-walks of surrounding nodes will be conducted. It also provides a more refined typing than the golang type, especially for some nodes that undergo refinement during compilation passes.

func (*AtomNode) Value

func (nb *AtomNode) Value() constant.Value

type BodyRelation

type BodyRelation interface {
	Relation
	// contains filtered or unexported methods
}

Common type for relations that may appear in a body clause of `<=` inference.

type Entity

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

Common type for entities, objects presumed or hypothesized to exist in the game.

func Integer

func Integer(pos lexer.TokenPos, value int) Entity

func RoleReference

func RoleReference(pos lexer.TokenPos, ident Entity) Entity

Construct a new node for a (role ...) relation. Can only appear in body relations, not as a head relation. When it appears as a base sentence it is the definition of that role (see above). Args:

pos marks the beginning of the relation's open paren
name is the identifier of the role being referenced

type Esc

type Esc uint16

Saved for future use; static analysis can use this segment for escape note.

type GoalNode

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

func Goal

func Goal(pos lexer.TokenPos, role RoleReferenceNode, body []BodyRelation) *GoalNode

Terminal rules are of the form (<= terminal (...) ...) where the `terminal` keyword is the entire head relation, so we only really need to represent the body relations that the inference is drawn from.

func (*GoalNode) NextPos

func (node *GoalNode) NextPos() lexer.TokenPos

func (*GoalNode) Pos

func (node *GoalNode) Pos() lexer.TokenPos

The Node's position can be inferred from its TokenPos value. Its NextPos() is specific to the actual backing struct, it may depend on child nodes.

func (*GoalNode) SetType

func (nb *GoalNode) SetType(NodeType)

Provide default implementations in the base type that panic or return nil.

func (*GoalNode) SetValue

func (nb *GoalNode) SetValue(v constant.Value)

func (*GoalNode) State

func (node *GoalNode) State() NodeState

func (*GoalNode) String

func (node *GoalNode) String() string

func (*GoalNode) Type

func (node *GoalNode) Type() NodeType

The NodeType for a node determines how tree-walks of surrounding nodes will be conducted. It also provides a more refined typing than the golang type, especially for some nodes that undergo refinement during compilation passes.

func (*GoalNode) Value

func (nb *GoalNode) Value() constant.Value

type GroundFormulaNode

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

func (*GroundFormulaNode) AddGroundTerm

func (node *GroundFormulaNode) AddGroundTerm(term GroundTerm)

func (*GroundFormulaNode) Arity

func (node *GroundFormulaNode) Arity() uint

func (*GroundFormulaNode) Name

func (node *GroundFormulaNode) Name() string

func (*GroundFormulaNode) NextPos

func (node *GroundFormulaNode) NextPos() lexer.TokenPos

func (*GroundFormulaNode) Pos

func (node *GroundFormulaNode) Pos() lexer.TokenPos

The Node's position can be inferred from its TokenPos value. Its NextPos() is specific to the actual backing struct, it may depend on child nodes.

func (*GroundFormulaNode) SetType

func (nb *GroundFormulaNode) SetType(NodeType)

Provide default implementations in the base type that panic or return nil.

func (*GroundFormulaNode) SetValue

func (nb *GroundFormulaNode) SetValue(v constant.Value)

func (*GroundFormulaNode) State

func (node *GroundFormulaNode) State() NodeState

func (*GroundFormulaNode) Type

func (node *GroundFormulaNode) Type() NodeType

The NodeType for a node determines how tree-walks of surrounding nodes will be conducted. It also provides a more refined typing than the golang type, especially for some nodes that undergo refinement during compilation passes.

func (*GroundFormulaNode) Value

func (nb *GroundFormulaNode) Value() constant.Value

type GroundRelation

type GroundRelation interface {
	Relation
	GroundTerm
}

Unifying type for Relations and Ground terms, i.e. entirely ground formulas.

type GroundTerm

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

A ground term is an atom or relation that contains no variable terms. some relations are inherently grounded (non-variable atoms, literals) and can be immediately determined by type, this is the interface type for satisfying thet requirement. Note that a relation may be ground without itself being a direct member of this type, e.g. relation objects. See IsGround(Node) for a runtime test of a node's groundedness.

type HeadRelation

type HeadRelation interface {
	Relation
	// contains filtered or unexported methods
}

Common type for relations that may appear in the head clause of `<=` infer.

type InitRuleNode

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

Init definitions resemble a function that operates on a single relation term, with the expectation that the relation is Ground.

func (*InitRuleNode) NextPos

func (node *InitRuleNode) NextPos() lexer.TokenPos

func (*InitRuleNode) Pos

func (node *InitRuleNode) Pos() lexer.TokenPos

The Node's position can be inferred from its TokenPos value. Its NextPos() is specific to the actual backing struct, it may depend on child nodes.

func (*InitRuleNode) SetType

func (nb *InitRuleNode) SetType(NodeType)

Provide default implementations in the base type that panic or return nil.

func (*InitRuleNode) SetValue

func (nb *InitRuleNode) SetValue(v constant.Value)

func (*InitRuleNode) State

func (node *InitRuleNode) State() NodeState

func (*InitRuleNode) String

func (node *InitRuleNode) String() string

func (*InitRuleNode) Type

func (node *InitRuleNode) Type() NodeType

The NodeType for a node determines how tree-walks of surrounding nodes will be conducted. It also provides a more refined typing than the golang type, especially for some nodes that undergo refinement during compilation passes.

func (*InitRuleNode) Value

func (nb *InitRuleNode) Value() constant.Value

type IntegerNode

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

func (*IntegerNode) NextPos

func (node *IntegerNode) NextPos() lexer.TokenPos

func (*IntegerNode) Pos

func (node *IntegerNode) Pos() lexer.TokenPos

The Node's position can be inferred from its TokenPos value. Its NextPos() is specific to the actual backing struct, it may depend on child nodes.

func (*IntegerNode) SetType

func (nb *IntegerNode) SetType(NodeType)

Provide default implementations in the base type that panic or return nil.

func (*IntegerNode) SetValue

func (nb *IntegerNode) SetValue(v constant.Value)

func (*IntegerNode) State

func (node *IntegerNode) State() NodeState

func (*IntegerNode) String

func (node *IntegerNode) String() string

func (*IntegerNode) Type

func (node *IntegerNode) Type() NodeType

The NodeType for a node determines how tree-walks of surrounding nodes will be conducted. It also provides a more refined typing than the golang type, especially for some nodes that undergo refinement during compilation passes.

func (*IntegerNode) Value

func (nb *IntegerNode) Value() constant.Value

type Node

type Node interface {
	fmt.Stringer
	Pos() lexer.TokenPos
	NextPos() lexer.TokenPos
}

Common interface for all Node types indicates their position and extent. Some additional Node subtypes (below) provide the semantic attribute of entire classes of Node types, selectively implemented by the backing structs that define the individual Node implementing types.

func Atom

func Atom(pos lexer.TokenPos, ident string) Node

Construct a new node for an atom, represented simply as an identifier.

func GroundFormula

func GroundFormula(pos lexer.TokenPos, name string) Node

func InitRule

func InitRule(pos lexer.TokenPos, subrule GroundRelation) Node

Construct a new node for an (init ...) sentence-level production

type NodeFlag

type NodeFlag uint8

Small set of booleans that can be individually toggled or read.

const (
	FLAG_DIRTY  NodeFlag = iota
	FLAG_GROUND          // indicates the entire tree under it is ground.

)

func (*NodeFlag) Read

func (bitset *NodeFlag) Read(flag int) bool

Reads the bit value at `pos` and returns it as a boolean.

func (*NodeFlag) Set

func (bitset *NodeFlag) Set(flag NodeFlag, on bool)

Sets the bit at `pos`, or unsets it, according to `on`.

type NodeIndex

type NodeIndex uint32

A special integer type that refers to its index in a NodePool collection.

type NodePool

type NodePool interface {
	Add(value Node) (index NodeIndex)
	Get(index NodeIndex) Node
}

Exported methods for the NodePool, responsible for the allocation and recycling of backing data for Node instances.

type NodeState

type NodeState uint32

Shorthand for tiny literals or state-machine bits for individual passes.

type NodeType

type NodeType uint8

A brief representation of the node's type for quick type-checking of AST Node instances. GDL types are few and, for the most part, distinct. The domains defined by games in GDL are a separate concern. For example, piece types and board position types could be considered classes and introduced into a type system, but in GDL that representation is a composite of atoms and the shape of relations concerning them, so that problem is contained in the unification of terms. Thus, we can narrow the scope of NodeType to the most primitive of lexical concerns of GDL, with room to grow for Plugg's representation of API entities, UI controls and visual elements.

const (
	NT_INVALID NodeType = iota

	// Identifier naming and constant atoms
	NT_ATOM
	NT_INTEGER
	NT_GROUNDREL
	NT_VAR
	NT_RELATION

	// Boolean operator relations
	NT_TRUE
	NT_OR
	NT_AND
	NT_NOT
	NT_DISTINCT

	// Inference rule relations
	NT_INFER
	NT_NEXT
	NT_LEGAL
	NT_INPUT
	NT_DOES

	// Types that are derived from GDL builtins
	NT_DEFROLE
	NT_ROLEREF
	NT_INIT
	NT_TERMINAL
	NT_GOAL
)

DO NOT DEPEND ON THE STABILITY OF THESE VALUES.

Enumeration of node types to an integer representation.

func (NodeType) String

func (nt NodeType) String() string

type Relation

type Relation interface {
	Node
	Name() string
	Arity() uint
	// contains filtered or unexported methods
}

Common type for relations, objects that give properties to entites or indicating a relationship between entities.

type RoleDefinitionNode

type RoleDefinitionNode struct {
	Name string
	// contains filtered or unexported fields
}

Role definitions are of the form `(role <IDENT>)`, strictly defining the set of player representations.

func (*RoleDefinitionNode) NextPos

func (node *RoleDefinitionNode) NextPos() lexer.TokenPos

func (*RoleDefinitionNode) Pos

func (node *RoleDefinitionNode) Pos() lexer.TokenPos

The Node's position can be inferred from its TokenPos value. Its NextPos() is specific to the actual backing struct, it may depend on child nodes.

func (*RoleDefinitionNode) SetType

func (nb *RoleDefinitionNode) SetType(NodeType)

Provide default implementations in the base type that panic or return nil.

func (*RoleDefinitionNode) SetValue

func (nb *RoleDefinitionNode) SetValue(v constant.Value)

func (*RoleDefinitionNode) State

func (node *RoleDefinitionNode) State() NodeState

func (*RoleDefinitionNode) String

func (node *RoleDefinitionNode) String() string

func (*RoleDefinitionNode) Type

func (node *RoleDefinitionNode) Type() NodeType

The NodeType for a node determines how tree-walks of surrounding nodes will be conducted. It also provides a more refined typing than the golang type, especially for some nodes that undergo refinement during compilation passes.

func (*RoleDefinitionNode) Value

func (nb *RoleDefinitionNode) Value() constant.Value

type RoleReferenceNode

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

Some expressions, such as `legal` and `does`, have parameters that implicitly refer to a role and not any other type of term. We can type-check them more effectively with a Node type that specifies that constraint.

func (*RoleReferenceNode) Arity

func (node *RoleReferenceNode) Arity() uint

func (*RoleReferenceNode) Name

func (node *RoleReferenceNode) Name() string

func (*RoleReferenceNode) NextPos

func (node *RoleReferenceNode) NextPos() lexer.TokenPos

func (*RoleReferenceNode) Pos

func (node *RoleReferenceNode) Pos() lexer.TokenPos

The Node's position can be inferred from its TokenPos value. Its NextPos() is specific to the actual backing struct, it may depend on child nodes.

func (*RoleReferenceNode) SetType

func (nb *RoleReferenceNode) SetType(NodeType)

Provide default implementations in the base type that panic or return nil.

func (*RoleReferenceNode) SetValue

func (nb *RoleReferenceNode) SetValue(v constant.Value)

func (*RoleReferenceNode) State

func (node *RoleReferenceNode) State() NodeState

func (*RoleReferenceNode) String

func (node *RoleReferenceNode) String() string

func (*RoleReferenceNode) Type

func (node *RoleReferenceNode) Type() NodeType

The NodeType for a node determines how tree-walks of surrounding nodes will be conducted. It also provides a more refined typing than the golang type, especially for some nodes that undergo refinement during compilation passes.

func (*RoleReferenceNode) Value

func (nb *RoleReferenceNode) Value() constant.Value

type Sentence

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

Common type for Sentence-level productions.

func RoleDefinition

func RoleDefinition(pos lexer.TokenPos, name string) Sentence

Construct a new node for a (role ...) sentence, defining the players. Args:

`pos` marks the beginning of the sentence
`name` is the indentifier of the role within the game definition

func Terminal

func Terminal(pos lexer.TokenPos, body []BodyRelation) Sentence

Terminal rules are of the form (<= terminal (...) ...) where the `terminal` keyword is the entire head relation, so we only really need to represent the body relations that the inference is drawn from.

type TerminalNode

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

func (*TerminalNode) NextPos

func (node *TerminalNode) NextPos() lexer.TokenPos

func (*TerminalNode) Pos

func (node *TerminalNode) Pos() lexer.TokenPos

The Node's position can be inferred from its TokenPos value. Its NextPos() is specific to the actual backing struct, it may depend on child nodes.

func (*TerminalNode) SetType

func (nb *TerminalNode) SetType(NodeType)

Provide default implementations in the base type that panic or return nil.

func (*TerminalNode) SetValue

func (nb *TerminalNode) SetValue(v constant.Value)

func (*TerminalNode) State

func (node *TerminalNode) State() NodeState

func (*TerminalNode) String

func (node *TerminalNode) String() string

func (*TerminalNode) Type

func (node *TerminalNode) Type() NodeType

The NodeType for a node determines how tree-walks of surrounding nodes will be conducted. It also provides a more refined typing than the golang type, especially for some nodes that undergo refinement during compilation passes.

func (*TerminalNode) Value

func (nb *TerminalNode) Value() constant.Value

type VarNode

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

func Var

func Var(pos lexer.TokenPos, ident string) *VarNode

func (*VarNode) NextPos

func (v *VarNode) NextPos() lexer.TokenPos

func (*VarNode) Pos

func (node *VarNode) Pos() lexer.TokenPos

The Node's position can be inferred from its TokenPos value. Its NextPos() is specific to the actual backing struct, it may depend on child nodes.

func (*VarNode) SetType

func (nb *VarNode) SetType(NodeType)

Provide default implementations in the base type that panic or return nil.

func (*VarNode) SetValue

func (nb *VarNode) SetValue(v constant.Value)

func (*VarNode) State

func (node *VarNode) State() NodeState

func (*VarNode) String

func (v *VarNode) String() string

func (*VarNode) Type

func (node *VarNode) Type() NodeType

The NodeType for a node determines how tree-walks of surrounding nodes will be conducted. It also provides a more refined typing than the golang type, especially for some nodes that undergo refinement during compilation passes.

func (*VarNode) Value

func (nb *VarNode) Value() constant.Value

Jump to

Keyboard shortcuts

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