Comments (5)
I think I will start this as a completely separate library - if it works out, we can see if it makes sense.
from quick-error.
Yes. That's my observation too. But I don't have a time to do it myself. So yes, please start it as a separate library. It's good idea besides the error handling.
from quick-error.
Ok, I already started this. Now I am stuck at the generalized problem of FIND_IMPL (instead of FIND_DESCRIPTION_IMPL, etc.). So in a simplified version, I want to do a search via macros
macro_rules! enum_transform{
(FIND $needle:ident
{$pop:ident $( $hay:ident )*}
) => {
// PSEUDO-CODE >>
if($pop == $needle) {
true
} else {
enum_transform!{FIND $needle {$( $hay )*}
}
// << PSEUDO-CODE
}
(FIND $needle:ident {}
) => {
false
}
}
assert_eq!(enum_transform!(FIND bar {foo bar baz}), true);
This can partly be reduced to this problem:
assert!(equal!(foo foo));
assert!(!equal!(foo bar));
Which rust macro is capable to do this check on the AST-level?
Of course I can do something like
macro_rules! equal{
($a:ident $b:ident)
=> { stringify!($a) == stringify!($b) }
}
Rust should be able to reduce this to true booleans at compile time - but strictly after the macros have completed. I believe this would not solve all problems, because the compiler would probably complain about invalid expressions, even if they are unreachable like this
if equal!(foo bar) {
// .. invalid expressions - rust would still complain, although they are unreachable
}
Even if it worked, I would not like this workaround very much.
Hm. This could be a show stopper. What do you think?
I was more or less confident until I realised this problem.
from quick-error.
Hm. I should try if macros can dynamically define new local macros and call them. I dont know if Rust allows that, if so, it would be very powerful.
from quick-error.
Ok, after playing around with this:
This works in general - which is astonishing, given the limitations of macro_rules. But there are two very big drawbacks doing this whole thing with macro_rules!
- The recursion depth of my prototype scales linear with the number of tokens O(enum) + O(impl). Due to some macro limitations, I would even need to make two passes over the implementations (first to replace the match-statements with higher-order-macros, this must be done in a macro-buffer before the implementations are written out, then another pass to replace
self
withself
due to macro hygiene, this must be done after the impl-definition has started and the newself
is in scope). Currently I try it in one pass, where only one of these succeeds and the other one fails (which one depends on whether I do this pass 'early' or 'late'). I am confident, that both work, if I split it into two passes. But two passes means at least2 * len(impl)
recursions. Even the most trivial cases would then be around the default recursion limit of 64. It is possible and very easy to increase this limit, but it does not seem like a very good idea. Even with one pass it would be problematic. - Last but not least, it is not possible to use macros inside macro-invocations (at least not with some additional trickery).
Takeaway: I think this should better be done with a procedural macro - but there is currently no way to write procedural rust macros for the stable toolchain. So I think this must wait until the macro reform.
Btw - This is how far I got: https://github.com/colin-kiegel/enum-transform/blob/master/src/macros.rs. I think this is a dead end for above reasons - but at least I learned a lot about rust macro_rules!. :-)
from quick-error.
Related Issues (20)
- error processing large numbers of items HOT 5
- error: recursion limit reached while expanding the macro `quick_error` HOT 2
- Support for structs HOT 11
- pretty-printing with `cause` traversal HOT 4
- Allow documentation of enum variant HOT 2
- Add tests/ HOT 2
- no_std support
- error-chain
- Suggest adding crate version label and building status label to README
- Allow documentation on fields. HOT 6
- Trailing commas HOT 13
- Allow wrapping of errors HOT 2
- quick_error macro emits "doc comment not used by rustdoc" HOT 4
- Reimplement as procedural macro? HOT 3
- Conditional compilation fails if enum variants use `from()` HOT 1
- Allow pub(crate)
- File name and line number for error? HOT 2
- no rules expected the token `=>`
- Clarify maintenance HOT 3
- Feature request: impl From<Context<...>> for ExternError HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from quick-error.