11 breaking releases

0.13.0 Jul 20, 2024
0.12.0 Nov 11, 2023
0.11.0 Aug 21, 2023
0.9.0 Jun 10, 2023
0.2.0 Feb 14, 2021

#90 in Parser implementations

Download history 21085/week @ 2024-07-29 29332/week @ 2024-08-05 24772/week @ 2024-08-12 31011/week @ 2024-08-19 30863/week @ 2024-08-26 23750/week @ 2024-09-02 29591/week @ 2024-09-09 22547/week @ 2024-09-16 29869/week @ 2024-09-23 29794/week @ 2024-09-30 31550/week @ 2024-10-07 26086/week @ 2024-10-14 24901/week @ 2024-10-21 20229/week @ 2024-10-28 23178/week @ 2024-11-04 27447/week @ 2024-11-11

96,546 downloads per month
Used in 4 crates (3 directly)

Apache-2.0/MIT

485KB
12K SLoC

Rust 6K SLoC // 0.1% comments C 4.5K SLoC // 0.2% comments Happy 1.5K SLoC

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.

Dependencies

~1.2–1.9MB
~35K SLoC