Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] Add a tokenizer as intermediate step #178

Closed
torkleyy opened this issue Jun 7, 2019 · 5 comments
Closed

[RFC] Add a tokenizer as intermediate step #178

torkleyy opened this issue Jun 7, 2019 · 5 comments
Labels
feature A new feature for the syntax or library. stale

Comments

@torkleyy
Copy link
Contributor

torkleyy commented Jun 7, 2019

Description

Add a tokenizer which emits Tokens given a byte sequence.

Those tokens will then be feed into the deserializer.

Motivation

This allows to simplify the logic in the deserializer, makes testing easier and is more likely to avoid bugs.

Additionally, we could refactor the Serializer to emit tokens, too (at a second step). If we do that, we might be able to address #175 by formatting the tokens; the pretty config would be mostly irrelevant for the serialization.

Aaand in a third step, we could even utilize this architecture to implement a formatter, simply by tokenizing an input file and pretty-formatting the tokens.

@torkleyy torkleyy added the feature A new feature for the syntax or library. label Jun 7, 2019
@cynecx
Copy link

cynecx commented Sep 6, 2019

Instead of implementing a new lexer, isn't it possible to actually use rust's lexer? (https://crates.io/crates/).

@CAD97
Copy link
Contributor

CAD97 commented Oct 7, 2019

Specifically, rustc's lexer is now available as rustc_lexer at https://crates.io/crates/rustc_lexer and while it explicitly has no API guarantee other than adhering to semver, it is highly desired to have the crate compile on stable (with no intention of breaking that status). Since RON explicitly wants to "look like Rust", using the standard Rust lexer makes sense.

The other option is to use proc_macro2 (and maybe syn?) to parse in all cases, which gives the ron! macro for "free" (as a proc-macro).

@CAD97
Copy link
Contributor

CAD97 commented Oct 7, 2019

I have way too much experience writing syn-based parsers.

Here's a parser for the RON syntax using syn/proc_macro2: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=18dc90ed4b5244507cb6660fd2f39de7

Feel free to use it. Also, double check me, I could've missed something.

(EDIT: Added ToTokens implementations)

@github-actions
Copy link

Issue has had no activity in the last 180 days and is going to be closed in 7 days if no further activity occurs

@github-actions github-actions bot added the stale label Nov 18, 2021
@kvark kvark reopened this Dec 3, 2021
@kvark kvark reopened this Dec 17, 2021
@torkleyy
Copy link
Contributor Author

I think we can leave this closed, it seems outside the scope of this repository and I've started something like this in ron-rs/ron-reboot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature A new feature for the syntax or library. stale
Projects
None yet
Development

No branches or pull requests

4 participants