ast

package
v0.0.0-...-e153092 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package ast defines the AST grammar for BJK files. See: https://github.com/setzer22/blackjack

Index

Constants

This section is empty.

Variables

View Source
var Lexer = lexer.MustSimple([]lexer.SimpleRule{
	{"Header", `(?:` + headerStr + `)[ ]*`},
	{"Ident", `[a-zA-Z]\w*`},
	{"Float", `\-?(?:\d*)?\.\d+`},
	{"Int", `\-?(?:\d*)?\d+`},
	{"String", `\"[^\"]*\"`},
	{"Punct", `[-[!@#$%^&*()+_={}\|:;"'<,>.?/]|]`},
	{"Whitespace", `[ \t\n\r]+`},
})

Lexer represents a lexer for the BJK grammar.

View Source
var Parser = participle.MustBuild[BJK](
	participle.Lexer(Lexer),
	participle.Elide("Whitespace"),

	rustUnquoteOption("String"),
)

Parser represents a participle parser for the BJK grammar.

Functions

This section is empty.

Types

type BJK

type BJK struct {
	Version Version `Header @@`

	Graph *Graph `"(" @@* ")"`
}

BJK is the root of a Blackjack file.

func New

func New() *BJK

New returns a new BJK ast, ready to be populated.

func (*BJK) String

func (b *BJK) String() string

type Connection

type Connection struct {
	NodeIdx   uint64 `"node_idx" ":" @Int ","?`
	ParamName string `"param_name" ":" @String ","?`
}

Connection represents a DependencyKind's connection.

type DependencyKind

type DependencyKind struct {
	External   *External   `  "External" "(" @@* ")" ","?`
	Connection *Connection `| "Conection" "(" @@* ")" ","?`
}

DependencyKind is an enum that represents an input's dependency. It is either an External or a Connection, but not both.

type External

type External struct {
	Promoted *string `"promoted" ":" ( "Some" "(" @String ")" | "None" ) ","?`
}

External represents an external dependency kind.

type ExternalParameters

type ExternalParameters struct {
	ParamValues []*ParamValue `"(" "param_values" ":" "{" @@* "}" ","? ")" ","?`
}

ExternalParameters represents external parameters.

func (*ExternalParameters) String

func (ep *ExternalParameters) String() string

type Graph

type Graph struct {
	Nodes []*Node `"nodes" ":" "[" ( "(" @@* ")" ","? )* "]" ","?`

	DefaultNode *uint64 `( "default_node" ":" ( "Some" "(" @Int ")" | "None" ) ","? )?`

	UIData *UIData `( "ui_data" ":" ( "Some" "(" @@ ")" | "None" ) ","? )?`

	ExternalParameters *ExternalParameters `( "external_parameters" ":"  ( "Some" "(" @@ ")" | "None" ) ","? )?`
}

Graph represents the content of the Blackjack file.

func (*Graph) String

func (g *Graph) String() string

type Input

type Input struct {
	Name     string         `"name" ":" @String ","*`
	DataType string         `"data_type" ":" @String ","*`
	Kind     DependencyKind `"kind" ":" @@ ","*`

	// Props are not preserved in the BJK file.
	Props map[string]lua.LValue
}

Input represents a node's input.

func (*Input) String

func (in *Input) String() string

type Node

type Node struct {
	OpName      string    `"op_name" ":" @String ","?` // e.g. "MakeScalar"
	ReturnValue *string   `"return_value" ":" ( "Some" "(" @String ")" | "None" ) ","?`
	Inputs      []*Input  `"inputs" ":" "[" ( "(" @@* ")" ","? )* "]" ","?`
	Outputs     []*Output `"outputs" ":" "[" ( "(" @@* ")" ","? )* "]" ","?`

	// Label is not preserved in the BJK file.
	Label string // e.g. "Scalar"
	// Index is not preserved in the BJK file.
	Index uint64
	// NodePosition, if set, is used to manually position the node.
	NodePosition *Vec2

	// EvalOutputs are generated by Eval but not preserved in the BJK file.
	EvalOutputs map[string]lua.LValue
}

Node represents a node in Blackjack.

func (*Node) GetInput

func (n *Node) GetInput(name string) (*Input, bool)

GetInput returns a named input or `nil, false` if not found.

func (*Node) GetInputs

func (n *Node) GetInputs() []string

GetInputs returns a slice of input names.

func (*Node) GetOutput

func (n *Node) GetOutput(name string) (*Output, bool)

GetOutput returns a named output or `nil, false` if not found.

func (*Node) GetOutputs

func (n *Node) GetOutputs() []string

GetOutputs returns a slice of output names.

func (*Node) String

func (n *Node) String() string

type Output

type Output struct {
	Name     string `"name" ":" @String ","*`
	DataType string `"data_type" ":" @String ","*`
}

Output represents a node's output.

func (*Output) String

func (out *Output) String() string

type ParamValue

type ParamValue struct {
	NodeIdx   uint64 `"(" "node_idx" ":" @Int ","?`
	ParamName string `"param_name" ":" @String ","? ")" ":"`

	ValueEnum ValueEnum `@@`
}

ParamValue is an enum that represents a parameter value. It is exactly one of the values.

func (*ParamValue) String

func (pv *ParamValue) String() string

type ScalarValue

type ScalarValue struct {
	X float64 `"Scalar" "(" @Float ")" ","?`
}

ScalarValue is one type of ParamValue.

func (*ScalarValue) String

func (sv *ScalarValue) String() string

type SelectionValue

type SelectionValue struct {
	Selection string `"String" "(" @String ")" ","?`
}

SelectionValue is one type of ParamValue.

func (*SelectionValue) String

func (sv *SelectionValue) String() string

type StringValue

type StringValue struct {
	S string `"String" "(" @String ")" ","?`
}

StringValue is one type of ParamValue.

func (*StringValue) String

func (sv *StringValue) String() string

type UIData

type UIData struct {
	NodePositions    []*Vec2  `"(" "node_positions" ":" "[" @@* "]" ","?`
	NodeOrder        []uint64 `"node_order" ":" "[" ( @Int ","? )* "]" ","?`
	Pan              Vec2     `"pan" ":" @@ ","?`
	Zoom             float64  `"zoom" ":" @Float ","?`
	LockedGizmoNodes []uint64 `"locked_gizmo_nodes" ":" "["  ( @Int ","? )* "]" ","? ")" ","?`
}

UIData represents data to drive the user interface.

func (*UIData) String

func (ui *UIData) String() string

type ValueEnum

type ValueEnum struct {
	Scalar    *ScalarValue    `  @@`
	Selection *SelectionValue `| @@`
	StrVal    *StringValue    `| @@`
	Vector    *VectorValue    `| @@`
}

ValueEnum represents an enum for a ParamValue.

func (ValueEnum) String

func (ev ValueEnum) String() string

type Vec2

type Vec2 struct {
	X float64 `"(" @Float ","`
	Y float64 `@Float ")" ","?`
}

Vec2 represents a 2D vector (or point).

type VectorValue

type VectorValue struct {
	X float64 `"Vector" "(" "(" @Float ","`
	Y float64 `@Float ","`
	Z float64 `@Float ")" ")" ","?`
}

VectorValue is one type of ParamValue.

func (*VectorValue) String

func (vv *VectorValue) String() string

type Version

type Version struct {
	Major int `@Int`
	Minor int `@Int`
	Patch int `@Int`
}

Version represents the version of the Blackjack file.

Jump to

Keyboard shortcuts

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