Skip to main content

Parser

Struct Parser 

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

The SurrealQL parser.

Fields§

§table_as_field: bool

Implementations§

Source§

impl Parser<'_>

Source

pub fn next_token_value<V: TokenValue>(&mut self) -> ParseResult<V>

Parse a token value from the next token in the parser.

Source

pub fn parse_string_lit(&mut self) -> ParseResult<String>

Source

pub fn parse_ident(&mut self) -> ParseResult<String>

Source

pub fn parse_ident_str(&mut self) -> ParseResult<&str>

Source

pub fn parse_flexible_ident(&mut self) -> ParseResult<String>

Source§

impl Parser<'_>

Source

pub async fn parse_expr_start(&mut self, stk: &mut Stk) -> ParseResult<Expr>

Parse a generic expression without triggering the query depth and setting table_as_field.

Meant to be used when parsing an expression the first time to avoid having the depth limit be lowered unnecessarily.

Source

pub async fn parse_expr_table(&mut self, stk: &mut Stk) -> ParseResult<Expr>

Parsers a generic value.

A generic loose ident like foo in for example foo.bar can be two different values depending on context: a table or a field the current document. This function parses loose idents as a table, see [parse_expr_field] for parsing loose idents as fields

Source

pub async fn parse_expr_field(&mut self, stk: &mut Stk) -> ParseResult<Expr>

Parsers a generic value.

A generic loose ident like foo in for example foo.bar can be two different values depending on context: a table or a field the current document. This function parses loose idents as a field, see [parse_expr_table] for parsing loose idents as table

Source

pub fn reject_letless_let(expr: &Expr, span: Span) -> ParseResult<()>

Source§

impl Parser<'_>

Source§

impl Parser<'_>

Source

pub async fn parse_fields(&mut self, stk: &mut Stk) -> ParseResult<Fields>

Parse fields of a selecting query: foo, bar in SELECT foo, bar FROM baz.

§Parser State

Expects the next tokens to be of a field set.

Source

pub async fn parse_plain_idiom(&mut self, stk: &mut Stk) -> ParseResult<Idiom>

Parse a idiom which can only start with a graph or an identifier. Other expressions are not allowed as start of this idiom

Source§

impl Parser<'_>

Source

pub async fn parse_kind( &mut self, stk: &mut Stk, delim: Span, ) -> ParseResult<Kind>

Parse a kind production.

§Parser State

expects the first < to already be eaten

Source

pub async fn parse_inner_kind(&mut self, stk: &mut Stk) -> ParseResult<Kind>

Parse an inner kind, a kind without enclosing < >.

Source§

impl Parser<'_>

Source

pub async fn parse_set( &mut self, stk: &mut Stk, start: Span, ) -> ParseResult<Vec<Expr>>

Source

pub async fn parse_block( &mut self, stk: &mut Stk, start: Span, ) -> ParseResult<Block>

Parses a block of statements.

§Parser State

