jyn514 / saltwater

A C compiler written in Rust, with a focus on good error messages.
BSD 3-Clause "New" or "Revised" License
290 stars 27 forks source link

Separate parsing into a library #266

Open jyn514 opened 4 years ago

jyn514 commented 4 years ago

Suggested by @pythondude325. Related to #151.

It would be really cool to have a separate library which serializes and deserializes C source code. Most of the serialization is already done in src/data in various impl Displays. The hard part will be factoring apart the lexer/parser from the rest of the compiler. The syntax part of this is already hard as noted in #151, but separating the preprocessor would also be somewhat difficult: I'd have to duplicate a fair bit of code (lexing tokens mostly) and have a way to pass locations around.

Related facts:

My proposed plan is this:

Open questions:

jyn514 commented 4 years ago

If #356 is implemented, the preprocessor could instead run between the lexer and the parser. This would clean up the current somewhat hacky way the preprocessor consumes the lexer's characters for it. It would also allow people to opt-in/out of the preprocessor.