package ast
Import Path
github.com/freeeve/gochickpeas/gql/internal/ast (on go.dev)
Dependency Relation
imports 3 packages, and imported by 8 packages
Involved Source Files
Package ast is the language-neutral query AST: produced by the GQL
parser (gql/internal/parser), consumed by desugar/bind/plan. Port of the
Rust cypher crate's ast.rs -- the shapes below the parser deliberately
keep the Rust engine's segment model (a query is reading clauses plus
projection boundaries ending in a final projection), so GQL's
RETURN...NEXT / LET / FILTER forms all normalize into the same With
clause the Rust binder and planner consume.
Expression AST nodes: the Expr interface, its node structs, operators,
and parsed literals. Split from ast.go to keep files under the repo
size norm.
Fingerprint renders a query AST to a canonical string: two ASTs render
identically iff they are structurally identical (every node emits a type
tag with delimited fields, strings are quoted), so the rendering is safe
as a plan-cache template key -- the Go analogue of the Rust engine
keying its L2 on the template AST's debug rendering.
The shared expression walker: desugar, the binder, and autoparam all
traverse expressions with it (including the pattern-carrying subquery
nodes' inner WHERE/projection expressions).
Package-Level Type Names (total 63)
BinOp is an infix operator.
func github.com/freeeve/gochickpeas/gql/internal/eval.Arith(op BinOp, l, r value.Value) value.Value
func github.com/freeeve/gochickpeas/gql/internal/eval.StrPred(op BinOp, l, r value.Value) value.Value
const OpAdd
const OpAnd
const OpConcat
const OpContains
const OpDiv
const OpEndsWith
const OpEq
const OpGt
const OpGte
const OpLt
const OpLte
const OpMul
const OpNeq
const OpOr
const OpStartsWith
const OpSub
const OpXor
CallProc is CALL proc(args...) YIELD field [AS alias], ... -- runs an
analytic procedure and produces one row per result with the yielded
columns bound. Args are general expressions: constant ones resolve at
plan time, others evaluate per input row (a correlated call).
Args []Expr
Proc string
Yields []YieldItem
*CallProc : Clause
CallSubquery is CALL [(vars...)] { subquery }: a clause-level correlated
subquery (lateral join). Imports is the variable-scope list -- the outer
variables visible inside; empty means uncorrelated (runs once,
cross-joins every outer row). The body query keeps a leading importing
With as its first clause (the shape the binder expects).
Imports []string
Query Query
*CallSubquery : Clause
Case is CASE [operand] WHEN...THEN... [ELSE default] END. A non-nil
Operand is the simple form (each cond compares to the operand);
otherwise the searched form (each cond is a boolean).
// nil when absent
// nil for the searched form
Whens []CaseWhen
*Case : Expr
Clause is a clause appearing before a part's final projection.
*CallProc
*CallSubquery
*Match
*PathBind
*ShortestPath
*Unwind
*With
Cost is the weighted shortest-path cost between two bound endpoints
(engine node; no GQL surface syntax -- reachable via CALL procedures).
Dir Dir
From string
To string
Types []string
Weight CostSpec
*Cost : Expr
CostKind discriminates a CostSpec.
const CostConstant
const CostExpr
const CostProperty
CountSub is COUNT { MATCH pattern [WHERE expr] }: how many times the
correlated inner pattern matches the current row.
Pattern *Pattern
// nil when absent
*CountSub : Expr
Dir is a relationship direction as written in the pattern.
Flipped is the direction seen when traversing the other way.
func Dir.Flipped() Dir
const DirBoth
const DirIn
const DirOut
Exists is EXISTS { MATCH pattern [WHERE expr] }: true if the (possibly
correlated) inner pattern matches at least once for the current row.
Pattern *Pattern
// nil when absent
*Exists : Expr
Expr is one expression node.
*Binary
*Case
*Cost
*CountSub
*Exists
*Func
*HasLabelExpr
*In
*Index
*IsNull
*IsTruth
*IsTyped
*ListComp
*ListExpr
*ListPred
*Lit
*MapLit
*MapProj
*PatternComp
*Prop
*PropOf
*Reduce
*Slice
*Unary
*Var
func Walk(e Expr, f func(Expr) bool)
func github.com/freeeve/gochickpeas/gql/internal/compile.ConstValue(ctx *eval.Ctx, e Expr, slots map[string]int, g *chickpeas.Snapshot) (value.Value, bool)
func github.com/freeeve/gochickpeas/gql/internal/compile.New(ctx *eval.Ctx, e Expr, slots map[string]int, g *chickpeas.Snapshot) *compile.Compiled
func github.com/freeeve/gochickpeas/gql/internal/eval.Eval(ctx *eval.Ctx, expr Expr, row []value.Value, slots map[string]int) value.Value
func github.com/freeeve/gochickpeas/gql/internal/eval.SubqueryCount(ctx *eval.Ctx, pattern *Pattern, where Expr, outerRow []value.Value, outerSlots map[string]int, stopAtFirst bool) int
func github.com/freeeve/gochickpeas/gql/internal/eval.SubqueryGroupCount(ctx *eval.Ctx, pattern *Pattern, where Expr, outerRow []value.Value, outerSlots map[string]int, anchorVar, groupVar string) map[graph.NodeID]int
func github.com/freeeve/gochickpeas/gql/internal/plan.MentionsVar(e Expr, name string) bool
func github.com/freeeve/gochickpeas/gql/internal/plan.OrderColIndex(expr Expr, columns []string, returns []plan.BoundReturn) int
func github.com/freeeve/gochickpeas/gql/internal/plan.SplitAnd(e Expr, out *[]Expr)
func github.com/freeeve/gochickpeas/gql/internal/plan.SplitAnd(e Expr, out *[]Expr)
func github.com/freeeve/gochickpeas/gql/internal/semantics.CheckRefs(e Expr, scope map[string]int) error
func github.com/freeeve/gochickpeas/gql/internal/semantics.CheckRefsSkippingAgg(e Expr, scope map[string]int) error
func github.com/freeeve/gochickpeas/gql/internal/semantics.DerivedName(e Expr) string
func github.com/freeeve/gochickpeas/gql/internal/semantics.ExprHasAgg(e Expr) bool
Func is a function call; Star is count(*), Distinct is count(DISTINCT x).
Args []Expr
Distinct bool
Name string
Star bool
*Func : Expr
HasLabelExpr tests a LabelExpr against the node bound to Var -- built
from the surface label predicate (n:Label) and by the planner lowering a
node pattern's general label expression.
Expr *LabelExpr
Var string
*HasLabelExpr : Expr
Index is base[index] (0-based; negative counts from the end; out of
range yields null).
Base Expr
Idx Expr
*Index : Expr
IsNull is the postfix null test; Negated is the IS NOT NULL form.
Expr Expr
Negated bool
*IsNull : Expr
IsTruth is the postfix truth-value test `x IS [NOT] TRUE|FALSE`:
IS TRUE is true iff x is the boolean true (null and non-booleans read
false); IS FALSE iff x is the boolean false. NOT negates the whole
test. (IS UNKNOWN parses to IsNull -- unknown IS the null truth value.)
Expr Expr
Negated bool
Want bool
*IsTruth : Expr
IsTyped is `x IS [NOT] TYPED <type>`: a runtime value-kind test.
Expr Expr
// normalized lowercase: integer, float, string, boolean, list, node, relationship
Negated bool
*IsTyped : Expr
LabelExpr is a boolean label expression tree: label tests combined with
& (and), | (or), ! (not), and parentheses.
Kind LabelKind
L *LabelExpr
// LabelName only
R *LabelExpr
LabelKind discriminates a LabelExpr node.
const LabelAnd
const LabelName
const LabelNot
const LabelOr
const LabelWild
ListComp is [x IN list WHERE filter | map] (engine node; no GQL surface
syntax yet).
// nil when absent
List Expr
// nil when absent
Var string
*ListComp : Expr
ListPred is a list-predicate quantifier: all(x IN list WHERE pred) and
the any/none/single forms.
List Expr
Pred Expr
Quant Quant
Var string
*ListPred : Expr
Literal is a parsed constant (distinct from a runtime value).
B bool
F float64
I int64
Kind LitKind
// LitParam slot
// LitStr text or LitNamedParam name
func BoolLit(b bool) Literal
func FloatLit(v float64) Literal
func IntLit(v int64) Literal
func NamedParamLit(name string) Literal
func NullLit() Literal
func ParamLit(slot uint32) Literal
func StrLit(s string) Literal
func github.com/freeeve/gochickpeas/gql/internal/eval.LitValue(ctx *eval.Ctx, l Literal) value.Value
func github.com/freeeve/gochickpeas/gql/internal/semantics.LitValue(l Literal) value.Value
LitKind discriminates a Literal.
const LitBool
const LitFloat
const LitInt
const LitNamedParam
const LitNull
const LitParam
const LitStr
MapLit is a map literal {key: expr, ...} in expression position; values
are arbitrary expressions (unlike a pattern's inline property map).
Fields []MapField
*MapLit : Expr
MapProj is a map projection var{.key, alias: expr, .*} (engine node; no
GQL surface syntax yet).
Entries []MapProjEntry
Var string
*MapProj : Expr
MapProjEntry is one entry of a MapProj.
// MapProjField only
Key string
Kind MapProjEntryKind
MapProjEntryKind discriminates a map-projection entry.
const MapProjAll
const MapProjField
const MapProjProp
Match is [OPTIONAL] MATCH pattern[, pattern...] [WHERE expr].
Comma-separated patterns bind sequentially (sharing variables). When
Optional, a row with no match survives with the new variables null.
Acyclic is the ACYCLIC path-mode prefix: no repeated node within
each quantified segment. TRAIL needs no flag -- it is the engine's
native traversal semantics.
Optional bool
Patterns []Pattern
Repeatable is the REPEATABLE ELEMENTS match mode: relationship
uniqueness is NOT enforced within the clause (walk semantics).
DIFFERENT EDGES needs no flag -- it is the engine default.
// nil when absent
*Match : Clause
NodePat is one node pattern.
LabelExpr is a general boolean label expression -- non-nil only when
not a plain conjunction (then Labels is empty). The planner lowers it
to a per-node HasLabelExpr WHERE conjunct.
Labels is the conjunctive (AND) label list -- the common case. When
the label expression is a plain conjunction it is flattened here and
LabelExpr stays nil, keeping the planner/kernel fast paths.
PropExprs are non-literal inline property values ({name: tagVar}).
The desugar pass lowers each to a WHERE equality before planning.
Props are literal/param inline property values ({id: 669},
{name: $p}) -- the fast seek/filter path.
// "" when anonymous
Where is the element pattern's inline predicate ((v:L WHERE expr));
the desugar pass conjoins it onto the clause WHERE.
func (*Pattern).EndNode() *NodePat
PathBind is [OPTIONAL] MATCH p = (a)-[...]->(b): bind the named path
over a general pattern (distinct from the path-search form).
Acyclic is the ACYCLIC path-mode prefix (see Match.Acyclic).
Optional bool
PathVar string
Pattern Pattern
// nil when absent
*PathBind : Clause
Pattern is a linear path pattern: a start node followed by zero or more
(rel, node) hops.
Hops []PatternHop
Start NodePat
EndNode is the node at the far end of the path (the start if no hops).
Reversed is the same path written end-to-start: the last node becomes
the start and every relationship direction flips. Used by the planner to
anchor traversal on the bound (selective) endpoint.
func (*Pattern).Reversed() Pattern
func github.com/freeeve/gochickpeas/gql/internal/eval.SubqueryCount(ctx *eval.Ctx, pattern *Pattern, where Expr, outerRow []value.Value, outerSlots map[string]int, stopAtFirst bool) int
func github.com/freeeve/gochickpeas/gql/internal/eval.SubqueryGroupCount(ctx *eval.Ctx, pattern *Pattern, where Expr, outerRow []value.Value, outerSlots map[string]int, anchorVar, groupVar string) map[graph.NodeID]int
PatternComp is [ (pattern) [WHERE filter] | proj ] (engine node; no GQL
surface syntax yet).
Pattern *Pattern
Proj Expr
// nil when absent
*PatternComp : Expr
Projection is a projection body (With / final RETURN): items, DISTINCT,
and the ordering / pagination applied to the projected rows.
Distinct bool
Items []ReturnItem
// nil when absent
OrderBy []SortItem
// OFFSET/SKIP; nil when absent
Star means `*` was written: all in-scope variables project ahead of
any explicit Items, expanded by the binder in introduction order.
PropOf is property access on an arbitrary expression (rels(e)[i].ts);
the common ident.key parses as Prop.
Base Expr
Key string
*PropOf : Expr
Quant is the list-predicate quantifier of a ListPred.
const QuantAll
const QuantAny
const QuantNone
const QuantSingle
Query is a whole read-only query: one or more QueryPart branches
combined by UNION / UNION ALL. len(Union) == len(Parts)-1.
Mode QueryMode
Parts []QueryPart
Union []UnionKind
func github.com/freeeve/gochickpeas/gql/internal/parser.Parse(src string) (*Query, error)
func Fingerprint(q *Query) string
func github.com/freeeve/gochickpeas/gql/internal/plan.Build(q *Query, g graph.Graph) (*plan.Plan, error)
func github.com/freeeve/gochickpeas/gql/internal/plan.BuildWithInCols(q *Query, inCols []string, g graph.Graph) (*plan.Plan, error)
func github.com/freeeve/gochickpeas/gql/internal/semantics.AutoParameterize(q *Query) []value.Value
func github.com/freeeve/gochickpeas/gql/internal/semantics.Desugar(q *Query) error
QueryMode says how a query runs: normally, or as EXPLAIN (plan only) /
PROFILE (plan annotated with actual per-operator row counts).
const Explain
const Profile
const Run
QueryPart is one UNION branch: zero or more reading / projection-boundary
clauses, then the final projection.
Clauses []Clause
Ret Projection
Reduce is reduce(acc = init, x IN list | body): left-fold a list
(engine node; no GQL surface syntax yet).
Acc string
Body Expr
Init Expr
List Expr
Var string
*Reduce : Expr
RelPat is one relationship pattern.
Dir Dir
Length is non-nil for a quantified relationship (-[:T]->{1,3}, *, +);
nil is a single fixed hop.
PropExprs []PropExprEntry
Props []PropEntry
Types []string
// "" when anonymous
Where is the element pattern's inline predicate ([r:T WHERE expr]);
the desugar pass conjoins it onto the clause WHERE.
ShortestPath is a path-search binding: GQL `MATCH p = ANY SHORTEST pat`
(All false) / `ALL SHORTEST pat` (All true), optionally weighted via
the COST clause. Binds PathVar between already-bound endpoints.
All bool
Optional bool
PathVar string
Pattern Pattern
// nil for hop-minimal
// nil when absent
*ShortestPath : Clause
Slice is base[from..to]; either bound may be nil; negative bounds count
from the end.
Base Expr
// nil when omitted
// nil when omitted
*Slice : Expr
UnionKind says how two adjacent QueryParts combine.
const UnionAll
const UnionDistinct
const UnionExcept
const UnionIntersect
Unwind is GQL `FOR var IN expr`: expand a list to rows -- for each input
row, emit one output row per element with var bound to it. An empty list
or null emits no rows for that input row.
Expr Expr
Var string
*Unwind : Clause
VarLength is a quantifier's bound spec. Nil bounds mean unspecified
(`*` => both nil; `{2,}` => Max nil; `{,3}` => Min nil; `{2}` => Min ==
Max).
Max *uint64
Min *uint64
With is the projection boundary: project columns forward, then
optionally filter the projected rows. GQL surface forms that lower here:
RETURN...NEXT (the projection), LET (star + extra items), FILTER (star +
where).
Proj Projection
// nil when absent
*With : Clause
Package-Level Functions (total 9)
BoolLit is a boolean literal.
Fingerprint is the canonical rendering of q.
FloatLit is a float literal.
IntLit is an integer literal.
NamedParamLit is a $name parameter.
NullLit is the null literal.
ParamLit is an auto-lifted parameter slot.
StrLit is a string literal.
Walk visits e and every sub-expression in pre-order. Returning false
from f skips the node's children (the node itself was already visited).
Pattern-carrying nodes (Exists/CountSub/PatternComp) descend into their
inner WHERE / projection expressions and the patterns' inline property
expressions, so a pass that rewrites literals or checks references sees
every expression a query evaluates.
Package-Level Constants (total 51)
CostConstant gives every traversed relationship a fixed weight.
CostExpr evaluates a per-edge weight formula referencing only the
path's relationship variable.
CostProperty reads the named relationship property as the edge weight.
DirBoth is -[...]-.
DirIn is <-[...]-.
DirOut is -[...]->.
Explain renders the plan without executing.
LabelAnd is `a & b`.
LabelName is a single label test.
LabelNot is `!a` (operand in L).
LabelOr is `a | b`.
LabelWild is `%`: the node carries at least one label.
LitBool is a boolean literal.
LitFloat is a float literal.
LitInt is an integer literal.
LitNamedParam is an explicit $name parameter.
LitNull is null.
LitParam is an auto-lifted parameter slot -- never produced by the
parser; the autoparam pass replaces constants so queries differing
only in a constant share one cached plan.
LitStr is a string literal.
MapProjAll is .* (all properties).
MapProjField is name: expr.
MapProjProp is .key.
Neg is arithmetic negation.
Not is boolean negation.
OpAdd is +.
OpAnd is AND.
OpConcat is || -- string/list concatenation only (null otherwise;
unlike +, it never adds numbers).
OpContains is CONTAINS.
OpDiv is /.
OpEndsWith is ENDS WITH.
OpEq is =.
OpGt is >.
OpGte is >=.
OpLt is <.
OpLte is <=.
OpMul is *.
OpNeq is <>.
OpOr is OR.
OpStartsWith is STARTS WITH (comparison precedence).
OpSub is -.
OpXor is XOR (three-valued: null when either side is null).
Profile executes and annotates the plan with row counts.
QuantAll is all(...).
QuantAny is any(...).
QuantNone is none(...).
QuantSingle is single(...).
Run executes normally.
UnionAll is UNION ALL: combine branches keeping every row.
UnionDistinct is UNION: combine branches, removing duplicate rows.
UnionExcept is EXCEPT: rows of the left side (deduplicated) not
present in the right side.
UnionIntersect is INTERSECT: rows (deduplicated) present on both
sides.
![]() |
The pages are generated with Golds v0.8.7. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |