-
Notifications
You must be signed in to change notification settings - Fork 143
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
Move printing to Display
and parsing to a new trait, FromOp
.
#86
Conversation
This removes `Language::from_op_str` and `Language::display_op`, replacing them with `OpStr::from_str` and `OpStr::fmt`, respectively. `define_language!` is also modified to implement this trait automatically.
Awesome! There's a lot of good stuff here. A couple thoughts:
|
Ah, I see your thiserror changes are actually pretty widespread. I guess it's worth keeping then. |
Good questions! Re: As I've been thinking about this more, I'm wondering whether we really want to be using strings at all. Right now the way these string functions are used is for constructing and parsing sexps, so maybe it would make more sense if we had Also, re: |
Yes, Display just prints the operator. That's true, it's mostly used to print sexps, but there are couple places where it's nice to just print the operators, like in Dot. |
Ok, I think that makes sense. I'll rework it into a trait for parsing and |
OpStr
.Display
and parsing to a new trait, FromOp
.
@mwillsey I made the changes you suggested -- let me know if there's anything else I should change. |
Nice work, thanks! |
This fixes #83 by replacing
Language::display_op
withOpStr::fmt
Display
. It also movesLanguage::from_op_str
toOpStr::from_str
FromOp::from_op
. Moving these two functions to a separate trait eliminates the need to give them default implementations which panic.define_language!
has been updated to automatically implementOpStr
Display
andFromOp
, so the transition should be seamless for people using the macro.Additionally, this pull request adds a dependency on thiserror, a crate which provides a derive macro for
std::error::Error
, as this refactoring replaces several instances ofString
being used as an error type with structured error types implementingError
.Let me know if there's anything that should be adjusted!