pub struct Parser<'a> {
pub table_as_field: bool,
/* private fields */
}Expand description
The SurrealQL parser.
Fields§
§table_as_field: boolImplementations§
Source§impl Parser<'_>
impl Parser<'_>
Sourcepub fn next_token_value<V: TokenValue>(&mut self) -> ParseResult<V>
pub fn next_token_value<V: TokenValue>(&mut self) -> ParseResult<V>
Parse a token value from the next token in the parser.
pub fn parse_string_lit(&mut self) -> ParseResult<String>
pub fn parse_ident(&mut self) -> ParseResult<String>
pub fn parse_ident_str(&mut self) -> ParseResult<&str>
pub fn parse_flexible_ident(&mut self) -> ParseResult<String>
Source§impl Parser<'_>
impl Parser<'_>
Sourcepub async fn parse_expr_start(&mut self, stk: &mut Stk) -> ParseResult<Expr>
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.
Sourcepub async fn parse_expr_table(&mut self, stk: &mut Stk) -> ParseResult<Expr>
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
Sourcepub async fn parse_expr_field(&mut self, stk: &mut Stk) -> ParseResult<Expr>
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
pub fn reject_letless_let(expr: &Expr, span: Span) -> ParseResult<()>
Source§impl Parser<'_>
impl Parser<'_>
pub async fn parse_function_name(&mut self) -> ParseResult<Function>
pub fn parse_version_digits(&mut self) -> ParseResult<u32>
Source§impl Parser<'_>
impl Parser<'_>
Sourcepub async fn parse_fields(&mut self, stk: &mut Stk) -> ParseResult<Fields>
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.
Sourcepub async fn parse_plain_idiom(&mut self, stk: &mut Stk) -> ParseResult<Idiom>
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<'_>
impl Parser<'_>
Sourcepub async fn parse_kind(
&mut self,
stk: &mut Stk,
delim: Span,
) -> ParseResult<Kind>
pub async fn parse_kind( &mut self, stk: &mut Stk, delim: Span, ) -> ParseResult<Kind>
Sourcepub async fn parse_inner_kind(&mut self, stk: &mut Stk) -> ParseResult<Kind>
pub async fn parse_inner_kind(&mut self, stk: &mut Stk) -> ParseResult<Kind>
Parse an inner kind, a kind without enclosing < >.
Source§impl Parser<'_>
impl Parser<'_>
pub async fn parse_set( &mut self, stk: &mut Stk, start: Span, ) -> ParseResult<Vec<Expr>>
Sourcepub async fn parse_block(
&mut self,
stk: &mut Stk,
start: Span,
) -> ParseResult<Block>
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<'_>
impl Parser<'_>
Sourcepub async fn parse_array(
&mut self,
stk: &mut Stk,
start: Span,
) -> ParseResult<Vec<Expr>>
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<'_>
impl Parser<'_>
pub async fn parse_record_id_or_range( &mut self, stk: &mut Stk, ident: String, ) -> ParseResult<RecordIdLit>
pub async fn parse_id_range( &mut self, stk: &mut Stk, ) -> ParseResult<RecordIdKeyRangeLit>
pub async fn parse_lookup_subject( &mut self, stk: &mut Stk, supports_referencing_field: bool, ) -> ParseResult<LookupSubject>
pub async fn parse_referencing_field( &mut self, supports_referencing_field: bool, ) -> ParseResult<Option<String>>
pub async fn parse_record_id( &mut self, stk: &mut Stk, ) -> ParseResult<RecordIdLit>
pub async fn parse_record_id_from_ident( &mut self, stk: &mut Stk, ident: String, ) -> ParseResult<RecordIdLit>
pub async fn parse_record_id_key( &mut self, stk: &mut Stk, ) -> ParseResult<RecordIdKeyLit>
Source§impl Parser<'_>
impl Parser<'_>
pub async fn parse_alter_stmt( &mut self, stk: &mut Stk, ) -> ParseResult<AlterStatement>
pub async fn parse_alter_system( &mut self, stk: &mut Stk, ) -> ParseResult<AlterSystemStatement>
pub async fn parse_alter_namespace( &mut self, ) -> ParseResult<AlterNamespaceStatement>
pub async fn parse_alter_database( &mut self, ) -> ParseResult<AlterDatabaseStatement>
pub async fn parse_alter_table( &mut self, stk: &mut Stk, ) -> ParseResult<AlterTableStatement>
pub async fn parse_alter_index(&mut self) -> ParseResult<AlterIndexStatement>
pub async fn parse_alter_field( &mut self, stk: &mut Stk, ) -> ParseResult<AlterFieldStatement>
pub async fn parse_alter_sequence( &mut self, stk: &mut Stk, ) -> ParseResult<AlterSequenceStatement>
Source§impl Parser<'_>
impl Parser<'_>
pub async fn parse_create_stmt( &mut self, stk: &mut Stk, ) -> ParseResult<CreateStatement>
Source§impl Parser<'_>
impl Parser<'_>
pub async fn parse_define_stmt( &mut self, stk: &mut Stk, ) -> ParseResult<DefineStatement>
pub async fn parse_define_namespace( &mut self, stk: &mut Stk, ) -> ParseResult<DefineNamespaceStatement>
pub async fn parse_define_database( &mut self, stk: &mut Stk, ) -> ParseResult<DefineDatabaseStatement>
pub async fn parse_define_function( &mut self, stk: &mut Stk, ) -> ParseResult<DefineFunctionStatement>
pub async fn parse_define_module( &mut self, _stk: &mut Stk, ) -> ParseResult<DefineModuleStatement>
pub async fn parse_define_user( &mut self, stk: &mut Stk, ) -> ParseResult<DefineUserStatement>
pub async fn parse_define_access( &mut self, stk: &mut Stk, ) -> ParseResult<DefineAccessStatement>
pub async fn parse_define_param( &mut self, stk: &mut Stk, ) -> ParseResult<DefineParamStatement>
pub async fn parse_define_table( &mut self, stk: &mut Stk, ) -> ParseResult<DefineTableStatement>
pub async fn parse_define_api( &mut self, stk: &mut Stk, ) -> ParseResult<DefineApiStatement>
pub async fn parse_define_event( &mut self, stk: &mut Stk, ) -> ParseResult<DefineEventStatement>
pub async fn parse_define_field( &mut self, stk: &mut Stk, ) -> ParseResult<DefineFieldStatement>
pub async fn parse_define_index( &mut self, stk: &mut Stk, ) -> ParseResult<DefineIndexStatement>
pub async fn parse_define_analyzer( &mut self, stk: &mut Stk, ) -> ParseResult<DefineAnalyzerStatement>
pub async fn parse_define_bucket( &mut self, stk: &mut Stk, token: Token, ) -> ParseResult<DefineBucketStatement>
pub async fn parse_define_sequence( &mut self, stk: &mut Stk, ) -> ParseResult<DefineSequenceStatement>
pub async fn parse_define_config( &mut self, stk: &mut Stk, ) -> ParseResult<DefineConfigStatement>
pub async fn parse_default_config( &mut self, stk: &mut Stk, ) -> ParseResult<DefaultConfig>
pub async fn parse_api_config( &mut self, stk: &mut Stk, ) -> ParseResult<ApiConfig>
pub fn parse_relation_schema(&mut self) -> ParseResult<Relation>
pub fn parse_tables(&mut self) -> ParseResult<Vec<String>>
Source§impl Parser<'_>
impl Parser<'_>
pub async fn parse_delete_stmt( &mut self, stk: &mut Stk, ) -> ParseResult<DeleteStatement>
Source§impl Parser<'_>
impl Parser<'_>
pub async fn parse_if_stmt( &mut self, stk: &mut Stk, ) -> ParseResult<IfelseStatement>
Source§impl Parser<'_>
impl Parser<'_>
pub async fn parse_insert_stmt( &mut self, stk: &mut Stk, ) -> ParseResult<InsertStatement>
Source§impl Parser<'_>
impl Parser<'_>
Sourcepub async fn try_parse_data(
&mut self,
stk: &mut Stk,
) -> ParseResult<Option<Data>>
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
Sourcepub async fn try_parse_output(
&mut self,
stk: &mut Stk,
) -> ParseResult<Option<Output>>
pub async fn try_parse_output( &mut self, stk: &mut Stk, ) -> ParseResult<Option<Output>>
Parses a statement output if the next token is return.
Sourcepub async fn parse_output(&mut self, stk: &mut Stk) -> ParseResult<Output>
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.
Sourcepub async fn try_parse_timeout(&mut self, stk: &mut Stk) -> ParseResult<Expr>
pub async fn try_parse_timeout(&mut self, stk: &mut Stk) -> ParseResult<Expr>
Parses a statement timeout if the next token is TIMEOUT.
pub async fn try_parse_fetch( &mut self, stk: &mut Stk, ) -> ParseResult<Option<Fetchs>>
pub async fn parse_fetchs(&mut self, stk: &mut Stk) -> ParseResult<Fetchs>
pub async fn try_parse_param_or_idiom_or_fields( &mut self, stk: &mut Stk, ) -> ParseResult<Vec<Fetch>>
pub async fn try_parse_condition( &mut self, stk: &mut Stk, ) -> ParseResult<Option<Cond>>
Sourcepub fn check_idiom(
kind: MissingKind,
fields: &Fields,
field_span: Span,
idiom: &Idiom,
idiom_span: Span,
) -> ParseResult<()>
pub fn check_idiom( kind: MissingKind, fields: &Fields, field_span: Span, idiom: &Idiom, idiom_span: Span, ) -> ParseResult<()>
Move this out of the parser.
pub fn try_parse_group( &mut self, fields: &Fields, fields_span: Span, split_span: Option<Span>, ) -> ParseResult<Option<Groups>>
Sourcepub async fn parse_permission(
&mut self,
stk: &mut Stk,
field: bool,
) -> ParseResult<Permissions>
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.
Sourcepub async fn parse_specific_permission(
&mut self,
stk: &mut Stk,
permissions: &mut Permissions,
field: bool,
) -> ParseResult<()>
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.
Sourcepub async fn parse_permission_value(
&mut self,
stk: &mut Stk,
) -> ParseResult<Permission>
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.
Sourcepub fn parse_base(&mut self) -> ParseResult<Base>
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.
Sourcepub fn parse_changefeed(&mut self) -> ParseResult<ChangeFeed>
pub fn parse_changefeed(&mut self) -> ParseResult<ChangeFeed>
Parses a changefeed production
§Parser State
Expects the parser to have already eating the CHANGEFEED keyword
Sourcepub async fn parse_reference(&mut self, stk: &mut Stk) -> ParseResult<Reference>
pub async fn parse_reference(&mut self, stk: &mut Stk) -> ParseResult<Reference>
Sourcepub async fn parse_view(&mut self, stk: &mut Stk) -> ParseResult<View>
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.
pub fn parse_distance(&mut self) -> ParseResult<Distance>
pub fn parse_vector_type(&mut self) -> ParseResult<VectorType>
pub fn parse_custom_function_name(&mut self) -> ParseResult<String>
Source§impl Parser<'_>
impl Parser<'_>
pub async fn parse_relate_stmt( &mut self, stk: &mut Stk, ) -> ParseResult<RelateStatement>
pub async fn parse_relation( &mut self, stk: &mut Stk, ) -> ParseResult<(Expr, Expr, Expr)>
pub async fn parse_relate_kind(&mut self, stk: &mut Stk) -> ParseResult<Expr>
pub async fn parse_relate_expr(&mut self, stk: &mut Stk) -> ParseResult<Expr>
pub async fn parse_thing_or_table(&mut self, stk: &mut Stk) -> ParseResult<Expr>
Source§impl Parser<'_>
impl Parser<'_>
pub async fn parse_remove_stmt( &mut self, stk: &mut Stk, ) -> ParseResult<RemoveStatement>
Source§impl Parser<'_>
impl Parser<'_>
Sourcepub async fn parse_select_stmt(
&mut self,
stk: &mut Stk,
) -> ParseResult<SelectStatement>
pub async fn parse_select_stmt( &mut self, stk: &mut Stk, ) -> ParseResult<SelectStatement>
expects select to be eaten.
pub fn try_parse_split( &mut self, fields: &Fields, fields_span: Span, ) -> ParseResult<Option<Splits>>
pub fn try_parse_orders( &mut self, fields: &Fields, fields_span: Span, ) -> ParseResult<Option<Ordering>>
pub async fn try_parse_limit( &mut self, stk: &mut Stk, ) -> ParseResult<Option<Limit>>
pub async fn try_parse_start( &mut self, stk: &mut Stk, ) -> ParseResult<Option<Start>>
Source§impl Parser<'_>
impl Parser<'_>
pub async fn parse_update_stmt( &mut self, stk: &mut Stk, ) -> ParseResult<UpdateStatement>
Source§impl Parser<'_>
impl Parser<'_>
pub async fn parse_upsert_stmt( &mut self, stk: &mut Stk, ) -> ParseResult<UpsertStatement>
Source§impl Parser<'_>
impl Parser<'_>
Sourcepub async fn parse_value(&mut self, stk: &mut Stk) -> ParseResult<PublicValue>
pub async fn parse_value(&mut self, stk: &mut Stk) -> ParseResult<PublicValue>
Parse a complete value which cannot contain non-literal expressions.
pub async fn parse_json(&mut self, stk: &mut Stk) -> ParseResult<PublicValue>
pub async fn parse_value_record_id( &mut self, stk: &mut Stk, ) -> ParseResult<PublicRecordId>
Source§impl<'a> Parser<'a>
impl<'a> Parser<'a>
Sourcepub fn new_with_experimental(source: &'a [u8], enabled: bool) -> Self
pub fn new_with_experimental(source: &'a [u8], enabled: bool) -> Self
Create a new parser from a give source.
Sourcepub fn new_with_settings(source: &'a [u8], settings: ParserSettings) -> Self
pub fn new_with_settings(source: &'a [u8], settings: ParserSettings) -> Self
Create a new parser from a give source.
pub fn with_settings(self, settings: ParserSettings) -> Self
Sourcepub fn next(&mut self) -> Token
pub fn next(&mut self) -> Token
Returns the next token and advance the parser one token forward.
Sourcepub fn next_whitespace(&mut self) -> Option<Token>
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
Sourcepub fn has_peek(&self) -> bool
pub fn has_peek(&self) -> bool
Returns if there is a token in the token buffer, meaning that a token was peeked.
Sourcepub fn pop_peek(&mut self) -> Token
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.
Sourcepub fn peek_whitespace(&mut self) -> Option<Token>
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.
Sourcepub fn peek_kind(&mut self) -> TokenKind
pub fn peek_kind(&mut self) -> TokenKind
Return the token kind of the next token without consuming it.
Sourcepub fn peek_token_at(&mut self, at: u8) -> Token
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.
pub fn peek1(&mut self) -> Token
pub fn peek2(&mut self) -> Token
Sourcepub fn peek_whitespace_token_at<const AT: u8>(&mut self) -> Option<Token>
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.
pub fn peek_whitespace1(&mut self) -> Option<Token>
pub fn peek_whitespace2(&mut self) -> Option<Token>
Sourcepub fn recent_span(&mut self) -> Span
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.
pub fn assert_finished(&mut self) -> ParseResult<()>
Sourcepub fn eat(&mut self, token: TokenKind) -> bool
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.
Sourcepub fn eat_whitespace(&mut self, token: TokenKind) -> bool
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.
Sourcepub fn backup_after(&mut self, span: Span)
pub fn backup_after(&mut self, span: Span)
Recover the parser state to after a given span.
Sourcepub async fn parse_query(&mut self, stk: &mut Stk) -> ParseResult<Ast>
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.
Sourcepub async fn parse_expr(&mut self, stk: &mut Stk) -> ParseResult<Expr>
pub async fn parse_expr(&mut self, stk: &mut Stk) -> ParseResult<Expr>
Parse a single expression.
pub fn lex_compound<F, R>( &mut self, start: Token, f: F, ) -> Result<CompoundToken<R>, SyntaxError>
pub fn span_str(&self, span: Span) -> &str
pub fn unescape_ident_span(&mut self, span: Span) -> Result<&str, SyntaxError>
pub fn unescape_string_span(&mut self, span: Span) -> Result<&str, SyntaxError>
pub fn unescape_regex_span(&mut self, span: Span) -> Result<&str, SyntaxError>
Sourcepub async fn speculate<T, F>(
&mut self,
stk: &mut Stk,
cb: F,
) -> ParseResult<Option<T>>
pub async fn speculate<T, F>( &mut self, stk: &mut Stk, cb: F, ) -> 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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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