-
Notifications
You must be signed in to change notification settings - Fork 7
Add support for parsing attributes and other improvements #23
Conversation
This reverts commit e825950.
i8::from_le_bytes(value_bytes.try_into().unwrap()) | ||
} | ||
|
||
fn read_u8(bytes: &mut &[u8]) -> u8 { |
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.
Not too happy with these - seems very repetitive, but couldn't figure out how to write this as a generic function - much like a function template in C++.
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.
You could use a macro to write these.
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.
Looking great!
let snake = syn::Ident::new(&to_snake(&camel_name), camel.span()); | ||
let index = index as u32; | ||
if let Some((_, value)) = &variant.discriminant { | ||
if let syn::Expr::Lit(value) = value { |
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.
You can inline this if let
into the one above:
if let Some((_, syn::Expr::Lit(value))) = &variant.discriminant {
|
||
pub fn split_type_name(name: &str) -> ParseResult<(&str, &str)> { | ||
let index = name.rfind('.').ok_or_else(|| ParseError::InvalidTypeName)?; | ||
Ok((name.get(0..index).unwrap(), name.get(index + 1..).unwrap())) |
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.
nit: if you're just going to unwrap
no need to use get
. You can do name[0..index]
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.
Right, forgot about that. 👍
use crate::tables::*; | ||
|
||
pub struct Reader { | ||
files: std::vec::Vec<File>, |
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.
nit: Vec
doesn't need to be namespaced
types: &'a NamespaceData, | ||
impl<'a> Iterator for NamespaceIterator<'a> { | ||
type Item = Namespace<'a>; | ||
fn next(&mut self) -> Option<Self::Item> { |
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.
This iterator seems like it can be accomplished using map
on iterator. Is there a need for this custom iterator?
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'll check.
i8::from_le_bytes(value_bytes.try_into().unwrap()) | ||
} | ||
|
||
fn read_u8(bytes: &mut &[u8]) -> u8 { |
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.
You could use a macro to write these.
This update adds the ability to parse basic built-in and custom WinRT attributes, the last remaining feature required by WinRT. It isn't complete, but it does cover the bases. What remains is substantially more testing, which I have started addressing here with some more testing infrastructure that will need to be fleshed out considerably. Notables:
Finally, I now include a test IDL file along with a checked-in winmd file for testing. The latter is checked in to avoid requiring MIDL as part of the build. Once the winmd parser can also produce winmd files, this will no longer be required, but until then it helps to test various edge cases without relying on recent OS metadata.
Fixes #22