Documentation
¶
Overview ¶
Package ast defines the Abstract Syntax Tree (AST) nodes for Cypher queries. It provides type definitions for all Cypher language constructs including statements, clauses, expressions, patterns, and literals.
The AST is organized into several categories:
- Node: The base interface for all AST nodes
- Stmt: Statements (Query, MatchStmt, CreateStmt, etc.)
- Clause: Clauses (MatchClause, WhereClause, ReturnClause, etc.)
- Expr: Expressions (BinaryExpr, FuncCall, Ident, etc.)
- Pattern: Patterns (PatternExpr, PathExpr, NodePattern, etc.)
Each node type implements the Node interface with Position(), End(), and String() methods. Additional interfaces (Stmt, Clause, Expr, Pattern) are used to categorize nodes.
Example:
query := &ast.Query{
Statements: []ast.Stmt{
&ast.MatchStmt{
Clauses: []ast.Clause{
&ast.MatchClause{
Pattern: pattern,
},
},
},
},
}
Index ¶
- func Walk(v Visitor, node Node) error
- type BinaryExpr
- type BoolLit
- type CaseExpr
- type Clause
- type CreateClause
- type CreateStmt
- type DeleteClause
- type DeleteStmt
- type Direction
- type ExistsExpr
- type Expr
- type FloatLit
- type FuncCall
- type Ident
- type InExpr
- type IntegerLit
- type IsNullExpr
- type ListComprehension
- type ListExpr
- type ListIndexExpr
- type ListLit
- type ListSliceExpr
- type MapExpr
- type MapLit
- type MapPair
- type MatchClause
- type MatchStmt
- type MergeClause
- type MergeStmt
- type Node
- type NodePattern
- type NullLit
- type OrderByExpr
- type OrderByItem
- type Param
- type ParamExpr
- type PathExpr
- type Pattern
- type PatternComprehension
- type PatternExpr
- type PatternExprItem
- type PatternPart
- type Pos
- type PropertyAccessExpr
- type Query
- type RelationPattern
- type RemoveClause
- type RemoveItemExpr
- type RemoveStmt
- type ReturnClause
- type ReturnExpr
- type ReturnItemExpr
- type ReturnStmt
- type SetClause
- type SetItem
- type SetStmt
- type Stmt
- type StringLit
- type UnaryExpr
- type UnionClause
- type UnwindClause
- type UnwindStmt
- type Visitor
- type Walker
- type WhenClause
- type WhereClause
- type WhereExpr
- type WithClause
- type WithStmt
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BinaryExpr ¶ added in v0.2.0
BinaryExpr represents a binary expression with two operands and an operator. It is used for arithmetic, comparison, and logical operations.
Example Cypher:
n.age > 25 (comparison) a + b (arithmetic) x AND y (logical)
Fields:
- Left: The left operand
- Operator: The binary operator (e.g., +, -, *, /, =, <>, <, >, AND, OR)
- Right: The right operand
- Start: Position in source where this expression begins
- EndPos: Position in source where this expression ends
func (*BinaryExpr) End ¶ added in v0.2.0
func (e *BinaryExpr) End() Pos
End returns the ending position of this expression in the source.
func (*BinaryExpr) Position ¶ added in v0.2.0
func (e *BinaryExpr) Position() Pos
Position returns the starting position of this expression in the source.
func (*BinaryExpr) String ¶ added in v0.2.0
func (e *BinaryExpr) String() string
String returns the operator.
type BoolLit ¶ added in v0.2.0
BoolLit represents a boolean literal expression. It holds a true or false value.
Example Cypher:
true false
Fields:
- Value: The boolean value
- Start: Position in source where this literal begins
- EndPos: Position in source where this literal ends
func (*BoolLit) End ¶ added in v0.2.0
End returns the ending position of this literal in the source.
type CaseExpr ¶ added in v0.2.0
type CaseExpr struct {
Operand Expr
Whens []*WhenClause
Else Expr
Start Pos
EndPos Pos
}
CaseExpr represents a CASE expression for conditional logic. It supports both simple and searched CASE forms.
Example Cypher:
CASE n.age
WHEN 18 THEN 'young'
WHEN 65 THEN 'senior'
ELSE 'adult'
END
CASE
WHEN n.age < 18 THEN 'minor'
WHEN n.age >= 65 THEN 'senior'
ELSE 'adult'
END
Fields:
- Operand: Optional expression for simple CASE (nil for searched CASE)
- Whens: List of WHEN clauses
- Else: Optional ELSE expression
- Start: Position in source where this expression begins
- EndPos: Position in source where this expression ends
func (*CaseExpr) End ¶ added in v0.2.0
End returns the ending position of this expression in the source.
type Clause ¶
type Clause interface {
Node
// contains filtered or unexported methods
}
Clause is the interface for all clause nodes. Clauses are components of statements (e.g., WHERE, RETURN).
In addition to Node methods, Clause implementations must have a clauseNode() method to distinguish them from other node types.
type CreateClause ¶
type CreateClause struct {
Pattern *PatternExpr
Start Pos
EndPos Pos
}
CreateClause represents a CREATE clause in a Cypher query. It creates new nodes and relationships in the graph.
Example Cypher:
CREATE (n:Person {name: 'Alice'})
CREATE (a)-[:KNOWS]->(b)
Fields:
- Pattern: The pattern describing what to create
- Start: Position in source where this clause begins
- EndPos: Position in source where this clause ends
func (*CreateClause) End ¶ added in v0.2.0
func (c *CreateClause) End() Pos
End returns the ending position of this clause in the source.
func (*CreateClause) Position ¶ added in v0.2.0
func (c *CreateClause) Position() Pos
Position returns the starting position of this clause in the source.
func (*CreateClause) String ¶ added in v0.2.0
func (c *CreateClause) String() string
String returns a string representation of this clause.
type CreateStmt ¶ added in v0.2.0
type CreateStmt struct {
Pattern *PatternExpr
Clauses []Clause
Start Pos
EndPos Pos
}
CreateStmt represents a CREATE statement in a Cypher query. It creates new nodes and relationships in the graph.
Example Cypher:
CREATE (n:Person {name: 'Alice', age: 30})
CREATE (a)-[:KNOWS {since: 2020}]->(b)
Fields:
- Pattern: The pattern describing what to create
- Clauses: Additional clauses (e.g., RETURN)
- Start: Position in source where this statement begins
- EndPos: Position in source where this statement ends
func (*CreateStmt) End ¶ added in v0.2.0
func (s *CreateStmt) End() Pos
End returns the ending position of this statement in the source.
func (*CreateStmt) Position ¶ added in v0.2.0
func (s *CreateStmt) Position() Pos
Position returns the starting position of this statement in the source.
func (*CreateStmt) String ¶ added in v0.2.0
func (s *CreateStmt) String() string
String returns "CREATE".
type DeleteClause ¶
DeleteClause represents a DELETE clause in a Cypher query. It deletes nodes and relationships. Use Detach to delete nodes without requiring deletion of their relationships first.
Example Cypher:
DELETE r DETACH DELETE n
Fields:
- Detach: If true, delete nodes and their relationships
- Items: Expressions identifying what to delete
- Start: Position in source where this clause begins
- EndPos: Position in source where this clause ends
func (*DeleteClause) End ¶ added in v0.2.0
func (c *DeleteClause) End() Pos
End returns the ending position of this clause in the source.
func (*DeleteClause) Position ¶ added in v0.2.0
func (c *DeleteClause) Position() Pos
Position returns the starting position of this clause in the source.
func (*DeleteClause) String ¶ added in v0.2.0
func (c *DeleteClause) String() string
String returns a string representation of this clause.
type DeleteStmt ¶ added in v0.2.0
DeleteStmt represents a DELETE statement in a Cypher query. It deletes nodes and relationships.
Example Cypher:
DELETE r DETACH DELETE n
Fields:
- Detach: If true, delete nodes and their relationships
- Items: Expressions identifying what to delete
- Start: Position in source where this statement begins
- EndPos: Position in source where this statement ends
func (*DeleteStmt) End ¶ added in v0.2.0
func (s *DeleteStmt) End() Pos
End returns the ending position of this statement in the source.
func (*DeleteStmt) Position ¶ added in v0.2.0
func (s *DeleteStmt) Position() Pos
Position returns the starting position of this statement in the source.
func (*DeleteStmt) String ¶ added in v0.2.0
func (s *DeleteStmt) String() string
String returns "DELETE" or "DETACH DELETE".
type Direction ¶ added in v0.2.0
type Direction int
Direction represents the direction of a relationship in a pattern. It determines how the relationship connects nodes.
const ( // DirectionBoth indicates a relationship in either direction (no arrow). // Example: (a)--(b) DirectionBoth Direction = iota // DirectionOutgoing indicates an outgoing relationship (right arrow). // Example: (a)-->(b) DirectionOutgoing // DirectionIncoming indicates an incoming relationship (left arrow). // Example: (a)<--(b) DirectionIncoming )
type ExistsExpr ¶ added in v0.2.0
type ExistsExpr struct {
Pattern *PatternExpr
Expr Expr
Start Pos
EndPos Pos
}
ExistsExpr represents an EXISTS subquery expression. It checks if a pattern exists in the graph.
Example Cypher:
EXISTS { (n)-[:KNOWS]->(m) }
EXISTS { MATCH (n)-[:FRIENDS_WITH]->(m) WHERE m.active = true }
Fields:
- Pattern: The pattern to check for existence
- Expr: Alternative expression form
- Start: Position in source where this expression begins
- EndPos: Position in source where this expression ends
func (*ExistsExpr) End ¶ added in v0.2.0
func (e *ExistsExpr) End() Pos
End returns the ending position of this expression in the source.
func (*ExistsExpr) Position ¶ added in v0.2.0
func (e *ExistsExpr) Position() Pos
Position returns the starting position of this expression in the source.
func (*ExistsExpr) String ¶ added in v0.2.0
func (e *ExistsExpr) String() string
String returns "EXISTS".
type Expr ¶ added in v0.2.0
type Expr interface {
Node
// contains filtered or unexported methods
}
Expr is the interface for all expression nodes. Expressions can be evaluated to produce values.
In addition to Node methods, Expr implementations must have an exprNode() method to distinguish them from other node types.
type FloatLit ¶ added in v0.2.0
FloatLit represents a floating-point literal expression. It holds a 64-bit floating-point value.
Example Cypher:
3.14159 -0.5 1.0e10
Fields:
- Value: The floating-point value
- Start: Position in source where this literal begins
- EndPos: Position in source where this literal ends
func (*FloatLit) End ¶ added in v0.2.0
End returns the ending position of this literal in the source.
type FuncCall ¶ added in v0.2.0
FuncCall represents a function call expression. It calls a built-in or user-defined function with arguments.
Example Cypher:
count(*) toUpper(name) coalesce(a, b, c)
Fields:
- Name: The function name
- Args: The function arguments
- Distinct: If true, applies DISTINCT to the arguments
- Start: Position in source where this expression begins
- EndPos: Position in source where this expression ends
func (*FuncCall) End ¶ added in v0.2.0
End returns the ending position of this expression in the source.
type Ident ¶ added in v0.2.0
Ident represents an identifier expression in Cypher. It is used for variable names, property names, and labels.
Example Cypher:
n (variable) name (property) Person (label)
Fields:
- Name: The identifier name
- Start: Position in source where this identifier begins
- EndPos: Position in source where this identifier ends
func (*Ident) End ¶ added in v0.2.0
End returns the ending position of this identifier in the source.
type InExpr ¶ added in v0.2.0
InExpr represents an IN expression for membership testing. It checks if a value is contained in a list.
Example Cypher:
n.name IN ['Alice', 'Bob', 'Charlie'] x IN range(1, 10)
Fields:
- Left: The value to check for membership
- Right: The list expression
- Start: Position in source where this expression begins
- EndPos: Position in source where this expression ends
func (*InExpr) End ¶ added in v0.2.0
End returns the ending position of this expression in the source.
type IntegerLit ¶ added in v0.2.0
IntegerLit represents an integer literal expression. It holds a signed 64-bit integer value.
Example Cypher:
42 -100 0
Fields:
- Value: The integer value
- Start: Position in source where this literal begins
- EndPos: Position in source where this literal ends
func (*IntegerLit) End ¶ added in v0.2.0
func (e *IntegerLit) End() Pos
End returns the ending position of this literal in the source.
func (*IntegerLit) Position ¶ added in v0.2.0
func (e *IntegerLit) Position() Pos
Position returns the starting position of this literal in the source.
func (*IntegerLit) String ¶ added in v0.2.0
func (e *IntegerLit) String() string
String returns "Integer".
type IsNullExpr ¶ added in v0.2.0
IsNullExpr represents an IS NULL or IS NOT NULL expression. It checks if a value is null or not null.
Example Cypher:
n.name IS NULL n.email IS NOT NULL
Fields:
- Expr: The expression to check
- IsNot: If true, this is IS NOT NULL
- Negate: Alternative negation flag
- Start: Position in source where this expression begins
- EndPos: Position in source where this expression ends
func (*IsNullExpr) End ¶ added in v0.2.0
func (e *IsNullExpr) End() Pos
End returns the ending position of this expression in the source.
func (*IsNullExpr) Position ¶ added in v0.2.0
func (e *IsNullExpr) Position() Pos
Position returns the starting position of this expression in the source.
func (*IsNullExpr) String ¶ added in v0.2.0
func (e *IsNullExpr) String() string
String returns "IS NULL" or "IS NOT NULL".
type ListComprehension ¶ added in v0.2.0
type ListComprehension struct {
Var string
Variable string
InExpr Expr
List Expr
Where Expr
Filter Expr
Expr Expr
Projection Expr
Start Pos
EndPos Pos
}
ListComprehension represents a list comprehension expression. It creates a new list by transforming and filtering an existing list.
Example Cypher:
[x IN list WHERE x > 0 | x * 2] [n IN nodes(p) | n.name]
Fields:
- Var: The iteration variable name
- Variable: Alternative variable name field
- InExpr: The expression being iterated (input list)
- List: Alternative input list field
- Where: Optional filter condition
- Filter: Alternative filter field
- Expr: The projection expression
- Projection: Alternative projection field
- Start: Position in source where this expression begins
- EndPos: Position in source where this expression ends
func (*ListComprehension) End ¶ added in v0.2.0
func (e *ListComprehension) End() Pos
End returns the ending position of this expression in the source.
func (*ListComprehension) Position ¶ added in v0.2.0
func (e *ListComprehension) Position() Pos
Position returns the starting position of this expression in the source.
func (*ListComprehension) String ¶ added in v0.2.0
func (e *ListComprehension) String() string
String returns "ListComprehension".
type ListExpr ¶ added in v0.2.0
ListExpr represents a list expression. It is used for list literals and list operations.
Example Cypher:
[1, 2, 3] ['a', 'b', 'c']
Fields:
- Elements: The list elements
- Start: Position in source where this expression begins
- EndPos: Position in source where this expression ends
func (*ListExpr) End ¶ added in v0.2.0
End returns the ending position of this expression in the source.
type ListIndexExpr ¶ added in v0.2.0
ListIndexExpr represents a list index expression. It accesses an element of a list by index.
Example Cypher:
list[0] (first element) list[-1] (last element)
Fields:
- List: The list expression
- Index: The index expression
- Start: Position in source where this expression begins
- EndPos: Position in source where this expression ends
func (*ListIndexExpr) End ¶ added in v0.2.0
func (e *ListIndexExpr) End() Pos
End returns the ending position of this expression in the source.
func (*ListIndexExpr) Position ¶ added in v0.2.0
func (e *ListIndexExpr) Position() Pos
Position returns the starting position of this expression in the source.
func (*ListIndexExpr) String ¶ added in v0.2.0
func (e *ListIndexExpr) String() string
String returns "ListIndex".
type ListLit ¶ added in v0.2.0
ListLit represents a list literal expression. It holds a list of expressions.
Example Cypher:
[1, 2, 3] ['a', 'b', 'c'] [] (empty list)
Fields:
- Elements: The list elements
- Start: Position in source where this literal begins
- EndPos: Position in source where this literal ends
func (*ListLit) End ¶ added in v0.2.0
End returns the ending position of this literal in the source.
type ListSliceExpr ¶ added in v0.2.0
ListSliceExpr represents a list slice expression. It extracts a portion of a list using start and end indices.
Example Cypher:
list[0..3] (first 3 elements) list[1..] (from index 1 to end) list[..5] (first 5 elements)
Fields:
- List: The list expression to slice
- From: The start index (nil means from beginning)
- To: The end index (nil means to end)
- Start: Position in source where this expression begins
- EndPos: Position in source where this expression ends
func (*ListSliceExpr) End ¶ added in v0.2.0
func (e *ListSliceExpr) End() Pos
End returns the ending position of this expression in the source.
func (*ListSliceExpr) Position ¶ added in v0.2.0
func (e *ListSliceExpr) Position() Pos
Position returns the starting position of this expression in the source.
func (*ListSliceExpr) String ¶ added in v0.2.0
func (e *ListSliceExpr) String() string
String returns "ListSlice".
type MapExpr ¶ added in v0.2.0
MapExpr represents a map expression. It is used for map literals with key-value pairs.
Example Cypher:
{name: 'Alice', age: 30}
{key: value, another: other}
Fields:
- Pairs: The key-value pairs
- Start: Position in source where this expression begins
- EndPos: Position in source where this expression ends
func (*MapExpr) End ¶ added in v0.2.0
End returns the ending position of this expression in the source.
type MapLit ¶ added in v0.2.0
MapLit represents a map literal expression. It holds a map of string keys to expression values.
Example Cypher:
{name: 'Alice', age: 30}
{} (empty map)
Fields:
- Properties: The map properties (key-value pairs)
- Start: Position in source where this literal begins
- EndPos: Position in source where this literal ends
type MapPair ¶ added in v0.2.0
MapPair represents a key-value pair in a map expression.
Fields:
- Key: The key name
- Value: The value expression
- Start: Position in source where this pair begins
- EndPos: Position in source where this pair ends
type MatchClause ¶
type MatchClause struct {
Optional bool
Pattern *PatternExpr
Where *WhereExpr
Return *ReturnExpr
Delete *DeleteClause
Start Pos
EndPos Pos
}
MatchClause represents a MATCH clause in a Cypher query. It matches patterns in the graph and can optionally be an OPTIONAL MATCH.
Example Cypher:
MATCH (n:Person)-[:KNOWS]->(m:Person) OPTIONAL MATCH (n)-[:WORKS_AT]->(c:Company)
Fields:
- Optional: If true, this is an OPTIONAL MATCH (returns null for non-matches)
- Pattern: The pattern to match in the graph
- Where: Optional WHERE filter expression
- Return: Optional RETURN clause
- Delete: Optional DELETE clause
- Start: Position in source where this clause begins
- EndPos: Position in source where this clause ends
func (*MatchClause) End ¶ added in v0.2.0
func (c *MatchClause) End() Pos
End returns the ending position of this clause in the source.
func (*MatchClause) Position ¶ added in v0.2.0
func (c *MatchClause) Position() Pos
Position returns the starting position of this clause in the source.
func (*MatchClause) String ¶ added in v0.2.0
func (c *MatchClause) String() string
String returns a string representation of this clause.
type MatchStmt ¶ added in v0.2.0
MatchStmt represents a MATCH statement in a Cypher query. It matches patterns in the graph and can include WHERE, SET, RETURN, and DELETE clauses.
Example Cypher:
MATCH (n:Person)-[:KNOWS]->(m:Person) WHERE n.age > 25 SET m.visited = true RETURN n, m
Fields:
- Optional: If true, this is an OPTIONAL MATCH
- Clauses: List of clauses in the statement
- Start: Position in source where this statement begins
- EndPos: Position in source where this statement ends
func (*MatchStmt) End ¶ added in v0.2.0
End returns the ending position of this statement in the source.
type MergeClause ¶ added in v0.2.0
type MergeClause struct {
Pattern *PatternExpr
OnCreate []*SetItem
OnMatch []*SetItem
Start Pos
EndPos Pos
}
MergeClause represents a MERGE clause in a Cypher query. It ensures a pattern exists in the graph, creating it if necessary. Supports ON CREATE and ON MATCH actions.
Example Cypher:
MERGE (n:Person {name: 'Alice'})
ON CREATE SET n.created = timestamp()
ON MATCH SET n.lastSeen = timestamp()
Fields:
- Pattern: The pattern to merge (create if doesn't exist)
- OnCreate: Actions to perform when creating new elements
- OnMatch: Actions to perform when matching existing elements
- Start: Position in source where this clause begins
- EndPos: Position in source where this clause ends
func (*MergeClause) End ¶ added in v0.2.0
func (c *MergeClause) End() Pos
End returns the ending position of this clause in the source.
func (*MergeClause) Position ¶ added in v0.2.0
func (c *MergeClause) Position() Pos
Position returns the starting position of this clause in the source.
func (*MergeClause) String ¶ added in v0.2.0
func (c *MergeClause) String() string
String returns a string representation of this clause.
type MergeStmt ¶ added in v0.2.0
type MergeStmt struct {
Pattern *PatternExpr
Clause *MergeClause
OnCreate []*SetItem
OnMatch []*SetItem
Start Pos
EndPos Pos
}
MergeStmt represents a MERGE statement in a Cypher query. It ensures a pattern exists in the graph, creating it if necessary. Supports ON CREATE and ON MATCH actions.
Example Cypher:
MERGE (n:Person {name: 'Alice'})
ON CREATE SET n.created = timestamp()
ON MATCH SET n.lastSeen = timestamp()
Fields:
- Pattern: The pattern to merge
- Clause: The merge clause with ON CREATE/MATCH actions
- OnCreate: Actions to perform when creating new elements
- OnMatch: Actions to perform when matching existing elements
- Start: Position in source where this statement begins
- EndPos: Position in source where this statement ends
func (*MergeStmt) End ¶ added in v0.2.0
End returns the ending position of this statement in the source.
type Node ¶ added in v0.2.0
Node is the base interface for all AST nodes. Every node in the AST must implement this interface.
Methods:
- Position(): Returns the starting position of the node
- End(): Returns the ending position of the node
- String(): Returns a string representation of the node
type NodePattern ¶
type NodePattern struct {
Variable string
Labels []string
Properties map[string]Expr
PropertyExpr Expr
Start Pos
EndPos Pos
}
NodePattern represents a node pattern in a Cypher query. It describes a node with optional variable name, labels, and properties.
Example Cypher:
(n:Person:Employee {name: 'Alice', age: 30})
(:Company)
(n)
Fields:
- Variable: Optional variable name for the node
- Labels: List of labels (e.g., Person, Employee)
- Properties: Map of property names to expressions
- PropertyExpr: Alternative property expression
- Start: Position in source where this node begins
- EndPos: Position in source where this node ends
func (*NodePattern) End ¶ added in v0.2.0
func (n *NodePattern) End() Pos
End returns the ending position of this node in the source.
func (*NodePattern) Position ¶ added in v0.2.0
func (n *NodePattern) Position() Pos
Position returns the starting position of this node in the source.
func (*NodePattern) String ¶ added in v0.2.0
func (n *NodePattern) String() string
String returns the variable name or "Node".
type NullLit ¶ added in v0.2.0
NullLit represents a NULL literal expression. It represents the absence of a value.
Example Cypher:
NULL
Fields:
- Start: Position in source where this literal begins
- EndPos: Position in source where this literal ends
func (*NullLit) End ¶ added in v0.2.0
End returns the ending position of this literal in the source.
type OrderByExpr ¶ added in v0.2.0
type OrderByExpr struct {
Items []*OrderByItem
Start Pos
EndPos Pos
}
OrderByExpr represents an ORDER BY clause in a Cypher query. It specifies how to sort the results.
Example Cypher:
ORDER BY n.age DESC, n.name ASC
Fields:
- Items: List of sort specifications
- Start: Position in source where this clause begins
- EndPos: Position in source where this clause ends
func (*OrderByExpr) End ¶ added in v0.2.0
func (c *OrderByExpr) End() Pos
End returns the ending position of this clause in the source.
func (*OrderByExpr) Position ¶ added in v0.2.0
func (c *OrderByExpr) Position() Pos
Position returns the starting position of this clause in the source.
func (*OrderByExpr) String ¶ added in v0.2.0
func (c *OrderByExpr) String() string
String returns a string representation of this clause.
type OrderByItem ¶ added in v0.2.0
OrderByItem represents a single sort specification in ORDER BY.
Example Cypher:
ORDER BY n.age DESC
Fields:
- Expr: The expression to sort by
- Descending: If true, sort in descending order
- Ascending: If true, sort in ascending order
- Start: Position in source where this item begins
- EndPos: Position in source where this item ends
func (*OrderByItem) End ¶ added in v0.2.0
func (c *OrderByItem) End() Pos
End returns the ending position of this item in the source.
func (*OrderByItem) Position ¶ added in v0.2.0
func (c *OrderByItem) Position() Pos
Position returns the starting position of this item in the source.
func (*OrderByItem) String ¶ added in v0.2.0
func (c *OrderByItem) String() string
String returns a string representation of this item.
type Param ¶ added in v0.2.0
Param represents a parameter placeholder expression. It references a parameter by name without the $ prefix.
Example Cypher:
$name
{age: $minAge}
Fields:
- Name: The parameter name (without $)
- Start: Position in source where this parameter begins
- EndPos: Position in source where this parameter ends
func (*Param) End ¶ added in v0.2.0
End returns the ending position of this parameter in the source.
type ParamExpr ¶ added in v0.2.0
ParamExpr represents a parameter expression. It is functionally equivalent to Param.
Example Cypher:
$name
Fields:
- Name: The parameter name (without $)
- Start: Position in source where this parameter begins
- EndPos: Position in source where this parameter ends
func (*ParamExpr) End ¶ added in v0.2.0
End returns the ending position of this parameter in the source.
type PathExpr ¶ added in v0.2.0
type PathExpr struct {
Nodes []*NodePattern
Relationships []*RelationPattern
Start Pos
EndPos Pos
}
PathExpr represents a path expression in a pattern. It describes a sequence of nodes connected by relationships.
Example Cypher:
(n:Person)-[:KNOWS]->(m:Person)<-[:FRIENDS_WITH]-(o:Person)
Fields:
- Nodes: The nodes in the path
- Relationships: The relationships connecting the nodes
- Start: Position in source where this path begins
- EndPos: Position in source where this path ends
type Pattern ¶
type Pattern interface {
Node
// contains filtered or unexported methods
}
Pattern is the interface for all pattern nodes. Patterns describe graph structures to match or create.
In addition to Node methods, Pattern implementations must have a patternNode() method to distinguish them from other node types.
type PatternComprehension ¶ added in v0.2.0
type PatternComprehension struct {
Pattern *PatternExpr
Where Expr
Expr Expr
Start Pos
EndPos Pos
}
PatternComprehension represents a pattern comprehension expression. It creates a list by matching a pattern and projecting results.
Example Cypher:
[(n)-[:KNOWS]->(m) | m.name]
Fields:
- Pattern: The pattern to match
- Where: Optional filter condition
- Expr: The projection expression
- Start: Position in source where this comprehension begins
- EndPos: Position in source where this comprehension ends
func (*PatternComprehension) End ¶ added in v0.2.0
func (p *PatternComprehension) End() Pos
End returns the ending position of this comprehension in the source.
func (*PatternComprehension) Position ¶ added in v0.2.0
func (p *PatternComprehension) Position() Pos
Position returns the starting position of this comprehension in the source.
func (*PatternComprehension) String ¶ added in v0.2.0
func (p *PatternComprehension) String() string
String returns "PatternComprehension".
type PatternExpr ¶ added in v0.2.0
type PatternExpr struct {
Parts []*PatternPart
Paths []*PathExpr
Start Pos
EndPos Pos
}
PatternExpr represents a complete pattern expression. It consists of one or more pattern parts that describe the graph structure to match or create.
Example Cypher:
(n:Person)-[:KNOWS]->(m:Person), (m)-[:WORKS_AT]->(c:Company)
Fields:
- Parts: The pattern parts (comma-separated in Cypher)
- Paths: Alternative path representations
- Start: Position in source where this pattern begins
- EndPos: Position in source where this pattern ends
func (*PatternExpr) End ¶ added in v0.2.0
func (p *PatternExpr) End() Pos
End returns the ending position of this pattern in the source.
func (*PatternExpr) Position ¶ added in v0.2.0
func (p *PatternExpr) Position() Pos
Position returns the starting position of this pattern in the source.
func (*PatternExpr) String ¶ added in v0.2.0
func (p *PatternExpr) String() string
String returns "Pattern".
type PatternExprItem ¶ added in v0.2.0
PatternExprItem represents an item within a pattern expression. It is similar to PatternPart but used in different contexts.
Fields:
- Variable: Optional variable name
- Path: The path expression
- Start: Position in source where this item begins
- EndPos: Position in source where this item ends
func (*PatternExprItem) End ¶ added in v0.2.0
func (p *PatternExprItem) End() Pos
End returns the ending position of this item in the source.
func (*PatternExprItem) Position ¶ added in v0.2.0
func (p *PatternExprItem) Position() Pos
Position returns the starting position of this item in the source.
func (*PatternExprItem) String ¶ added in v0.2.0
func (p *PatternExprItem) String() string
String returns the variable name or "PatternItem".
type PatternPart ¶ added in v0.2.0
PatternPart represents a single part of a pattern expression. It can be named with a variable and contains a path.
Example Cypher:
p = (n:Person)-[:KNOWS]->(m:Person)
Fields:
- Variable: Optional variable name for the entire pattern part
- Path: The path expression within this part
- Start: Position in source where this part begins
- EndPos: Position in source where this part ends
func (*PatternPart) End ¶ added in v0.2.0
func (p *PatternPart) End() Pos
End returns the ending position of this part in the source.
func (*PatternPart) Position ¶ added in v0.2.0
func (p *PatternPart) Position() Pos
Position returns the starting position of this part in the source.
func (*PatternPart) String ¶ added in v0.2.0
func (p *PatternPart) String() string
String returns the variable name or "PatternPart".
type Pos ¶ added in v0.2.0
Pos represents a position in the source code. It is used for error reporting and source mapping.
Fields:
- Line: The 1-based line number
- Column: The 1-based column number
- Offset: The 0-based byte offset from the start of the file
type PropertyAccessExpr ¶ added in v0.2.0
PropertyAccessExpr represents a property access expression (e.g., n.name). It accesses a property of a node, relationship, or map.
Example Cypher:
n.name user.email person.address.city (nested access)
Fields:
- Target: The expression whose property is being accessed
- Property: The property name
- Start: Position in source where this expression begins
- EndPos: Position in source where this expression ends
func (*PropertyAccessExpr) End ¶ added in v0.2.0
func (e *PropertyAccessExpr) End() Pos
End returns the ending position of this expression in the source.
func (*PropertyAccessExpr) Position ¶ added in v0.2.0
func (e *PropertyAccessExpr) Position() Pos
Position returns the starting position of this expression in the source.
func (*PropertyAccessExpr) String ¶ added in v0.2.0
func (e *PropertyAccessExpr) String() string
String returns the property name.
type Query ¶ added in v0.2.0
Query represents a complete Cypher query. It can contain multiple statements separated by semicolons.
Example Cypher:
MATCH (n) RETURN n;
CREATE (m:Person {name: 'Alice'})
Fields:
- Statements: List of statements in the query
- Start: Position in source where this query begins
- EndPos: Position in source where this query ends
type RelationPattern ¶
type RelationPattern struct {
Variable string
Types []string
Direction Direction
Properties map[string]Expr
MinHops *int
MaxHops *int
VariableLength bool
RightArrow bool
LeftArrow bool
Start Pos
EndPos Pos
}
RelationPattern represents a relationship pattern in a Cypher query. It describes a relationship with optional variable name, types, direction, properties, and variable length constraints.
Example Cypher:
-[r:KNOWS {since: 2020}]->
-[:FRIENDS_WITH|COLLEAGUE]->
-[*1..3]-> (variable length)
-->
Fields:
- Variable: Optional variable name for the relationship
- Types: List of relationship types
- Direction: The relationship direction
- Properties: Map of property names to expressions
- MinHops: Minimum number of hops (for variable length)
- MaxHops: Maximum number of hops (for variable length)
- VariableLength: If true, this is a variable-length pattern
- RightArrow: If true, has a right arrow
- LeftArrow: If true, has a left arrow
- Start: Position in source where this relationship begins
- EndPos: Position in source where this relationship ends
func (*RelationPattern) End ¶ added in v0.2.0
func (r *RelationPattern) End() Pos
End returns the ending position of this relationship in the source.
func (*RelationPattern) Position ¶ added in v0.2.0
func (r *RelationPattern) Position() Pos
Position returns the starting position of this relationship in the source.
func (*RelationPattern) String ¶ added in v0.2.0
func (r *RelationPattern) String() string
String returns the variable name or "Relation".
type RemoveClause ¶
type RemoveClause struct {
Items []*RemoveItemExpr
Start Pos
EndPos Pos
}
RemoveClause represents a REMOVE clause in a Cypher query. It removes properties and labels from nodes and relationships.
Example Cypher:
REMOVE n.age REMOVE n:Person
Fields:
- Items: List of items to remove
- Start: Position in source where this clause begins
- EndPos: Position in source where this clause ends
func (*RemoveClause) End ¶ added in v0.2.0
func (c *RemoveClause) End() Pos
End returns the ending position of this clause in the source.
func (*RemoveClause) Position ¶ added in v0.2.0
func (c *RemoveClause) Position() Pos
Position returns the starting position of this clause in the source.
func (*RemoveClause) String ¶ added in v0.2.0
func (c *RemoveClause) String() string
String returns a string representation of this clause.
type RemoveItemExpr ¶ added in v0.2.0
RemoveItemExpr represents a single item in a REMOVE statement. It can remove a property or a label.
Example Cypher:
REMOVE n.age // Property REMOVE n:Person // Label
Fields:
- Target: The target expression
- IsLabel: If true, this is a label removal
- Label: The label name (if IsLabel is true)
- Start: Position in source where this item begins
- EndPos: Position in source where this item ends
func (*RemoveItemExpr) End ¶ added in v0.2.0
func (r *RemoveItemExpr) End() Pos
End returns the ending position of this item in the source.
func (*RemoveItemExpr) Position ¶ added in v0.2.0
func (r *RemoveItemExpr) Position() Pos
Position returns the starting position of this item in the source.
func (*RemoveItemExpr) String ¶ added in v0.2.0
func (r *RemoveItemExpr) String() string
String returns "RemoveItem".
type RemoveStmt ¶ added in v0.2.0
type RemoveStmt struct {
Items []*RemoveItemExpr
Start Pos
EndPos Pos
}
RemoveStmt represents a REMOVE statement in a Cypher query. It removes properties and labels from nodes and relationships.
Example Cypher:
REMOVE n.age REMOVE n:Person
Fields:
- Items: List of items to remove
- Start: Position in source where this statement begins
- EndPos: Position in source where this statement ends
func (*RemoveStmt) End ¶ added in v0.2.0
func (s *RemoveStmt) End() Pos
End returns the ending position of this statement in the source.
func (*RemoveStmt) Position ¶ added in v0.2.0
func (s *RemoveStmt) Position() Pos
Position returns the starting position of this statement in the source.
func (*RemoveStmt) String ¶ added in v0.2.0
func (s *RemoveStmt) String() string
String returns "REMOVE".
type ReturnClause ¶
type ReturnClause struct {
Items []*ReturnItemExpr
Distinct bool
OrderBy *OrderByExpr
Skip Expr
Limit Expr
Start Pos
EndPos Pos
}
ReturnClause represents a RETURN clause in a Cypher query. It specifies what data to return from the query.
Example Cypher:
RETURN n, m.name AS friendName RETURN DISTINCT n.age ORDER BY n.age DESC LIMIT 10
Fields:
- Items: List of expressions to return
- Distinct: If true, return only distinct rows
- OrderBy: Optional ORDER BY clause
- Skip: Optional number of rows to skip
- Limit: Optional maximum number of rows to return
- Start: Position in source where this clause begins
- EndPos: Position in source where this clause ends
func (*ReturnClause) End ¶ added in v0.2.0
func (c *ReturnClause) End() Pos
End returns the ending position of this clause in the source.
func (*ReturnClause) Position ¶ added in v0.2.0
func (c *ReturnClause) Position() Pos
Position returns the starting position of this clause in the source.
func (*ReturnClause) String ¶ added in v0.2.0
func (c *ReturnClause) String() string
String returns a string representation of this clause.
type ReturnExpr ¶ added in v0.2.0
type ReturnExpr struct {
Items []*ReturnItemExpr
Distinct bool
OrderBy *OrderByExpr
Skip Expr
Limit Expr
Start Pos
EndPos Pos
}
ReturnExpr represents a RETURN expression in a Cypher query. It is functionally equivalent to ReturnClause.
Fields:
- Items: List of expressions to return
- Distinct: If true, return only distinct rows
- OrderBy: Optional ORDER BY clause
- Skip: Optional number of rows to skip
- Limit: Optional maximum number of rows to return
- Start: Position in source where this expression begins
- EndPos: Position in source where this expression ends
func (*ReturnExpr) End ¶ added in v0.2.0
func (c *ReturnExpr) End() Pos
End returns the ending position of this expression in the source.
func (*ReturnExpr) Position ¶ added in v0.2.0
func (c *ReturnExpr) Position() Pos
Position returns the starting position of this expression in the source.
func (*ReturnExpr) String ¶ added in v0.2.0
func (c *ReturnExpr) String() string
String returns a string representation of this expression.
type ReturnItemExpr ¶ added in v0.2.0
ReturnItemExpr represents a single item in a RETURN clause. It can have an optional alias (AS clause).
Example Cypher:
RETURN n.name AS personName
Fields:
- Expr: The expression to return
- Alias: Optional alias name (empty if no AS clause)
- Start: Position in source where this item begins
- EndPos: Position in source where this item ends
func (*ReturnItemExpr) End ¶ added in v0.2.0
func (c *ReturnItemExpr) End() Pos
End returns the ending position of this item in the source.
func (*ReturnItemExpr) Position ¶ added in v0.2.0
func (c *ReturnItemExpr) Position() Pos
Position returns the starting position of this item in the source.
func (*ReturnItemExpr) String ¶ added in v0.2.0
func (c *ReturnItemExpr) String() string
String returns a string representation of this item.
type ReturnStmt ¶ added in v0.2.0
type ReturnStmt struct {
Distinct bool
Items []*ReturnItemExpr
OrderBy *OrderByExpr
Skip Expr
Limit Expr
Return *ReturnExpr
Start Pos
EndPos Pos
}
ReturnStmt represents a RETURN statement in a Cypher query. It specifies what data to return.
Example Cypher:
RETURN n, m.name AS friendName RETURN DISTINCT n.age ORDER BY n.age DESC LIMIT 10
Fields:
- Distinct: If true, return only distinct rows
- Items: List of expressions to return
- OrderBy: Optional ORDER BY clause
- Skip: Optional number of rows to skip
- Limit: Optional maximum number of rows
- Return: The return expression
- Start: Position in source where this statement begins
- EndPos: Position in source where this statement ends
func (*ReturnStmt) End ¶ added in v0.2.0
func (s *ReturnStmt) End() Pos
End returns the ending position of this statement in the source.
func (*ReturnStmt) Position ¶ added in v0.2.0
func (s *ReturnStmt) Position() Pos
Position returns the starting position of this statement in the source.
func (*ReturnStmt) String ¶ added in v0.2.0
func (s *ReturnStmt) String() string
String returns "RETURN".
type SetClause ¶
SetClause represents a SET clause in a Cypher query. It sets properties on nodes and relationships.
Example Cypher:
SET n.name = 'Alice'
SET n += {age: 30, city: 'NYC'}
SET n:Person:Employee
Fields:
- Items: List of SET operations to perform
- Start: Position in source where this clause begins
- EndPos: Position in source where this clause ends
func (*SetClause) End ¶ added in v0.2.0
End returns the ending position of this clause in the source.
type SetItem ¶ added in v0.2.0
SetItem represents a single SET operation. It can set a property, add labels, or perform a map update.
Example Cypher:
SET n.name = 'Alice' // Property assignment
SET n += {age: 30} // Map update
SET n:Person:Employee // Label addition
Fields:
- Target: The target expression (property or node)
- Value: The value to set
- Operator: The operator (= or +=)
- IsLabel: If true, this is a label operation
- Start: Position in source where this item begins
- EndPos: Position in source where this item ends
type SetStmt ¶ added in v0.2.0
SetStmt represents a SET statement in a Cypher query. It sets properties on nodes and relationships.
Example Cypher:
SET n.name = 'Alice'
SET n += {age: 30, city: 'NYC'}
SET n:Person:Employee
Fields:
- Items: List of SET operations
- Start: Position in source where this statement begins
- EndPos: Position in source where this statement ends
func (*SetStmt) End ¶ added in v0.2.0
End returns the ending position of this statement in the source.
type Stmt ¶ added in v0.2.0
type Stmt interface {
Node
// contains filtered or unexported methods
}
Stmt is the interface for all statement nodes. Statements represent executable actions in Cypher queries.
In addition to Node methods, Stmt implementations must have a stmtNode() method to distinguish them from other node types.
type StringLit ¶ added in v0.2.0
StringLit represents a string literal expression. It holds a string value (quotes are not included).
Example Cypher:
'hello' "world" 'it\'s a test'
Fields:
- Value: The string value (without quotes)
- Start: Position in source where this literal begins
- EndPos: Position in source where this literal ends
func (*StringLit) End ¶ added in v0.2.0
End returns the ending position of this literal in the source.
type UnaryExpr ¶ added in v0.2.0
UnaryExpr represents a unary expression with an operator and operand. It is used for negation and other unary operations.
Example Cypher:
-n (negation) NOT x (logical not)
Fields:
- Operator: The unary operator (e.g., -, NOT)
- Operand: The operand expression
- Start: Position in source where this expression begins
- EndPos: Position in source where this expression ends
func (*UnaryExpr) End ¶ added in v0.2.0
End returns the ending position of this expression in the source.
type UnionClause ¶ added in v0.2.0
UnionClause represents a UNION clause in a Cypher query. It combines results from multiple queries.
Example Cypher:
MATCH (n) RETURN n.name UNION MATCH (m) RETURN m.name MATCH (n) RETURN n.name UNION ALL MATCH (m) RETURN m.name
Fields:
- All: If true, this is UNION ALL (keeps duplicates)
- Start: Position in source where this clause begins
- EndPos: Position in source where this clause ends
func (*UnionClause) End ¶ added in v0.2.0
func (c *UnionClause) End() Pos
End returns the ending position of this clause in the source.
func (*UnionClause) Position ¶ added in v0.2.0
func (c *UnionClause) Position() Pos
Position returns the starting position of this clause in the source.
func (*UnionClause) String ¶ added in v0.2.0
func (c *UnionClause) String() string
String returns a string representation of this clause.
type UnwindClause ¶ added in v0.2.0
UnwindClause represents an UNWIND clause in a Cypher query. It expands a list into a sequence of rows.
Example Cypher:
UNWIND [1, 2, 3] AS num UNWIND $names AS name
Fields:
- Expr: The list expression to unwind
- Var: The variable name for each element
- Start: Position in source where this clause begins
- EndPos: Position in source where this clause ends
func (*UnwindClause) End ¶ added in v0.2.0
func (c *UnwindClause) End() Pos
End returns the ending position of this clause in the source.
func (*UnwindClause) Position ¶ added in v0.2.0
func (c *UnwindClause) Position() Pos
Position returns the starting position of this clause in the source.
func (*UnwindClause) String ¶ added in v0.2.0
func (c *UnwindClause) String() string
String returns a string representation of this clause.
type UnwindStmt ¶ added in v0.2.0
type UnwindStmt struct {
List Expr
Variable string
Return *ReturnExpr
Start Pos
EndPos Pos
}
UnwindStmt represents an UNWIND statement in a Cypher query. It expands a list into a sequence of rows.
Example Cypher:
UNWIND [1, 2, 3] AS num UNWIND $names AS name
Fields:
- List: The list expression to unwind
- Variable: The variable name for each element
- Return: Optional RETURN clause
- Start: Position in source where this statement begins
- EndPos: Position in source where this statement ends
func (*UnwindStmt) End ¶ added in v0.2.0
func (s *UnwindStmt) End() Pos
End returns the ending position of this statement in the source.
func (*UnwindStmt) Position ¶ added in v0.2.0
func (s *UnwindStmt) Position() Pos
Position returns the starting position of this statement in the source.
func (*UnwindStmt) String ¶ added in v0.2.0
func (s *UnwindStmt) String() string
String returns "UNWIND".
type Visitor ¶ added in v0.2.0
type Visitor interface {
// Visit is called for each node in the AST.
// It returns the visitor to use for child nodes, or nil to skip children.
// An error can be returned to stop the walk.
Visit(node Node) (w Visitor, err error)
}
Visitor is the interface for visiting AST nodes. Implementations can perform operations on nodes during the walk.
type Walker ¶ added in v0.2.0
type Walker struct {
// contains filtered or unexported fields
}
Walker walks an AST and calls the visitor for each node.
type WhenClause ¶ added in v0.2.0
WhenClause represents a WHEN clause in a CASE expression. It pairs a condition with a result.
Example Cypher:
WHEN 18 THEN 'young'
Fields:
- Condition: The condition to match (for searched CASE)
- Result: The result expression if the condition matches
- Start: Position in source where this clause begins
- EndPos: Position in source where this clause ends
func (*WhenClause) End ¶ added in v0.2.0
func (c *WhenClause) End() Pos
End returns the ending position of this clause in the source.
func (*WhenClause) Position ¶ added in v0.2.0
func (c *WhenClause) Position() Pos
Position returns the starting position of this clause in the source.
func (*WhenClause) String ¶ added in v0.2.0
func (c *WhenClause) String() string
String returns "WHEN".
type WhereClause ¶
WhereClause represents a WHERE clause in a Cypher query. It filters results based on a boolean expression.
Example Cypher:
WHERE n.age > 25 AND n.name STARTS WITH 'A'
Fields:
- Expr: The boolean expression to evaluate
- Start: Position in source where this clause begins
- EndPos: Position in source where this clause ends
func (*WhereClause) End ¶ added in v0.2.0
func (c *WhereClause) End() Pos
End returns the ending position of this clause in the source.
func (*WhereClause) Position ¶ added in v0.2.0
func (c *WhereClause) Position() Pos
Position returns the starting position of this clause in the source.
func (*WhereClause) String ¶ added in v0.2.0
func (c *WhereClause) String() string
String returns a string representation of this clause.
type WhereExpr ¶ added in v0.2.0
WhereExpr represents a WHERE expression in a Cypher query. It is similar to WhereClause but used in different contexts.
Fields:
- Expr: The boolean expression to evaluate
- Start: Position in source where this expression begins
- EndPos: Position in source where this expression ends
func (*WhereExpr) End ¶ added in v0.2.0
End returns the ending position of this expression in the source.
type WithClause ¶ added in v0.2.0
type WithClause struct {
Items []*ReturnItemExpr
Distinct bool
OrderBy *OrderByExpr
Skip Expr
Limit Expr
Where Expr
Start Pos
EndPos Pos
}
WithClause represents a WITH clause in a Cypher query. It chains query parts, passing results to the next part.
Example Cypher:
WITH n, count(*) AS cnt ORDER BY cnt DESC LIMIT 10
Fields:
- Items: List of expressions to pass forward
- Distinct: If true, return only distinct rows
- OrderBy: Optional ORDER BY clause
- Skip: Optional number of rows to skip
- Limit: Optional maximum number of rows to return
- Where: Optional WHERE filter
- Start: Position in source where this clause begins
- EndPos: Position in source where this clause ends
func (*WithClause) End ¶ added in v0.2.0
func (c *WithClause) End() Pos
End returns the ending position of this clause in the source.
func (*WithClause) Position ¶ added in v0.2.0
func (c *WithClause) Position() Pos
Position returns the starting position of this clause in the source.
func (*WithClause) String ¶ added in v0.2.0
func (c *WithClause) String() string
String returns a string representation of this clause.
type WithStmt ¶ added in v0.2.0
type WithStmt struct {
Items []*ReturnItemExpr
Distinct bool
OrderBy *OrderByExpr
Skip Expr
Limit Expr
Where Expr
Start Pos
EndPos Pos
}
WithStmt represents a WITH statement in a Cypher query. It chains query parts, passing results to the next part.
Example Cypher:
WITH n, count(*) AS cnt ORDER BY cnt DESC LIMIT 10
Fields:
- Items: List of expressions to pass forward
- Distinct: If true, return only distinct rows
- OrderBy: Optional ORDER BY clause
- Skip: Optional number of rows to skip
- Limit: Optional maximum number of rows
- Where: Optional WHERE filter
- Start: Position in source where this statement begins
- EndPos: Position in source where this statement ends
func (*WithStmt) End ¶ added in v0.2.0
End returns the ending position of this statement in the source.