token

package
v0.2.4 Latest Latest
Warning

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

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

Documentation

Overview

Package token defines constants representing the lexical tokens of Cypher.

Cypher is a declarative graph query language used primarily by Neo4j and the openCypher project. This package provides token types for the full openCypher 9 specification, covering clauses, expressions, operators, literals, and structural punctuation specific to graph patterns.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Position

type Position struct {
	Line   int
	Column int
	Offset int
}

Position represents an absolute offset plus line/column in source text.

type Token

type Token struct {
	Type    Type
	Literal string
	Line    int
	Column  int
}

Token represents a lexical token with source-position information.

type Type

type Type int

Type represents the type of a lexical token.

const (
	// Special tokens
	ILLEGAL Type = iota
	EOF
	COMMENT // // line comment  or  /* block comment */

	// Identifiers and literals
	IDENT     // identifier, label, property key
	INT       // 42
	FLOAT     // 3.14
	STRING    // 'hello' or "hello"
	TRUE      // true
	FALSE     // false
	NULL      // null
	PARAMETER // $param or {param}

	// Operators — arithmetic
	PLUS     // +
	MINUS    // -
	ASTERISK // *
	SLASH    // /
	PERCENT  // %
	CARET    // ^ (exponentiation)

	// Operators — comparison
	EQ  // =
	NEQ // <>
	LT  // <
	GT  // >
	LTE // <=
	GTE // >=

	// Operators — string / list
	CONCAT    // + (overloaded; context-resolved in parser)
	CONCAT_OP // || (GQL string concatenation)
	TILDE_EQ  // =~ (regex match)

	// Delimiters
	COMMA          // ,
	SEMICOLON      // ;
	LPAREN         // (
	RPAREN         // )
	LBRACKET       // [
	RBRACKET       // ]
	LBRACE         // {
	RBRACE         // }
	DOT            // .
	DOTDOT         // ..   (range in relationship patterns)
	COLON          // :    (label / type separator)
	PIPE           // |    (alternative relationship types)
	AMPERSAND      // &    (label boolean AND)
	BANG           // !    (label boolean NOT)
	ARROW_RIGHT    // ->   (directed relationship, right)
	ARROW_LEFT     // <-   (directed relationship, left)
	DASH           // -    (undirected / relationship body, same rune as MINUS — resolved by lexer context)
	BACKTICK_IDENT // `escaped identifier`

	// -------------------------------------------------------------------------
	// Reading clauses
	// -------------------------------------------------------------------------
	MATCH
	OPTIONAL
	WITH
	UNWIND
	CALL  // procedure call
	YIELD // CALL ... YIELD

	// -------------------------------------------------------------------------
	// Writing clauses
	// -------------------------------------------------------------------------
	CREATE
	MERGE
	SET
	DELETE
	DETACH
	REMOVE
	FOREACH

	// -------------------------------------------------------------------------
	// Projection / modifiers
	// -------------------------------------------------------------------------
	RETURN
	ORDER
	BY
	SKIP
	LIMIT
	DISTINCT
	AS
	ASCENDING
	ASC
	DESCENDING
	DESC

	// -------------------------------------------------------------------------
	// Subquery / composite
	// -------------------------------------------------------------------------
	UNION
	ALL
	EXISTS // EXISTS { ... } subquery pattern

	// -------------------------------------------------------------------------
	// Predicates / conditions
	// -------------------------------------------------------------------------
	WHERE
	AND
	OR
	XOR
	NOT
	IN
	IS
	STARTS
	ENDS
	CONTAINS
	CASE
	WHEN
	THEN
	ELSE
	END

	// -------------------------------------------------------------------------
	// Path functions / quantifiers
	// -------------------------------------------------------------------------
	SHORTESTPATH
	ALLSHORTESTPATHS
	ANY    // list/path quantifier
	NONE   // list/path quantifier
	SINGLE // list/path quantifier — list quantifier "SINGLE(x IN list WHERE ...)"
	FILTER // deprecated but still in use: FILTER(x IN list WHERE ...)

	// -------------------------------------------------------------------------
	// Literals with keyword form
	// -------------------------------------------------------------------------
	COUNT   // COUNT(*), COUNT(DISTINCT ...)
	COLLECT // COLLECT { } subquery expression (Neo4j 5+)

	// -------------------------------------------------------------------------
	// ON clause (used in MERGE)
	// -------------------------------------------------------------------------
	ON
	MATCH_KW // ON MATCH SET  (the MATCH inside ON MATCH is the same token as MATCH above)

	// -------------------------------------------------------------------------
	// Load data
	// -------------------------------------------------------------------------
	LOAD
	CSV
	FROM
	HEADERS

	// -------------------------------------------------------------------------
	// Show / admin (openCypher extensions widely supported)
	// -------------------------------------------------------------------------
	SHOW
	INDEXES
	CONSTRAINTS
	PROCEDURES
	DATABASES
	DATABASE

	// -------------------------------------------------------------------------
	// Type system keywords
	// -------------------------------------------------------------------------
	BOOLEAN
	INTEGER
	FLOAT_KW  // FLOAT as a type keyword (not the literal)
	STRING_KW // STRING as a type keyword
	DATE
	TIME
	DATETIME
	LOCALDATETIME
	LOCALTIME
	DURATION
	POINT
	NODE
	RELATIONSHIP
	MAP
	LIST
	PATH
	GRAPH
	NOTHING
	ANY_KW // ANY as a type (not the quantifier) — see openCypher type system

	// -------------------------------------------------------------------------
	// Namespace keyword
	// -------------------------------------------------------------------------
	NAMESPACE // for procedure/function qualified names: apoc.util.sleep

	// -------------------------------------------------------------------------
	// Cypher 25 clause keywords
	// -------------------------------------------------------------------------
	FINISH

	// -------------------------------------------------------------------------
	// Subquery / transaction keywords (Neo4j 5+)
	// -------------------------------------------------------------------------
	CONCURRENT   // CONCURRENT
	TRANSACTIONS // TRANSACTIONS
	OF           // OF
	ROWS         // ROWS

)

func LookupIdent

func LookupIdent(ident string) Type

LookupIdent performs a case-insensitive keyword lookup. Returns IDENT if the string is not a Cypher keyword.

func (Type) IsKeyword

func (t Type) IsKeyword() bool

IsKeyword returns true when the token type is a reserved keyword.

func (Type) String

func (t Type) String() string

String returns the human-readable name of this token type.

Jump to

Keyboard shortcuts

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