Skip to main content

Parser

Struct Parser 

Source
pub struct Parser<'a> { /* private fields */ }
Expand description

Recursive descent parser for the openCypher subset.

Implementations§

Source§

impl<'a> Parser<'a>

Source

pub fn parse_match_clause( &mut self, optional: bool, ) -> Result<MatchClause, ParseError>

Parse a MATCH clause (TASK-028).

Expects the parser to be positioned at the MATCH keyword. The optional flag indicates whether OPTIONAL was already consumed by the caller.

Grammar: MATCH pattern [WHERE expression]

Source

pub fn parse_return_clause(&mut self) -> Result<ReturnClause, ParseError>

Parse a RETURN clause (TASK-029, TASK-030).

Grammar: RETURN [DISTINCT] items [ORDER BY order_items] [SKIP expr] [LIMIT expr]

Source

pub fn parse_create_clause(&mut self) -> Result<CreateClause, ParseError>

Parse a CREATE clause (TASK-031).

Grammar: CREATE pattern

Source

pub fn parse_set_clause(&mut self) -> Result<SetClause, ParseError>

Parse a SET clause (TASK-032).

Grammar: SET property = expression [, property = expression]*

Source

pub fn parse_remove_clause(&mut self) -> Result<RemoveClause, ParseError>

Parse a REMOVE clause (TASK-032).

Grammar: REMOVE (property_access | variable:Label) [, …]*

Source

pub fn parse_delete_clause( &mut self, detach: bool, ) -> Result<DeleteClause, ParseError>

Parse a DELETE clause (TASK-033).

Grammar: DELETE expression [, expression]* The detach flag indicates whether DETACH was already consumed.

Source

pub fn parse_with_clause(&mut self) -> Result<WithClause, ParseError>

Parse a WITH clause (P2 syntax – parsed but execution returns UnsupportedSyntax).

Grammar: WITH [DISTINCT] items [WHERE expression]

Source

pub fn parse_unwind_clause(&mut self) -> Result<UnwindClause, ParseError>

Parse an UNWIND clause (TASK-068).

Grammar: UNWIND expression AS variable

Source

pub fn parse_merge_clause(&mut self) -> Result<MergeClause, ParseError>

Parse a MERGE clause.

Grammar: MERGE pattern [ON MATCH SET items] [ON CREATE SET items]

Source

pub fn parse_create_index_clause( &mut self, ) -> Result<CreateIndexClause, ParseError>

Parse a CREATE INDEX clause (TASK-098).

Grammar: CREATE INDEX [name] ON :Label(property) The parser has already consumed CREATE and is positioned at INDEX.

Source

pub fn parse_create_edge_index_clause( &mut self, ) -> Result<CreateIndexClause, ParseError>

Parse a CREATE EDGE INDEX clause (CC-T3).

Grammar: CREATE EDGE INDEX [name] ON :RelType(property) The parser has already consumed CREATE and is positioned at EDGE.

Source

pub fn parse_drop_index_clause(&mut self) -> Result<DropIndexClause, ParseError>

Parse a DROP INDEX clause (TASK-098).

Grammar: DROP INDEX name

Source

pub fn parse_create_snapshot_clause( &mut self, ) -> Result<CreateSnapshotClause, ParseError>

Parse a CREATE SNAPSHOT clause (HH-001).

Grammar: CREATE SNAPSHOT (var:Label {props}) [AT TIME expr] FROM MATCH pattern [WHERE filter] RETURN items The parser has already consumed CREATE and is positioned at SNAPSHOT.

Source

pub fn parse_create_hyperedge_clause( &mut self, ) -> Result<CreateHyperedgeClause, ParseError>

Parse a CREATE HYPEREDGE clause (MM-001).

Grammar: CREATE HYPEREDGE (var:Label) FROM (expr [AT TIME expr], …) TO (expr [AT TIME expr], …) The parser has already consumed CREATE and is positioned at HYPEREDGE.

Source

pub fn parse_match_hyperedge_clause( &mut self, ) -> Result<MatchHyperedgeClause, ParseError>

Parse a MATCH HYPEREDGE clause (MM-003).

Grammar: MATCH HYPEREDGE (var:Label) The parser has already consumed MATCH and is positioned at HYPEREDGE.

Source§

impl<'a> Parser<'a>

Source

pub fn parse_expression(&mut self) -> Result<Expression, ParseError>

Parse an expression using Pratt parsing (precedence climbing).

Source

pub fn parse_expression_no_and(&mut self) -> Result<Expression, ParseError>

Parse an expression but stop before AND/OR (for BETWEEN TIME expr AND expr). This prevents the AND keyword from being consumed as a binary AND operator.

Source§

impl<'a> Parser<'a>

Source

pub fn parse_pattern(&mut self) -> Result<Pattern, ParseError>

Parse a full pattern: node (rel node)* (, node (rel node)*)*

Source

pub fn parse_node_pattern(&mut self) -> Result<NodePattern, ParseError>

Parse a node pattern: (variable:Label:Label2 {prop: value, ...}) All parts are optional except the parentheses.

Source

pub fn parse_map_literal(&mut self) -> Result<MapLiteral, ParseError>

Parse a map literal: {key: value, key: value, ...}

Source§

impl<'a> Parser<'a>

Source

pub fn new(tokens: &'a [(Token, Span)], input: &'a str) -> Self

Create a new parser over the given token slice and source text.

Source

pub fn peek(&self) -> Option<&Token>

Peek at the current token without consuming it.

Source

pub fn advance(&mut self) -> Option<&(Token, Span)>

Advance the parser by one token, returning the consumed token and span.

Source

pub fn expect(&mut self, expected: &Token) -> Result<Span, ParseError>

Expect a specific token, consuming it. Returns the span on success.

Source

pub fn check(&self, expected: &Token) -> bool

Check if the current token matches without consuming it.

Source

pub fn eat(&mut self, expected: &Token) -> bool

Consume the current token if it matches, returning true.

Source

pub fn current_span(&self) -> Span

Return the span of the current token, or a zero-length span at EOF.

Source

pub fn offset_to_line_col(&self, offset: usize) -> (usize, usize)

Convert byte offset to (line, column) using the input string.

Source

pub fn error(&self, message: impl Into<String>) -> ParseError

Return a ParseError at the current position with the given message.

Source

pub fn at_end(&self) -> bool

Return true when there are no more tokens.

Source

pub fn expect_ident(&mut self) -> Result<String, ParseError>

Expect and consume an identifier, returning its name.

Auto Trait Implementations§

§

impl<'a> Freeze for Parser<'a>

§

impl<'a> RefUnwindSafe for Parser<'a>

§

impl<'a> Send for Parser<'a>

§

impl<'a> Sync for Parser<'a>

§

impl<'a> Unpin for Parser<'a>

§

impl<'a> UnsafeUnpin for Parser<'a>

§

impl<'a> UnwindSafe for Parser<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.