risingwave_sqlparser::tokenizer

Struct Tokenizer

source
pub struct Tokenizer<'a> {
    sql: &'a str,
    chars: Peekable<Chars<'a>>,
    line: u64,
    col: u64,
}
Expand description

SQL Tokenizer

Fields§

§sql: &'a str§chars: Peekable<Chars<'a>>§line: u64§col: u64

Implementations§

source§

impl<'a> Tokenizer<'a>

source

pub fn new(query: &'a str) -> Self

Create a new SQL tokenizer for the specified SQL statement

source

fn next(&mut self) -> Option<char>

Consume the next character.

source

fn peek(&mut self) -> Option<char>

Return the next character without consuming it.

source

pub fn tokenize_with_location( &mut self, ) -> Result<Vec<TokenWithLocation>, TokenizerError>

Tokenize the statement and produce a vector of tokens with locations.

Whitespaces are skipped.

source

fn tokenize_with_whitespace(&mut self) -> Result<Vec<Token>, TokenizerError>

Tokenize the statement and produce a vector of tokens.

Whitespaces are included.

source

fn tokenize(&mut self) -> Result<Vec<TokenWithLocation>, TokenizerError>

Tokenize the statement and produce a vector of tokens.

Whitespaces are included.

source

fn next_token_with_location( &mut self, ) -> Result<Option<TokenWithLocation>, TokenizerError>

Get the next token or return None

source

fn next_token(&mut self) -> Result<Option<Token>, TokenizerError>

Get the next token or return None

source

fn tokenize_dollar_preceded_value(&mut self) -> Result<Token, TokenizerError>

Tokenize dollar preceded value (i.e: a string/placeholder)

source

fn error<R>(&self, message: impl Into<String>) -> Result<R, TokenizerError>

source

fn reject_number_junk(&mut self) -> Result<(), TokenizerError>

source

fn tokenize_single_line_comment(&mut self) -> String

source

fn tokenize_word(&mut self, first_char: char) -> String

Tokenize an identifier or keyword, after the first char is already consumed.

source

fn tokenize_single_quoted_string(&mut self) -> Result<String, TokenizerError>

Read a single quoted string, starting with the opening quote.

source

fn tokenize_single_quoted_string_with_escape( &mut self, ) -> Result<CstyleEscapedString, TokenizerError>

Read a single qutoed string with escape

source

fn unescape_c_style(s: &str) -> Result<String, String>

Helper function used to convert string with c-style escapes into a normal string e.g. ‘hello\x3fworld’ -> ‘hello?world’

Detail of c-style escapes refer from: https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-STRINGS-UESCAPE:~:text=4.1.2.2.%C2%A0String%20Constants%20With%20C%2DStyle%20Escapes

source

fn tokenize_multiline_comment( &mut self, ) -> Result<Option<Token>, TokenizerError>

source

fn consume_and_return( &mut self, t: Token, ) -> Result<Option<Token>, TokenizerError>

source

fn peeking_take_while(&mut self, predicate: impl FnMut(char) -> bool) -> String

Read from self until predicate returns false or EOF is hit. Return the characters read as String, and keep the first non-matching char available as self.next().

Auto Trait Implementations§

§

impl<'a> Freeze for Tokenizer<'a>

§

impl<'a> RefUnwindSafe for Tokenizer<'a>

§

impl<'a> Send for Tokenizer<'a>

§

impl<'a> Sync for Tokenizer<'a>

§

impl<'a> Unpin for Tokenizer<'a>

§

impl<'a> UnwindSafe for Tokenizer<'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.

§

impl<T> Instrument for T

§

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

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

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, 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.
§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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