limbo/parser
Pekka Enberg 1de647758f
Some checks failed
Build and push limbo-sim image / deploy (push) Has been cancelled
Dart/Flutter / test (blacksmith-4vcpu-ubuntu-2404) (push) Has been cancelled
Dart/Flutter / test (macos-latest) (push) Has been cancelled
Dart/Flutter / test (windows-latest) (push) Has been cancelled
Dart/Flutter / precompile (blacksmith-4vcpu-ubuntu-2404) (push) Has been cancelled
Dart/Flutter / precompile (macOS-latest) (push) Has been cancelled
Dart/Flutter / precompile (windows-latest) (push) Has been cancelled
Dart/Flutter / publish (push) Has been cancelled
Java Tests / test (push) Has been cancelled
Build & publish @tursodatabase/sync / stable - wasm32-wasip1-threads - node@20 (push) Has been cancelled
Build & publish @tursodatabase/sync / stable - aarch64-apple-darwin - node@20 (push) Has been cancelled
Build & publish @tursodatabase/sync / stable - x86_64-pc-windows-msvc - node@20 (push) Has been cancelled
Build & publish @tursodatabase/sync / stable - x86_64-unknown-linux-gnu - node@20 (push) Has been cancelled
Build & publish @tursodatabase/database / stable - wasm32-wasip1-threads - node@20 (push) Has been cancelled
Build & publish @tursodatabase/database / stable - aarch64-apple-darwin - node@20 (push) Has been cancelled
Build & publish @tursodatabase/database / stable - x86_64-pc-windows-msvc - node@20 (push) Has been cancelled
Build & publish @tursodatabase/database / stable - x86_64-unknown-linux-gnu - node@20 (push) Has been cancelled
Python / configure-strategy (push) Has been cancelled
Python / lint (push) Has been cancelled
Python / linux (x86_64) (push) Has been cancelled
Python / macos-arm64 (aarch64) (push) Has been cancelled
Python / sdist (push) Has been cancelled
Rust / cargo-fmt-check (push) Has been cancelled
Rust / build-native (blacksmith-4vcpu-ubuntu-2404) (push) Has been cancelled
Rust / build-native (macos-latest) (push) Has been cancelled
Rust / build-native (windows-latest) (push) Has been cancelled
Rust / clippy (push) Has been cancelled
Rust / simulator (push) Has been cancelled
Rust / test-limbo (push) Has been cancelled
Rust / test-sqlite (push) Has been cancelled
Rust Benchmarks+Nyrkiö / bench (push) Has been cancelled
Rust Benchmarks+Nyrkiö / tpc-h (push) Has been cancelled
Rust Benchmarks+Nyrkiö / vfs-bench-compile (push) Has been cancelled
Rust Benchmarks+Nyrkiö / clickbench (push) Has been cancelled
Rust Benchmarks+Nyrkiö / tpc-h-criterion (push) Has been cancelled
Build & publish @tursodatabase/sync / Test turso-sync-js on Linux-x64-gnu - node@20 (push) Has been cancelled
Build & publish @tursodatabase/database / Test bindings on Linux-x64-gnu - node@20 (push) Has been cancelled
Build & publish @tursodatabase/sync / Publish (push) Has been cancelled
Build & publish @tursodatabase/database / Publish (push) Has been cancelled
Python / test (push) Has been cancelled
Python / Release (push) Has been cancelled
Merge 'refactor parser fmt' from Lâm Hoàng Phúc
@penberg this PR try to clean up `turso_parser`'s`fmt` code.
- `get_table_name` and `get_column_name` should return None when
table/column does not exist.
```rust
/// Context to be used in ToSqlString
pub trait ToSqlContext {
    /// Given an id, get the table name
    /// First Option indicates whether the table exists
    ///
    /// Currently not considering aliases
    fn get_table_name(&self, _id: TableInternalId) -> Option<&str> {
        None
    }

    /// Given a table id and a column index, get the column name
    /// First Option indicates whether the column exists
    /// Second Option indicates whether the column has a name
    fn get_column_name(&self, _table_id: TableInternalId, _col_idx: usize) -> Option<Option<&str>> {
        None
    }

    // help function to handle missing table/column names
    fn get_table_and_column_names(
        &self,
        table_id: TableInternalId,
        col_idx: usize,
    ) -> (String, String) {
        let table_name = self
            .get_table_name(table_id)
            .map(|s| s.to_owned())
            .unwrap_or_else(|| format!("t{}", table_id.0));

        let column_name = self
            .get_column_name(table_id, col_idx)
            .map(|opt| {
                opt.map(|s| s.to_owned())
                    .unwrap_or_else(|| format!("c{col_idx}"))
            })
            .unwrap_or_else(|| format!("c{col_idx}"));

        (table_name, column_name)
    }
}
```
- remove `FmtTokenStream` because it is same as `WriteTokenStream `
- remove useless functions and simplify `ToTokens`
```rust
/// Generate token(s) from AST node
/// Also implements Display to make sure devs won't forget Display
pub trait ToTokens: Display {
    /// Send token(s) to the specified stream with context
    fn to_tokens<S: TokenStream + ?Sized, C: ToSqlContext>(
        &self,
        s: &mut S,
        context: &C,
    ) -> Result<(), S::Error>;

    // Return displayer representation with context
    fn displayer<'a, 'b, C: ToSqlContext>(&'b self, ctx: &'a C) -> SqlDisplayer<'a, 'b, C, Self>
    where
        Self: Sized,
    {
        SqlDisplayer::new(ctx, self)
    }
}
```

Closes #2748
2025-09-02 18:35:43 +03:00
..
benches remove turso_sqlite3_parser from turso_parser 2025-09-02 18:10:28 +07:00
src Merge 'refactor parser fmt' from Lâm Hoàng Phúc 2025-09-02 18:35:43 +03:00
Cargo.toml resolve conflict 2025-09-02 18:46:41 +07:00
README.md test exprs 2025-08-07 15:40:36 +07:00

TODO