apache / apache/datafusion-sqlparser-rs

Expose a method for mutating Parser::index

オープン
#1,593 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
Rust
スター
3.5k
フォーク
772
平均マージ
4日 9時間
マージ済み PR(30日)
17

説明

We have designed an SQL parser using sqlparser's `Parser`, and we wish to implement two helper methods for consuming tokens—similar to `Parser::consume_token` and `Parser::consume_tokens`—but with the ability to accept string inputs and perform case-insensitive matching.

However, since the Parser does not provide a method to mutate the `Parser::index`, we are unable to correctly implement our own `consume_tokens` because we need to revert the parser state if consumption fails mid-way.

We propose adding and exposing a new method in sqlparser's `Parser`, such as `set_index` or `index_mut`, to allow users to mutate the index.

The expected implementation of our `consume_token` and `consume_tokens`:

``` rust
/// Consumes the next token if it matches the expected token, otherwise return false.
///
/// Note, the matching is not case sensitive.
fn consume_token(&mut self, expected: &str) -> bool {
if self.parser.peek_token().to_string().to_uppercase() == *expected.to_uppercase() {
self.parser.next_token();
true
} else {
false
}
}

/// If the current and subsequent tokens exactly match the `tokens` sequence, consume them and returns true.
/// Otherwise, no tokens are consumed and returns false
///
/// Note, the matching is not case sensitive.
fn consume_tokens(&mut self, tokens: &[&str]) -> bool {
let index = self.parser.index();
for token in tokens {
if !self.consume_token(*token) {
// Or: `*self.parser.index_mut() = index;`
self.parser.set_index(index);
return false;
}
}
true
}

```

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

調査の方向性

まず Rust Parser の実装と、既存の index、consume_token、consume_tokens メソッドを見つけます。次に、トークンの消費に関する parser のテストを確認し、複数トークンの消費に失敗した場合に以前の位置へ戻せるよう、index を変更または設定する方法を公開します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
rust
領域
databases
issue の種類
機能追加
難易度
2/5
見積もり時間
1〜3時間
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
45/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。