cypher

package module
v0.0.0-...-6d50254 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2019 License: MIT Imports: 6 Imported by: 0

README

cypher-parser

Cypher Query Language parser in Go.

References

This code is based on https://github.com/influxdata/influxql and modified for the Cypher language.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ScanBareIdent

func ScanBareIdent(r io.RuneScanner) string

ScanBareIdent reads bare identifier from a rune reader.

func ScanString

func ScanString(r io.RuneScanner) (string, error)

ScanString reads a quoted string from a rune reader.

Types

type EdgeDirection

type EdgeDirection int

EdgeDirection ...

const (
	EdgeUndefined EdgeDirection = iota
	EdgeRight
	EdgeLeft
	EdgeOutgoing
)

type EdgePattern

type EdgePattern struct {
	Variable   *string
	Labels     []string
	Properties map[string]Expr
	MinHops    *int
	MaxHops    *int
	Direction  EdgeDirection
}

EdgePattern ...

func (EdgePattern) String

func (ep EdgePattern) String() string

func (EdgePattern) Var

func (ep EdgePattern) Var() *string

Var ...

type Expr

type Expr interface {
	String() string
	// contains filtered or unexported methods
}

Expr ...

type MatchPattern

type MatchPattern struct {
	Variable *Variable
	Elements []PatternElement
}

MatchPattern ...

func (MatchPattern) String

func (mp MatchPattern) String() string

type NodePattern

type NodePattern struct {
	Variable   *Variable
	Labels     []string
	Properties map[string]Expr
}

NodePattern ...

func (NodePattern) String

func (np NodePattern) String() string

type OrderBy

type OrderBy struct {
	Dir  OrderDirection
	Item Expr
}

OrderBy ...

func (OrderBy) String

func (o OrderBy) String() string

type OrderDirection

type OrderDirection int

OrderDirection ...

const (
	// Ascending defines the ascending ordering.
	Ascending OrderDirection = iota
	// Descending defines the descending ordering.
	Descending
)

type ParseError

type ParseError struct {
	Message  string
	Found    string
	Expected []string
	Pos      Pos
}

ParseError represents an error that occurred during parsing.

func (*ParseError) Error

func (e *ParseError) Error() string

Error returns the string representation of the error.

type Parser

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

Parser represents a Cypher parser.

func NewParser

func NewParser(r io.Reader) *Parser

NewParser returns a new instance of Parser.

func (*Parser) ParseQuery

func (p *Parser) ParseQuery() (q Query, err error)

ParseQuery parses a Cypher string and returns a Query AST object.

func (*Parser) ParseSingleQuery

func (p *Parser) ParseSingleQuery() (*SingleQuery, error)

ParseSingleQuery ...

func (*Parser) Scan

func (p *Parser) Scan() (tok Token, pos Pos, lit string)

Scan returns the next token from the underlying scanner.

func (*Parser) ScanEdgePattern

func (p *Parser) ScanEdgePattern() (*EdgePattern, error)

ScanEdgePattern returns an EdgePattern if possible to consume a complete valid edge.

func (*Parser) ScanExpression

func (p *Parser) ScanExpression() (Expr, error)

ScanExpression ...

func (*Parser) ScanIgnoreWhitespace

func (p *Parser) ScanIgnoreWhitespace() (tok Token, pos Pos, lit string)

ScanIgnoreWhitespace scans the next non-whitespace and non-comment token.

func (*Parser) ScanMatchPattern

func (p *Parser) ScanMatchPattern() (*MatchPattern, error)

ScanMatchPattern ...

func (*Parser) ScanNodePattern

func (p *Parser) ScanNodePattern() (*NodePattern, error)

ScanNodePattern returns a NodePattern if possible to consume a complete valid node.

func (*Parser) ScanPatternElements

func (p *Parser) ScanPatternElements() (pe []PatternElement, err error)

ScanPatternElements ...

func (*Parser) ScanProperties

func (p *Parser) ScanProperties() (*map[string]Expr, error)

ScanProperties ...

