limbo/vendored/sqlite3-parser
Jussi Saurio 77ce4780d9 Fix ProgramBuilder::cursor_ref not having unique keys
Currently we have this:

program.alloc_cursor_id(Option<String>, CursorType)`

where the String is the table's name or alias ('users' or 'u' in
the query).

This is problematic because this can happen:

`SELECT * FROM t WHERE EXISTS (SELECT * FROM t)`

There are two cursors, both with identifier 't'. This causes a bug
where the program will use the same cursor for both the main query
and the subquery, since they are keyed by 't'.

Instead introduce `CursorKey`, which is a combination of:

1. `TableInternalId`, and
2. index name (Option<String> -- in case of index cursors.

This should provide key uniqueness for cursors:

`SELECT * FROM t WHERE EXISTS (SELECT * FROM t)`

here the first 't' will have a different `TableInternalId` than the
second `t`, so there is no clash.
2025-05-29 00:59:24 +03:00
..
.github vendor sqlite3-parser (lemon-rs) 2024-11-16 20:08:59 +02:00
benches Switch to workspace dependencies 2025-02-12 17:28:04 +02:00
examples Switch to workspace dependencies 2025-02-12 17:28:04 +02:00
sqlparser_bench Activate Bench for comparison 2025-04-11 13:40:56 -03:00
src Fix ProgramBuilder::cursor_ref not having unique keys 2025-05-29 00:59:24 +03:00
third_party/lemon chore: enable all features in clippy ci and fix more clippy lints 2025-01-15 23:23:12 +01:00
.gitignore vendor sqlite3-parser (lemon-rs) 2024-11-16 20:08:59 +02:00
build.rs vendor sqlite3-parser (lemon-rs) 2024-11-16 20:08:59 +02:00
Cargo.toml Create CollationSeq enum and functions. Move strum to workspace dependency to avoid version mismatch with Parser 2025-05-19 15:22:14 -03:00
checks.md vendor sqlite3-parser (lemon-rs) 2024-11-16 20:08:59 +02:00
CMakeLists.txt vendor sqlite3-parser (lemon-rs) 2024-11-16 20:08:59 +02:00
LICENSE vendor sqlite3-parser (lemon-rs) 2024-11-16 20:08:59 +02:00
README.md vendor sqlite3-parser (lemon-rs) 2024-11-16 20:08:59 +02:00
Sync.md vendor sqlite3-parser (lemon-rs) 2024-11-16 20:08:59 +02:00

Build Status Latest Version Docs dependency status

LEMON parser generator modified to generate Rust code.

Lemon source and SQLite3 grammar were last synced as of July 2024.

Unsupported

Unsupported Grammar syntax

  • %token_destructor: Code to execute to destroy token data
  • %default_destructor: Code for the default non-terminal destructor
  • %destructor: Code which executes whenever this symbol is popped from the stack during error processing

https://www.codeproject.com/Articles/1056460/Generating-a-High-Speed-Parser-Part-Lemon https://www.sqlite.org/lemon.html

SQLite

SQLite lexer and SQLite parser have been ported from C to Rust. The parser generates an AST.

Lexer/Parser:

  • Keep track of position (line, column).
  • Streamable (stop at the end of statement).
  • Resumable (restart after the end of statement).

Lexer and parser have been tested with the following scripts:

TODO:

Unsupported by Rust

  • #line directive

API change

  • No ParseAlloc/ParseFree anymore

Features not tested

  • NDEBUG
  • YYNOERRORRECOVERY
  • YYERRORSYMBOL

To be fixed

  • RHS are moved. Maybe it is not a problem if they are always used once. Just add a check in lemon...
  • %extra_argument is not supported.
  • Terminal symbols generated by lemon should be dumped in a specified file.

Raison d'être

  • lemon_rust does the same thing but with an old version of lemon. And it seems not possible to use yystack as a stack because items may be access randomly and the top+1 item can be used.

  • lalrpop would be the perfect alternative but it does not support fallback/streaming (see this issue) and compilation/generation is slow.

Minimum supported Rust version (MSRV)

Latest stable Rust version at the time of release. It might compile with older versions.