Documentation
¶
Index ¶
- Variables
- func Parse(r io.Reader) (*Graph, *ParseError)
- func Serialize(g *Graph) string
- type Edge
- type Graph
- func (g *Graph) AddEdge(from, to string, attrs map[string]interface{}) (*Edge, error)
- func (g *Graph) AddExistingEdge(edge *Edge) error
- func (g *Graph) AddExistingNode(node *Node) error
- func (g *Graph) AddExistingSet(set *Set) error
- func (g *Graph) AddNode(id string, attrs map[string]interface{}) (*Node, error)
- func (g *Graph) AddSet(id string, attrs map[string]interface{}) (*Set, error)
- func (g *Graph) Clone() *Graph
- func (g *Graph) GetEdges() []*Edge
- func (g *Graph) GetNode(id string) *Node
- func (g *Graph) GetNodes() map[string]*Node
- func (g *Graph) GetSets() map[string]*Set
- func (g *Graph) RemoveEdge(from, to string) error
- func (g *Graph) RemoveNode(id string) error
- func (g *Graph) SetInternalState(nodes map[string]*Node, edges []*Edge, sets map[string]*Set)
- type Lexer
- type Node
- type NodeRef
- type ParseError
- type Set
- type Token
- type TokenType
Constants ¶
This section is empty.
Variables ¶
var Guides embed.FS
Guides embeds the AI/LLM guide files
Functions ¶
Types ¶
type Edge ¶
type Edge struct {
From string
To string
Attributes map[string]interface{}
Sets map[string]struct{}
}
Edge represents a directed edge in the graph.
func (*Edge) GetBool ¶
GetBool returns the bool value of an edge attribute. Returns (value, true) if the attribute exists and is a bool. Returns (false, false) if the attribute is missing or not a bool.
func (*Edge) GetInt ¶
GetInt returns the int64 value of an edge attribute. Returns (value, true) if the attribute exists and is a number. Returns (0, false) if the attribute is missing or not a number.
func (*Edge) GetString ¶
GetString returns the string value of an edge attribute. Returns (value, true) if the attribute exists and is a string. Returns ("", false) if the attribute is missing or not a string.
func (*Edge) SetAttribute ¶
SetAttribute sets an attribute on an edge. Returns an error if validation fails.
type Graph ¶
type Graph struct {
// contains filtered or unexported fields
}
Graph is the top-level semantic model produced by parsing a GSL document.
func (*Graph) AddEdge ¶
AddEdge adds an edge to the graph. Returns the created edge and an error if validation fails. Validates that both from and to nodes exist.
func (*Graph) AddExistingEdge ¶
AddExistingEdge adds a pre-created edge to the graph, preserving all edge state. Used by graph operations that need to preserve edge attributes and set memberships.
func (*Graph) AddExistingNode ¶
AddExistingNode adds a pre-created node to the graph, preserving all node state. Used by graph operations that need to preserve node attributes and set memberships.
func (*Graph) AddExistingSet ¶
AddExistingSet adds a pre-created set to the graph, preserving all set state. Used by graph operations that need to preserve set attributes.
func (*Graph) AddNode ¶
AddNode adds or updates a node in the graph. Returns the created/updated node and an error if validation fails. If a node with the same ID already exists, it is returned and no error occurs.
func (*Graph) AddSet ¶
AddSet adds or updates a set in the graph. Returns the created/updated set and an error if validation fails. If a set with the same ID already exists, it is returned and no error occurs.
func (*Graph) Clone ¶
Clone creates a deep copy of the graph. All nodes, edges, and sets are copied with their attributes and set memberships. The cloned graph is independent: mutations to the clone do not affect the original.
func (*Graph) GetEdges ¶
GetEdges returns a read-only copy of the graph's edge slice. Changes to the returned slice do not affect the graph.
func (*Graph) GetNodes ¶
GetNodes returns a read-only copy of the graph's node map. Changes to the returned map do not affect the graph.
func (*Graph) GetSets ¶
GetSets returns a read-only copy of the graph's set map. Changes to the returned map do not affect the graph.
func (*Graph) RemoveEdge ¶
RemoveEdge removes an edge from the graph. Returns an error if the edge does not exist.
func (*Graph) RemoveNode ¶
RemoveNode removes a node from the graph. Returns an error if the node does not exist or has dangling edges.
func (*Graph) SetInternalState ¶
SetInternalState sets the internal state of a graph. This is a testing-only method and should not be used in production code. It directly sets nodes, edges, and sets without validation.
type Node ¶
type Node struct {
ID string
Attributes map[string]interface{}
Sets map[string]struct{}
Parent *string // cached from Attributes["parent"] if it's a NodeRef
}
Node represents a node in the graph.
func (*Node) GetBool ¶
GetBool returns the bool value of a node attribute. Returns (value, true) if the attribute exists and is a bool. Returns (false, false) if the attribute is missing or not a bool.
func (*Node) GetInt ¶
GetInt returns the int64 value of a node attribute. Returns (value, true) if the attribute exists and is a number. Returns (0, false) if the attribute is missing or not a number.
func (*Node) GetRef ¶
GetRef returns the NodeRef value of a node attribute. Returns (value, true) if the attribute exists and is a NodeRef. Returns (nil, false) if the attribute is missing or not a NodeRef.
func (*Node) GetString ¶
GetString returns the string value of a node attribute. Returns (value, true) if the attribute exists and is a string. Returns ("", false) if the attribute is missing or not a string.
func (*Node) SetAttribute ¶
SetAttribute sets an attribute on a node. Returns an error if validation fails.
type NodeRef ¶
type NodeRef string
NodeRef is a distinct type for node references in attribute values.
type ParseError ¶
type ParseError struct {
Message string // Main error message (empty if no fatal error)
Warnings []error // Non-fatal parse issues
Err error // Fatal error, if any
}
ParseError represents a structured error from parsing GSL code. It contains a fatal error (if any) and non-fatal warnings discovered during parsing.
func (*ParseError) Error ¶
func (pe *ParseError) Error() string
Error implements the error interface for ParseError.
func (*ParseError) HasError ¶
func (pe *ParseError) HasError() bool
HasError returns true if there was a fatal error.
func (*ParseError) HasWarnings ¶
func (pe *ParseError) HasWarnings() bool
HasWarnings returns true if there were any non-fatal warnings.
type Set ¶
type Set struct {
ID string
Attributes map[string]interface{}
// contains filtered or unexported fields
}
Set represents a named set/grouping.
func (*Set) GetBool ¶
GetBool returns the bool value of a set attribute. Returns (value, true) if the attribute exists and is a bool. Returns (false, false) if the attribute is missing or not a bool.
func (*Set) GetInt ¶
GetInt returns the int64 value of a set attribute. Returns (value, true) if the attribute exists and is a number. Returns (0, false) if the attribute is missing or not a number.
func (*Set) GetString ¶
GetString returns the string value of a set attribute. Returns (value, true) if the attribute exists and is a string. Returns ("", false) if the attribute is missing or not a string.
func (*Set) SetAttribute ¶
SetAttribute sets an attribute on a set. Returns an error if validation fails.
type TokenType ¶
type TokenType int
const ( // Special TOKEN_ILLEGAL TokenType = iota TOKEN_EOF // Literals TOKEN_IDENT TOKEN_STRING TOKEN_NUMBER // Keywords TOKEN_NODE TOKEN_SET TOKEN_TRUE TOKEN_FALSE // Symbols TOKEN_LBRACKET // [ TOKEN_RBRACKET // ] TOKEN_LBRACE // { TOKEN_RBRACE // } TOKEN_COMMA // , TOKEN_EQUALS // = TOKEN_ARROW // -> TOKEN_AT // @ TOKEN_COLON // : )