func (*Parser) ScanReadingClause

func (p *Parser) ScanReadingClause() (*ReadingClause, error)

ScanReadingClause ...

func (*Parser) Unscan

func (p *Parser) Unscan()

Unscan pushes the previously read token back onto the buffer.

type PatternElement

type PatternElement interface {
	String() string
	// contains filtered or unexported methods
}

PatternElement ...

type Pos

type Pos struct {
	Line int
	Char int
}

Pos specifies the line and character position of a token. The Char and Line are both zero-based indexes.

type Query

type Query struct {
	Root *SingleQuery
}

Query represents the Cypher query root element.

func ParseQuery

func ParseQuery(s string) (Query, error)

ParseQuery parses a query string and returns its AST representation.

func (Query) String

func (q Query) String() string

type ReadingClause

type ReadingClause struct {
	OptionalMatch bool
	Pattern       []MatchPattern
	Where         *Expr
}

ReadingClause ...

func (ReadingClause) String

func (rc ReadingClause) String() string

type Scanner

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

Scanner is a lexical scanner.

func NewScanner

func NewScanner(r io.Reader) *Scanner

NewScanner returns a new instance of Scanner.

func (*Scanner) Scan

func (s *Scanner) Scan() (Token, Pos, string)

Scan returns the next token from the input.

type SingleQuery

type SingleQuery struct {
	Reading     []ReadingClause
	Distinct    bool
	ReturnItems []Expr
	Order       []OrderBy
	Skip        *Expr
	Limit       *Expr
}

SingleQuery ...

func (SingleQuery) String

func (sq SingleQuery) String() string

type StrLiteral

type StrLiteral string

StrLiteral ...

func (StrLiteral) String

func (s StrLiteral) String() string

type Symbol

type Symbol string

Symbol ...

func (Symbol) String

func (s Symbol) String() string

type Token

type Token int

Token is a lexical token of the Cypher language.

const (
	// ILLEGAL Token, EOF, WS are Special Cypher tokens.
	ILLEGAL Token = iota
	EOF
	WS
	COMMENT

	// IDENT and the following are literal tokens.
	IDENT     // main
	NUMBER    // 12345.67
	INTEGER   // 12345
	STRING    // "abc"
	BADSTRING // "abc
	BADESCAPE // "\q
	TRUE      // true
	FALSE     // false
	NULL      // null

	PLUS // +
	SUB  // -
	MUL  // *
	DIV  // /
	MOD  // %
	POW  // ^
	EQ   // =
	NEQ  // <>
	LT   // <
	LTE  // <=
	GT   // >
	GTE  // >=
	INC  // +=
	BAR  // |

	AND // AND
	OR  // OR
	XOR // XOR
	NOT // NOT

	LPAREN    // (
	RPAREN    // )
	LBRACE    // {
	RBRACE    // }
	LBRACKET  // [
	RBRACKET  // ]
	COMMA     // ,
	COLON     // :
	SEMICOLON // ;
	DOT       // .
	DOUBLEDOT // ..

	// ALL and the following are Cypher Keywords
	ADD
	ALL
	AS
	ASC
	ASCENDING
	BY
	CASE
	CONSTRAINT
	CONTAINS
	CREATE
	DELETE
	DESC
	DESCENDING
	DETACH
	DISTINCT
	DO
	DROP
	ELSE
	END
	ENDS
	EXISTS
	FOR
	IN
	IS
	LIMIT
	MANDATORY
	MATCH
	MERGE
	OF
	ON
	OPTIONAL
	ORDER
	REMOVE
	REQUIRE
	RETURN
	SCALAR
	SET
	SKIP
	STARTS
	THEN
	UNION
	UNIQUE
	UNWIND
	WHEN
	WHERE
	WITH
)

func Lookup

func Lookup(ident string) Token

Lookup returns the token associated with a given string.

func (Token) String

func (tok Token) String() string

String returns the string representation of the token.

type Variable

type Variable string

Variable ...

func (Variable) String

func (v Variable) String() string

Jump to

Keyboard shortcuts

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