-
Notifications
You must be signed in to change notification settings - Fork 371
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
Custom Parser and Reader Macros #2242
Conversation
Ho nelly! It's happening! Thanks for all the work you two put into this. I agree that we don't need single-character reader macros in addition to
I think that's redundant because the syntax for defining or requiring reader macros already makes it clear that they're reader macros. When you see
Is that for implementation reasons or theoretical reasons? I don't blame you for wanting to rename |
I wonder if we can make tag macros just a syntactic sugar for a reader macro that parses one thing and then passes that thing to the underlying macro function? Reader macros are a bit unwieldy by their nature and a sugared form could continue to be useful if you don't need to take advantage of the rest of the reader's functionality.
That's valid. Let me test enabling readers at require to and see how it feels.
This is currently an implementation thing, but it think it could be done to make
Makes sense enough. Let me double check though that there isn't some other reader related stuff that uses |
Probably. One can imagine a macro-writing macro in Hyrule like
Okay. |
|
Neat. |
f6744f7
to
406c662
Compare
did i miss anything? |
That sounds like everything we've discussed. I hope to take another look at the code soon. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is shaping up super well, once again many thanks for taking this on allie!
Here are some things I came across while taking this for a test run:
-
What is the expected interface for
deftag
/defreader
? Ie for(defreader THING ...)
is THING supposed to be a (well-formed) symbol, a string, or any sequence of characters?- If we want to support the latter case (eg
(defreader : ...)
instead of(defreader ":" ...)
thendefreader
itself will likely need to be a reader macro
- If we want to support the latter case (eg
-
Along those lines, bad error message for using the wrong type for the reader name, eg
(defreader : '5)
producesTypeError: can only concatenate str (not "Keyword") to str
(similar for other types, like Integer if you try to define(defreader 4 '5)
instead of(defreader "4" '5)
) -
(defreader name [expr] ...)
looks like it's specifying args, but this actually just a list as the first body expression. This could just be a #docmebro? or alternatively we can explicitly require an empty args list (eg(defreader name [] ...)
) to make this explicit. I'm leaning towards the empty args list to make it consistent with all the otherdef...
forms. -
requiring a reader macro (
(require module :readers ["#xyz"])
) is inconsistent with defining a reader macro, in that the leading "#" is required, which feels a bit strange
aad76e2
to
54b122a
Compare
It looks there is no equivalent of the old assert can_compile(r'f"hello {"n"} world"') Are you sure this is correct? It seems counterintuitive to me, and it's not consistent with Python. I think there's a mistake in Some tests seem to have been lost, such as |
Perhaps the intention was to be consistent with
I agree. We should either always forbid the
I would recommend against requiring |
My vote is to keep this; it's a lot easier to use format strings (and feels lispier) when curly braces work like
Fair point! |
Oh right, I forgot to mention: |
54b122a
to
3b187a8
Compare
this does mean that I'll open a followup PR with moving @scauligi can you speak to the I think that's everything? |
If you're going ahead with
No reason we couldn't just call it something else, right? We should have plenty of decent options without having to give it special accommodation in the reader. Perhaps
It looks like Hyrule is already broken by this PR. Not your fault; that's what usually happens with breaking changes to Hy. My recommendation is, remove |
That was intentional; the API is different since the new reader can directly take a stream where (iirc) the old reader needed the entire input at once as a string; so there's no need to have a separate
Hmm, I am leaning slightly towards adding |
If that was intended, it doesn't seem to work:
|
Ah, looks like I mixed myself up; internally it uses a stream but the reader interface indeed still expects the whole string up front. I expect changing the function names shouldn't affect users too much, but do you want to keep the original names? |
think everything looks good. only thing i'm noticing now is that i didn't let |
I see, that's a good point. |
Actually, since this PR is already so big, and we probably have more such things we need to do, would you like to do it as a follow-up PR? |
works for me |
i'll rebase the tuple syntax pr and remove the whitespace stuff once we merge |
Very good. I shall rebase and push the merge button. |
Co-authored-by: Kodi Arfer <Kodiologist@users.noreply.github.com>
Co-authored-by: Allison Casey <allie.jo.casey@gmail.com> Co-authored-by: Kodi Arfer <Kodiologist@users.noreply.github.com>
Co-authored-by: Kodi Arfer <Kodiologist@users.noreply.github.com>
This commit also removes the ability to call `defmacro` on a string literal. Co-authored-by: Kodi Arfer <Kodiologist@users.noreply.github.com>
Co-authored-by: Kodi Arfer <Kodiologist@users.noreply.github.com>
Co-authored-by: Kodi Arfer <Kodiologist@users.noreply.github.com>
Co-authored-by: Kodi Arfer <Kodiologist@users.noreply.github.com>
Then we can use regular `import` to import the result.
Co-authored-by: Kodi Arfer <Kodiologist@users.noreply.github.com>
4382ac5
to
0e429cb
Compare
closes #722
Open question if hy should support such a permissive reader macros. This PR has it so you can define a reader for any single char or any sym prefixed by a
#
.In my opinion reader macros prefised by
#
are more idiomatic and restricting user defined macros to only ones prefixed by#
would make Hy more predictable and tooling easier down the road. I'd be in favor of that kind of restriction, but i'll leave that as an open question for discussion.There's also the behavior of reader macros on require. Right now, readers macros need to be required per module and then enabled per module. This is how Racket works and to me seems like the right thing to do for a macro that drastically change how code looks and is written. Again another question for discussion though.
@scauligi as this was your baby, do you have any thoughts?