parser

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Graph label boolean expression miniparser for sulpher.

Neo4j 5 introduced a boolean expression grammar for label and relationship-type filters inside node and relationship patterns:

(n:Person&Employee)         — node must have both labels
(n:Person|Employee)         — node must have at least one label
(n:!Deleted)                — node must not have the label
(n:%)                       — node may have any label (wildcard)
(n:(Person|Employee)&!Bot)  — grouped expression
-[:KNOWS|LIKES]->           — simple form (already handled by pattern.go)
-[:(KNOWS|LIKES)&!BLOCKED]->— boolean type filter (new form)

Grammar (precedence, low to high):

LabelOr   = LabelAnd  ( "|" LabelAnd  )*
LabelAnd  = LabelNot  ( "&" LabelNot  )*
LabelNot  = "!" LabelNot | LabelAtom
LabelAtom = LabelName | "%" | "(" LabelOr ")"

This miniparser owns only the label expression itself. The surrounding colon and pattern brackets are consumed by the pattern miniparser (pattern.go), which calls parseLabelFilter() when it detects a boolean operator after the first label.

Package parser implements a recursive-descent parser for Cypher.

The parser follows the openCypher 9 grammar as its specification target. It produces an *ast.Query root node and accumulates parse errors as strings (matching the tsqlparser error-reporting convention) rather than panicking.

Expression parsing uses the Pratt (top-down operator precedence) technique, identical to the approach in tsqlparser.

CALL subquery block miniparser for sulpher.

Neo4j 5 introduced CALL {} as a first-class clause distinct from the CALL procedureName(…) procedure invocation. This file owns all parsing for the block subquery form.

Supported forms:

CALL (var1, var2) { query }
CALL (var1, var2) { query } IN TRANSACTIONS
CALL (var1, var2) { query } IN TRANSACTIONS OF n ROWS
CALL (var1, var2) { query } IN n CONCURRENT TRANSACTIONS
CALL (var1, var2) { query } IN n TRANSACTIONS          -- alias

The deprecated importing-WITH form (Neo4j 4.x style) is also accepted:

CALL { WITH var1 … }

Detection: in parseClause(), when CALL is followed by ( or { (not an identifier), this parser is called instead of parseCallClause().

Index

Constants

View Source
const (
	LOWEST    int
	OR_PREC   // OR, XOR
	AND_PREC  // AND
	NOT_PREC  // NOT
	COMPARE   // =, <>, <, >, <=, >=
	STRING_OP // STARTS WITH, ENDS WITH, CONTAINS, =~
	IN_PREC   // IN, IS NULL, IS NOT NULL
	SUM       // +, -
	PRODUCT   // *, /, %
	UNARY     // unary -, +
	POWER     // ^
	CALL      // function calls, subscript
	PROPERTY  // .property, [index]
)

Operator precedence levels — higher number binds tighter.

Variables

This section is empty.

Functions

This section is empty.

Types

type Parser

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

Parser holds parser state.

func New

func New(l *lexer.Lexer) *Parser

New creates a new Parser for the given Lexer.

func (*Parser) Errors

func (p *Parser) Errors() []string

Errors returns all parse errors accumulated so far.

func (*Parser) ParseQuery

func (p *Parser) ParseQuery() *ast.Query

ParseQuery parses a complete Cypher query and returns the AST root.

Jump to

Keyboard shortcuts

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