-
Notifications
You must be signed in to change notification settings - Fork 15
Support for runtime metaprogramming #121
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
base: jane
Are you sure you want to change the base?
Conversation
204aad5
to
535f727
Compare
535f727
to
3acbc08
Compare
|
||
let double = | ||
<[let x = <[42]> in | ||
<[123 + $x]>]> |
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.
I think we need more thorough tests of the kinds of things that usually trip ocamlformat up:
- quotes/spices of very long identifiers, splices split over multiple lines
- Every way a comment can interact with a piece of metaprogramming syntax
- Every way an attribute can interact with a piece of metaprogramming syntax
It may be instructive to look at @dvulakh's recent test for block indices for the kind of thoroughness we aim for. This may seem like overkill, but in practice we generally find that such tests catch bugs.
and syntax_directive = | ||
{ | ||
psyn_mode: string loc; | ||
psyn_toggle: bool; |
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.
It's not obvious to me what psyn_mode
and psyn_toggle
represent - maybe a comment?
vendor/parser-standard/parsetree.mli
Outdated
{ | ||
plex_desc: lexer_directive_desc; | ||
plex_loc: Location.t | ||
} |
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.
It's not immediately obvious to me that we need to add these bits to parser-standard
, since I think it is not used for printing. But maybe I'm failing to consider some aspect of the round trip tests?
Adds support for formatting runtime quotations and splices to ocamlformat.
The appropriate changes are added to the lexing, parsing, and formatting.
At the level of individual files, runtime metaprogramming can be enabled or disabled using a syntax directive:
#syntax quotations [on|off]
. This requires that we add such directives as a construct that does not lead to an error in the lexer; in fact, it has to get propagated through the parser and the formatter. These lexer directives are represented using the newlexer_directive
type.