-
-
Notifications
You must be signed in to change notification settings - Fork 128
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
Add option to change error constructor #445
Open
mysteriouslyseeing
wants to merge
14
commits into
maciejhirsz:master
Choose a base branch
from
mysteriouslyseeing:error_callback
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
0b53340
Added initial functionality to error callback
mysteriouslyseeing 63169b5
Changed Logos::make_error to take a mutable reference
mysteriouslyseeing fe62bcb
Added error_callback usage to custom_error.rs
mysteriouslyseeing 5d80583
changed custom_error test to use error_callback
mysteriouslyseeing 2ee7e14
Updated book
mysteriouslyseeing a0a358e
Removed temporary example
mysteriouslyseeing 582cfcc
Removed error_callback attr, added to error
mysteriouslyseeing 7834597
Edit book to reflect syntax changes
mysteriouslyseeing ac220e4
Added mini example to book
mysteriouslyseeing d7b1e7c
Added #[inline(always)]
mysteriouslyseeing 227eed4
Fixed performance regression
mysteriouslyseeing 9835896
Added #[doc(hidden)] to Logos::make_error
mysteriouslyseeing ac45573
Removed redundant method `set_error`
mysteriouslyseeing 6ae71c4
CallbackResults now use Token::make_error
mysteriouslyseeing File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
use proc_macro2::{Span, TokenStream}; | ||
use syn::spanned::Spanned; | ||
use syn::Ident; | ||
|
||
use crate::leaf::Callback; | ||
use crate::parser::nested::NestedValue; | ||
use crate::parser::Parser; | ||
use crate::util::MaybeVoid; | ||
|
||
pub struct ErrorType { | ||
pub ty: TokenStream, | ||
pub callback: Option<Callback>, | ||
} | ||
|
||
impl ErrorType { | ||
pub fn new(ty: TokenStream) -> Self { | ||
Self { ty, callback: None } | ||
} | ||
|
||
pub fn named_attr(&mut self, name: Ident, value: NestedValue, parser: &mut Parser) { | ||
match (name.to_string().as_str(), value) { | ||
("callback", NestedValue::Assign(tokens)) => { | ||
let span = tokens.span(); | ||
let callback = match parser.parse_callback(tokens) { | ||
Some(callback) => callback, | ||
None => { | ||
parser.err("Not a valid callback", span); | ||
return; | ||
} | ||
}; | ||
|
||
if let Some(previous) = self.callback.replace(callback) { | ||
parser | ||
.err( | ||
"Callback has been already set", | ||
span.join(name.span()).unwrap(), | ||
) | ||
.err("Previous callback set here", previous.span()); | ||
} | ||
} | ||
("callback", _) => { | ||
parser.err("Expected: callback = ...", name.span()); | ||
} | ||
(unknown, _) => { | ||
parser.err( | ||
format!( | ||
"\ | ||
Unknown nested attribute: {}\n\ | ||
\n\ | ||
Expected one of: callback\ | ||
", | ||
unknown | ||
), | ||
name.span(), | ||
); | ||
} | ||
} | ||
} | ||
|
||
pub fn unwrap(opt: Option<Self>) -> (MaybeVoid, Option<Callback>) { | ||
if let Some(Self { ty, callback }) = opt { | ||
(MaybeVoid::Some(ty), callback) | ||
} else { | ||
(MaybeVoid::Void, None) | ||
} | ||
} | ||
|
||
pub fn span(&self) -> Span { | ||
self.ty.span() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
We can probably try this to see if that helps the compiler.
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.
Performance is unchanged, unfortunately: