Replies: 4 comments 5 replies
-
What are you mean? |
Beta Was this translation helpful? Give feedback.
1 reply
-
@quimt |
Beta Was this translation helpful? Give feedback.
0 replies
-
@quimt, what about add alias for
|
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
There is a musing by Araq that tends to stick with me:
There is of course a broader idea of how we would like the DSL to compose with builtin Nim constructs. Nim supports metaprogramming, so it would be great if we could do that with the standard component declaration syntax in happyX.
So lets run down what we might want and what is supported. As we will see, some of this could be handled by the framework, and some of this might have more general utility in a variety of other projects.
Generics
Generics are the most common strategy for avoiding code duplication, so it would be awesome to be able to write something like this:
Templates
Doesn't currently work, but not of huge interest.
Macros
Much more flexible, but AST macros can be extra annoying to write since they require introspection on the syntax of the DSL, which is not standard Nim.
quote do
: andgenAst()
both currently fail for basically the same reason:This fails, even in this example where the macro has no parameters. This appears to be because
quote do
is a quasiquoting operator and genAst() is a drop in replacement, all that we have for macro generation are quasiquotes that try to generate the AST in advance using the immediate context of the declaration.Full quotes that are evaluated later inside the context of the DSL don't seem to be readily available in Nim, however one can implement a more sophisticated macro with parameters using
macros.toStrLit()
andmacros.parseExpr()
It works, but just barely, and not very flexibly. It would start to work nicer if any code block could be literally quoted before it gets parsed, using a string to represent the code seems to be the only way currently, and results in an uglier experience, for instance with syntax highlighting. Perhaps a full, pre-parsed quote of a code block would be useful to other macros that manipulate DSL code, and would be something to request of nim-lang itself?
Beta Was this translation helpful? Give feedback.
All reactions