Files
turso/vendored/sqlite3-parser
Pekka Enberg 7ca84ee5b0 Merge 'parser: use YYSTACKDEPTH' from Lâm Hoàng Phúc
sqlite uses [fixed-size](https://github.com/sqlite/sqlite/blob/7fc6e6a27
26e650d3b82c6d3683bdbdc10e02467/tool/lempar.c#L238) array for `yystack`
and grow stack if needed. Let replace `vec` with `smallvec` in rust
version.
after:
```sh
sqlparser-rs parsing benchmark/sqlparser::select
                        time:   [564.19 ns 565.63 ns 567.18 ns]
                        change: [-11.514% -11.288% -11.067%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 4 outliers among 100 measurements (4.00%)
  1 (1.00%) low mild
  3 (3.00%) high mild
sqlparser-rs parsing benchmark/sqlparser::with_select
                        time:   [1.9812 µs 1.9861 µs 1.9914 µs]
                        change: [-7.5226% -7.3080% -7.0858%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 5 outliers among 100 measurements (5.00%)
  1 (1.00%) low mild
  4 (4.00%) high mild

```

Reviewed-by: Jussi Saurio <jussi.saurio@gmail.com>

Closes #1999
2025-07-08 16:20:51 +03:00
..
2024-11-16 20:08:59 +02:00
2024-11-16 20:08:59 +02:00
2025-07-05 14:55:18 +07:00
2025-07-08 14:58:33 +07:00
2024-11-16 20:08:59 +02:00
2024-11-16 20:08:59 +02:00
2024-11-16 20:08:59 +02:00
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.