Commit Graph

63 Commits

Author SHA1 Message Date
Pekka Enberg
1de647758f 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
Pekka Enberg
adc6cb008a Merge 'introduce match_ignore_ascii_case macro' from Lâm Hoàng Phúc
this PR converts generate code in `turso_parser`'s `build.rs` into macro
for reusability. `match_ignore_ascii_case` will generate trie-like tree
matching from normal match expression.
example:
```rust
    match_ignore_ascii_case!(match input {
        b"AB" => TokenType::TK_ABORT,
        b"AC" => TokenType::TK_ACTION,
        _ => TokenType::TK_ID,
    })
```
will generate:
```rust
    match input.get(0) {
        Some(b'A') | Some(b'a') => match input.get(1) {
            Some(b'B') | Some(b'b') => match input.get(2) {
                None => TokenType::TK_ABORT,
                _ => TokenType::TK_ID,
            },
            Some(b'C') | Some(b'c') => match input.get(2) {
                None => TokenType::TK_ACTION,
                _ => TokenType::TK_ID,
            },
            _ => TokenType::TK_ID,
        },
        _ => TokenType::TK_ID,
    }
```

Closes #2865
2025-09-02 18:34:55 +03:00
TcMits
d0cb3d0d08 CURRENT_TIMESTAMP can fallback TK_ID 2025-09-02 20:50:58 +07:00
TcMits
06e14c8ace merge main 2025-09-02 18:17:37 +07:00
TcMits
d298480e4a Merge branch 'main' into perf-3 2025-09-02 18:13:58 +07:00
TcMits
33a04fbaf7 resolve conflict 2025-09-02 17:30:10 +07:00
Pekka Enberg
cfaba4ab10 Merge 'Implement libSQL's ALTER COLUMN extension' from Levy A.
Implement `ALTER COLUMN` as described here:
https://github.com/tursodatabase/libsql/blob/main/libsql-
sqlite3/doc/libsql_extensions.md#altering-columns
- [x] Add `ALTER COLUMN` to parser
- [x] Implement `Insn::AlterColumn`
- [x] Add tests

Closes #2814
2025-09-02 09:06:03 +03:00
PThorpe92
b76f9b7733 Use eq_ignore_ascii_case in place of allocating new string in parser 2025-09-01 12:32:33 -04:00
PThorpe92
4bb2497d36 Parser: translate true and false to 0 and 1 literals 2025-09-01 11:24:12 -04:00
TcMits
190e9bcc95 add match_ignore_ascii_case macro 2025-08-31 14:35:03 +07:00
Levy A.
5b378e3730 feat: add AlterColumn instruction
also refactor `RenameColumn` to reuse the logic from `AlterColumn`
2025-08-30 03:10:39 -03:00
Levy A.
678ca8d33b feat(parser): add ALTER COLUMN 2025-08-30 03:10:39 -03:00
TcMits
bfff90b70e unrelated changes 2025-08-27 15:02:58 +07:00
TcMits
4ddfdb2a62 finish 2025-08-27 14:58:35 +07:00
Pekka Enberg
26ba09c45f Revert "Merge 'Remove double indirection in the Parser' from Pedro Muniz"
This reverts commit 71c1b357e4, reversing
changes made to 6bc568ff69 because it
actually makes things slower.
2025-08-26 14:58:21 +03:00
pedrocarlo
5108c72a28 remove box from Vec<Box<Expr>> 2025-08-25 19:47:46 -03:00
TcMits
22b6bad2c0 Merge branch 'main' into clean-parser-4 2025-08-24 13:15:05 +07:00
TcMits
399f10fe9a refactor parser fmt 2025-08-23 19:16:26 +07:00
TcMits
fd63688ede reduce cloning Token in parser 2025-08-23 15:07:32 +07:00
Pekka Enberg
52ef4c2dfe Merge 'correctly implement offset() in parser' from Lâm Hoàng Phúc
Closes #2731
2025-08-22 15:40:18 +03:00
TcMits
81603f6706 correctly implement offset() in parser 2025-08-22 17:47:39 +07:00
TcMits
4b07555e87 remove dup test 2025-08-22 17:02:10 +07:00
TcMits
f49c47f248 remove dup check 2025-08-22 16:47:41 +07:00
TcMits
df8ab9c104 clippy again 2025-08-22 16:39:59 +07:00
TcMits
a1bc3bf988 clippy 2025-08-22 16:36:10 +07:00
TcMits
14eb8a8ffe move check code into parser 2025-08-22 16:28:56 +07:00
Levy A.
34724a0571 fix: proper parser offset tracking 2025-08-22 02:11:53 -03:00
Levy A.
8a610a776f refactor: Result type alias 2025-08-21 15:24:01 -03:00
Levy A.
07975603d3 fix: incorrect sql statement in parser test 2025-08-21 15:24:01 -03:00
Levy A.
a86a066a91 fix order by function clause 2025-08-21 15:24:01 -03:00
Levy A.
c6b032de63 feat: add AST formating and checking 2025-08-21 15:19:17 -03:00
Levy A.
b0537d02c7 fix: SQLite operators are left associative 2025-08-21 15:19:16 -03:00
Levy A.
dd39f47cda feat: add materialized view + implement essential methods for core 2025-08-21 15:19:16 -03:00
TcMits
4d91f19ab2 rebase 2025-08-15 17:05:28 +07:00
TcMits
fb5203ce45 make eat_assert faster 2025-08-15 16:45:20 +07:00
TcMits
22f53d1fe6 clippy again 2025-08-15 16:45:18 +07:00
TcMits
1cafdc1f8e fmt 2025-08-15 16:45:18 +07:00
TcMits
f0bd4cca69 clippy 2025-08-15 16:45:18 +07:00
TcMits
bbd96d263c finish REINDEX 2025-08-15 16:45:08 +07:00
TcMits
49a0a3417a finish UPDATE 2025-08-13 15:11:32 +07:00
TcMits
b8ad44bf07 finish INSERT 2025-08-13 14:45:34 +07:00
TcMits
161c87212e finish all DROP 2025-08-13 14:07:28 +07:00
TcMits
179cce2ceb finish DELETE 2025-08-13 13:56:58 +07:00
TcMits
c444b80d2e finish CREATE VIRTUAL TABLE 2025-08-12 19:14:10 +07:00
TcMits
ba87698448 finish CREATE VIEW 2025-08-12 17:46:43 +07:00
TcMits
3622370d27 finish CREATE TRIGGER 2025-08-12 17:25:29 +07:00
TcMits
1b925e4f92 finish CREATE TRIGGER without tests 2025-08-12 14:22:42 +07:00
TcMits
4849db3335 finish CREATE TABLE 2025-08-11 16:17:26 +07:00
TcMits
df514ec75a finish CREATE INDEX 2025-08-11 13:27:32 +07:00
TcMits
3c39ff1f9c finish ALTER 2025-08-10 19:24:18 +07:00