Expects the starting { to have already been eaten and its span to be handed to this functions as the start parameter.

Source§

impl Parser<'_>

Source

pub async fn parse_array( &mut self, stk: &mut Stk, start: Span, ) -> ParseResult<Vec<Expr>>

Parses an array production

§Parser state

Expects the starting [ to already be eaten and its span passed as an argument.

Source§

impl Parser<'_>

Source

pub async fn parse_record_id_or_range( &mut self, stk: &mut Stk, ident: String, ) -> ParseResult<RecordIdLit>

Source

pub async fn parse_id_range( &mut self, stk: &mut Stk, ) -> ParseResult<RecordIdKeyRangeLit>

Source

pub async fn parse_lookup_subject( &mut self, stk: &mut Stk, supports_referencing_field: bool, ) -> ParseResult<LookupSubject>

Source

pub async fn parse_referencing_field( &mut self, supports_referencing_field: bool, ) -> ParseResult<Option<String>>

Source

pub async fn parse_record_id( &mut self, stk: &mut Stk, ) -> ParseResult<RecordIdLit>

Source

pub async fn parse_record_id_from_ident( &mut self, stk: &mut Stk, ident: String, ) -> ParseResult<RecordIdLit>

Source

pub async fn parse_record_id_key( &mut self, stk: &mut Stk, ) -> ParseResult<RecordIdKeyLit>

Source§

impl Parser<'_>

Source

pub async fn parse_alter_stmt( &mut self, stk: &mut Stk, ) -> ParseResult<AlterStatement>

Source

pub async fn parse_alter_system( &mut self, stk: &mut Stk, ) -> ParseResult<AlterSystemStatement>

Source

pub async fn parse_alter_namespace( &mut self, ) -> ParseResult<AlterNamespaceStatement>

Source

pub async fn parse_alter_database( &mut self, ) -> ParseResult<AlterDatabaseStatement>

Source

pub async fn parse_alter_table( &mut self, stk: &mut Stk, ) -> ParseResult<AlterTableStatement>

Source

pub async fn parse_alter_index(&mut self) -> ParseResult<AlterIndexStatement>

Source

pub async fn parse_alter_field( &mut self, stk: &mut Stk, ) -> ParseResult<AlterFieldStatement>

Source

pub async fn parse_alter_sequence( &mut self, stk: &mut Stk, ) -> ParseResult<AlterSequenceStatement>

Source§

impl Parser<'_>

Source

pub async fn parse_create_stmt( &mut self, stk: &mut Stk, ) -> ParseResult<CreateStatement>

Source§

impl Parser<'_>

Source

pub async fn parse_define_stmt( &mut self, stk: &mut Stk, ) -> ParseResult<DefineStatement>

Source

pub async fn parse_define_namespace( &mut self, stk: &mut Stk, ) -> ParseResult<DefineNamespaceStatement>

Source

pub async fn parse_define_database( &mut self, stk: &mut Stk, ) -> ParseResult<DefineDatabaseStatement>

Source

pub async fn parse_define_function( &mut self, stk: &mut Stk, ) -> ParseResult<DefineFunctionStatement>

Source

pub async fn parse_define_module( &mut self, _stk: &mut Stk, ) -> ParseResult<DefineModuleStatement>

Source

pub async fn parse_define_user( &mut self, stk: &mut Stk, ) -> ParseResult<DefineUserStatement>

Source

pub async fn parse_define_access( &mut self, stk: &mut Stk, ) -> ParseResult<DefineAccessStatement>

Source

pub async fn parse_define_param( &mut self, stk: &mut Stk, ) -> ParseResult<DefineParamStatement>

Source

pub async fn parse_define_table( &mut self, stk: &mut Stk, ) -> ParseResult<DefineTableStatement>

Source

pub async fn parse_define_api( &mut self, stk: &mut Stk, ) -> ParseResult<DefineApiStatement>

Source

pub async fn parse_define_event( &mut self, stk: &mut Stk, ) -> ParseResult<DefineEventStatement>

Source

pub async fn parse_define_field( &mut self, stk: &mut Stk, ) -> ParseResult<DefineFieldStatement>

Source

pub async fn parse_define_index( &mut self, stk: &mut Stk, ) -> ParseResult<DefineIndexStatement>

Source

pub async fn parse_define_analyzer( &mut self, stk: &mut Stk, ) -> ParseResult<DefineAnalyzerStatement>

Source

pub async fn parse_define_bucket( &mut self, stk: &mut Stk, token: Token, ) -> ParseResult<DefineBucketStatement>

Source

pub async fn parse_define_sequence( &mut self, stk: &mut Stk, ) -> ParseResult<DefineSequenceStatement>

Source

pub async fn parse_define_config( &mut self, stk: &mut Stk, ) -> ParseResult<DefineConfigStatement>

Source

pub async fn parse_default_config( &mut self, stk: &mut Stk, ) -> ParseResult<DefaultConfig>

Source

pub async fn parse_api_config( &mut self, stk: &mut Stk, ) -> ParseResult<ApiConfig>

Source

pub fn parse_relation_schema(&mut self) -> ParseResult<Relation>

Source

pub fn parse_tables(&mut self) -> ParseResult<Vec<String>>

Source§

impl Parser<'_>

Source

pub async fn parse_delete_stmt( &mut self, stk: &mut Stk, ) -> ParseResult<DeleteStatement>

Source§

impl Parser<'_>

Source

pub async fn parse_if_stmt( &mut self, stk: &mut Stk, ) -> ParseResult<IfelseStatement>

Source§

impl Parser<'_>

Source

pub async fn parse_insert_stmt( &mut self, stk: &mut Stk, ) -> ParseResult<InsertStatement>

Source§

impl Parser<'_>

Source

pub async fn try_parse_data( &mut self, stk: &mut Stk, ) -> ParseResult<Option<Data>>

Parses a data production if the next token is a data keyword. Otherwise returns None

Source

pub async fn try_parse_output( &mut self, stk: &mut Stk, ) -> ParseResult<Option<Output>>

Parses a statement output if the next token is return.

Source

pub async fn parse_output(&mut self, stk: &mut Stk) -> ParseResult<Output>

Needed because some part of the RPC needs to call into the parser for this specific part.

Source

pub async fn try_parse_timeout(&mut self, stk: &mut Stk) -> ParseResult<Expr>

Parses a statement timeout if the next token is TIMEOUT.

Source

pub async fn try_parse_fetch( &mut self, stk: &mut Stk, ) -> ParseResult<Option<Fetchs>>

Source

pub async fn parse_fetchs(&mut self, stk: &mut Stk) -> ParseResult<Fetchs>

Source

pub async fn try_parse_param_or_idiom_or_fields( &mut self, stk: &mut Stk, ) -> ParseResult<Vec<Fetch>>

Source

pub async fn try_parse_condition( &mut self, stk: &mut Stk, ) -> ParseResult<Option<Cond>>

Source

pub fn check_idiom( kind: MissingKind, fields: &Fields, field_span: Span, idiom: &Idiom, idiom_span: Span, ) -> ParseResult<()>

Move this out of the parser.

Source

pub fn try_parse_group( &mut self, fields: &Fields, fields_span: Span, split_span: Option<Span>, ) -> ParseResult<Option<Groups>>

Source

pub async fn parse_permission( &mut self, stk: &mut Stk, field: bool, ) -> ParseResult<Permissions>

Parse a permissions production

§Parser State

Expects the parser to have just eaten the PERMISSIONS keyword.

Source

pub async fn parse_specific_permission( &mut self, stk: &mut Stk, permissions: &mut Permissions, field: bool, ) -> ParseResult<()>

Parse a specific permission for a type of query

Sets the permission for a specific query on the given permission keyword.

§Parser State

Expects the parser to just have eaten the FOR keyword.

Source

pub async fn parse_permission_value( &mut self, stk: &mut Stk, ) -> ParseResult<Permission>

Parses a the value for a permission for a type of query

§Parser State

Expects the parser to just have eaten either SELECT, CREATE, UPDATE or DELETE.

Source

pub fn parse_base(&mut self) -> ParseResult<Base>

Parses a base

So either NAMESPACE, DATABASE, ROOT, or SCOPE if scope_allowed is true.

§Parser state

Expects the next keyword to be a base.

Source

pub fn parse_changefeed(&mut self) -> ParseResult<ChangeFeed>

Parses a changefeed production

§Parser State

Expects the parser to have already eating the CHANGEFEED keyword

Source

pub async fn parse_reference(&mut self, stk: &mut Stk) -> ParseResult<Reference>

Parses a reference

§Parser State

Expects the parser to have already eating the REFERENCE keyword

Source

pub async fn parse_view(&mut self, stk: &mut Stk) -> ParseResult<View>

Parses a view production

§Parse State

Expects the parser to have already eaten the possible ( if the view was wrapped in parens. Expects the next keyword to be SELECT.

Source

pub fn parse_distance(&mut self) -> ParseResult<Distance>

Source

pub fn parse_vector_type(&mut self) -> ParseResult<VectorType>

Source

pub fn parse_custom_function_name(&mut self) -> ParseResult<String>

Source§

impl Parser<'_>

Source

pub async fn parse_relate_stmt( &mut self, stk: &mut Stk, ) -> ParseResult<RelateStatement>

Source

pub async fn parse_relation( &mut self, stk: &mut Stk, ) -> ParseResult<(Expr, Expr, Expr)>

Source

pub async fn parse_relate_kind(&mut self, stk: &mut Stk) -> ParseResult<Expr>

Source

pub async fn parse_relate_expr(&mut self, stk: &mut Stk) -> ParseResult<Expr>

Source

pub async fn parse_thing_or_table(&mut self, stk: &mut Stk) -> ParseResult<Expr>

Source§

impl Parser<'_>

Source

pub async fn parse_remove_stmt( &mut self, stk: &mut Stk, ) -> ParseResult<RemoveStatement>

Source§

impl Parser<'_>

Source

pub async fn parse_select_stmt( &mut self, stk: &mut Stk, ) -> ParseResult<SelectStatement>

expects select to be eaten.

Source

pub fn try_parse_split( &mut self, fields: &Fields, fields_span: Span, ) -> ParseResult<Option<Splits>>

Source

pub fn try_parse_orders( &mut self, fields: &Fields, fields_span: Span, ) -> ParseResult<Option<Ordering>>

Source

pub async fn try_parse_limit( &mut self, stk: &mut Stk, ) -> ParseResult<Option<Limit>>

Source

pub async fn try_parse_start( &mut self, stk: &mut Stk, ) -> ParseResult<Option<Start>>

Source§

impl Parser<'_>

Source

pub async fn parse_update_stmt( &mut self, stk: &mut Stk, ) -> ParseResult<UpdateStatement>

Source§

impl Parser<'_>

Source

pub async fn parse_upsert_stmt( &mut self, stk: &mut Stk, ) -> ParseResult<UpsertStatement>

Source§

impl Parser<'_>

Source

pub async fn parse_value(&mut self, stk: &mut Stk) -> ParseResult<PublicValue>

Parse a complete value which cannot contain non-literal expressions.

Source

pub async fn parse_json(&mut self, stk: &mut Stk) -> ParseResult<PublicValue>

Source

pub async fn parse_value_record_id( &mut self, stk: &mut Stk, ) -> ParseResult<PublicRecordId>

Source§

impl<'a> Parser<'a>

Source

pub fn new(source: &'a [u8]) -> Self

Create a new parser from a give source.

Source

pub fn new_with_experimental(source: &'a [u8], enabled: bool) -> Self

Create a new parser from a give source.

Source

pub fn new_with_settings(source: &'a [u8], settings: ParserSettings) -> Self

Create a new parser from a give source.

Source

pub fn with_settings(self, settings: ParserSettings) -> Self

Source

pub fn next(&mut self) -> Token

Returns the next token and advance the parser one token forward.

Source

pub fn next_whitespace(&mut self) -> Option<Token>

Returns the next token and advance the parser one token forward.

This function is like next but returns whitespace tokens which are normally skipped

Source

pub fn has_peek(&self) -> bool

Returns if there is a token in the token buffer, meaning that a token was peeked.

Source

pub fn pop_peek(&mut self) -> Token

Consume the current peeked value and advance the parser one token forward.

Should only be called after peeking a value.

Source

pub fn peek(&mut self) -> Token

Returns the next token without consuming it.

Source

pub fn peek_whitespace(&mut self) -> Option<Token>

Returns the next token without consuming it.

This function is like peek but returns whitespace tokens which are normally skipped Does not undo tokens skipped in a previous normal peek.

Source

pub fn peek_kind(&mut self) -> TokenKind

Return the token kind of the next token without consuming it.

Source

pub fn peek_token_at(&mut self, at: u8) -> Token

Returns the next n’th token without consuming it. peek_token_at(0) is equivalent to peek.

Source

pub fn peek1(&mut self) -> Token

Source

pub fn peek2(&mut self) -> Token

Source

pub fn peek_whitespace_token_at<const AT: u8>(&mut self) -> Option<Token>

Returns the next n’th token without consuming it. This function will return None if there was any whitespace between the ’nth - 1; token and the nth token.

peek_token_at(0) is equivalent to peek.

Source

pub fn peek_whitespace1(&mut self) -> Option<Token>

Source

pub fn peek_whitespace2(&mut self) -> Option<Token>

Source

pub fn recent_span(&mut self) -> Span

Returns the span of the next token if it was already peeked, otherwise returns the token of the last consumed token.

Source

pub fn last_span(&mut self) -> Span

returns the token of the last consumed token.

Source

pub fn assert_finished(&mut self) -> ParseResult<()>

Source

pub fn eat(&mut self, token: TokenKind) -> bool

Eat the next token if it is of the given kind. Returns whether a token was eaten.

Source

pub fn eat_whitespace(&mut self, token: TokenKind) -> bool

Eat the next token if it is of the given kind. Returns whether a token was eaten.

Unlike Parser::eat this function will not consume the token if there is whitespace between the last and next token.

Source

pub fn backup_after(&mut self, span: Span)

Recover the parser state to after a given span.

Source

pub async fn parse_query(&mut self, stk: &mut Stk) -> ParseResult<Ast>

Parse a full query.

This is the primary entry point of the parser.

Source

pub async fn parse_expr(&mut self, stk: &mut Stk) -> ParseResult<Expr>

Parse a single expression.

Source

pub fn lex_compound<F, R>( &mut self, start: Token, f: F, ) -> Result<CompoundToken<R>, SyntaxError>
where F: Fn(&mut Lexer<'_>, Token) -> Result<R, SyntaxError>,

Source

pub fn span_str(&self, span: Span) -> &str

Source

pub fn unescape_ident_span(&mut self, span: Span) -> Result<&str, SyntaxError>

Source

pub fn unescape_string_span(&mut self, span: Span) -> Result<&str, SyntaxError>

Source

pub fn unescape_regex_span(&mut self, span: Span) -> Result<&str, SyntaxError>

Source

pub async fn speculate<T, F>( &mut self, stk: &mut Stk, cb: F, ) -> ParseResult<Option<T>>
where F: AsyncFnOnce(&mut Stk, &mut Parser<'_>) -> ParseResult<Option<T>>,

Speculativily parse a branch.

If the callback returns Ok(Some(_)) then the lexer state advances like it would normally. However if any other value is returned from the callback the lexer is rolled back to before the function was called.

This function can be used for cases where the right branch cannot be determined from the n’th next token.

§Usage

This function is very powerfull but also has the drawbacks.

  • First it enables ambigous grammar, when implementing new syntax using this function please first see if it is possible to implement the feature using the peek functions an otherwise maybe consider redesigning the syntax so it is LL(n).

  • Second because it doesn’t provide feedback on what exactly happened it can result in errors being unpredictable

  • Third, any parsing using speculating and then recovering is doing extra work it ideally didn’t have to do.

Please limit the usage to only syntax that can’t be efficiently parsed without backtracking and do not use it for implementing new syntax. If new syntax requires this function to implement it consider altering the syntax to remove the need for backtracking.

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<G1, G2> Within<G2> for G1
where G2: Contains<G1>,

Source§

fn is_within(&self, b: &G2) -> bool