-
Notifications
You must be signed in to change notification settings - Fork 209
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
initial readtable implementation #340
Conversation
I've got some updates coming to this, with a much clearer API and explanation which will be easier to discuss, so don't worry too much about going through this yet. |
This is a far better and cleaner implementation of readtables. I've rebased it so the diff is clean and you can see only what I've changed. @disnet and @natefaubion can you look this over and see if there are any major problems with it? I'd like to land it soon else I get distracted/involved with something else and let this bitrot. The general idea is to expose a parser API to the reader. This API is pretty minimal, and you have to take care to handle things correctly in the reader. The API includes the The reader is a simple object that has an You change the current reader by calling Right now you are only able to hook into punctuators. Racket allows you to specify whether or not you only want to be a punctuator or literally anything else. I think only allowing punctuators right now is fine.. I feel like this is a pretty good first pass, and we can tweak it or add to it if needed later. |
Additionally, I should probably write some tests, |
This is looking awesome! I'll take a deeper look later today. In addition to a few tests would it also be possible to add some basic documentation here? |
Sure! I can add docs and tests. I want to figure out one last thing first: how to easily load readtables. Right now there's a However, as Nate pointed out, eventually The JSX reader depends on a macro (takes away a lot of token mangling). Instead of forcing the user to always do One final thought: if we can't specify the language in the file itself, maybe we could have a |
Actually, in regards to the config file, if you can imperatively import macros with |
I vote that for now, we keep readtables and macros separate when it comes to loading them. For now let's just add another switch for loading a readtable. If you have a package that provides readtable extensions and macros for the user, they need to load them separately. We'll figure out how they interact better when we work on modules. Additionally, to help with the use case of using helper macros inside readers, I added a new API Now there are no macro dependencies, you just need to load the readtable. I think this is a good starting point, and we can improve this over time. I'll start writing tests/docs next, probably not for a few days though, have some other stuff to do. |
Agreed. A more friendly API/syntax can come later. |
Added some tests. The API is pretty minimal, but the tests cover the basic cases and some of the fine details. I will write some docs later this week. |
Added a bunch of docs. Feel free to look over and suggest changes. |
I think I am done here, tests and docs included. Please let me know if something looks wrong. I would love to get this merged soon! |
Wahoo! I'll take a look and merge it tonight. |
This is looking great! I'll do a release next week assuming nobody finds a showstopper over the weekend. |
Awesome, thanks for merging!! |
This is my initial implementation of readtables. It's very early and not ready to be merged yet, but I wanted to open it up as early as possible for feedback. There's definitely sloppy code in some places, which will be cleaned up. I'm mostly interested in feedback about the APIs and how we handle custom reader extensions.
I went ahead and included an example reader in the source, which will be removed before this is merged. The reader implements the JSX extension to embed HTML in JS. This has been a fantastic example of a reader and has uncovered practical needs that our APIs need to meet.
Theoretically, with this code you can expand this file:
with the command:
The "example-readtable.js" file will be looked up relative to the sweet files, not your working directory, so that should work. Just a stop gap for now. That should output:
There are 3 integration points that I'd like feedback on:
readtables.js
implements a base reader object that can be extended withCustomReader.create
. This provides higher-level methods for a reader. It will scan for tokens and automatically queue them in a buffer, and provides methods likereset
which will bail out and reset the parser to the state before the reader was invoked.EDIT: A minor point to #3 above, the React compiler not only looks for the JSX annotation at the top of the file, but also parses an argument off of it. The annotation is
/** @jsx React.DOM */
, so it only prefixes the DOM elements with that you pass. (a
is turned intoReact.DOM.a
)Racket only allows reader extensions to be invoked on expressions. I think that makes a lot of sense. In fact, for JSX I have go through more work to make sure that the
<
character is in place of an expression. The problem is that at thereadToken
stage we know nothing about the shape of the code or if we are at an expression or not. Not sure how Racket does this, but it's something to think about.I made it so that you cannot override delimiters. Reader extensions are only checked after delimiters are parsed in
readToken
. It seems like too much power to override delimiters and I don't think we should allow it; the chances for something to go wrong are high.That is my braindump of all of my work. It's probably somewhat scattered, but it feels nice to get it out there so that feedback can help shape it early on.