Skip to content

Commit

Permalink
suffering knows no bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
repnop committed Jul 3, 2024
1 parent 38feb4e commit 58016ad
Show file tree
Hide file tree
Showing 4 changed files with 552 additions and 20 deletions.
5 changes: 5 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ pub enum FdtError {
BadPtr,
/// An error was encountered during parsing
ParseError(ParseError),
PHandleNotFound(u32),
MissingRequiredNode(&'static str),
MissingRequiredProperty(&'static str),
InvalidPropertyValue,
Expand All @@ -101,6 +102,10 @@ impl core::fmt::Display for FdtError {
FdtError::BadMagic => write!(f, "bad FDT magic value"),
FdtError::BadPtr => write!(f, "an invalid pointer was passed"),
FdtError::ParseError(e) => core::fmt::Display::fmt(e, f),
FdtError::PHandleNotFound(value) => write!(
f,
"a node containing the `phandle` property value of `{value}` was not found"
),
FdtError::MissingRequiredNode(name) => {
write!(f, "FDT is missing a required node `{}`", name)
}
Expand Down
14 changes: 12 additions & 2 deletions src/nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::{
ParserWithMode, StringsBlock, StructsBlock,
},
properties::{InvalidPropertyValue, Property, PropertyValue},
standard_nodes::Root,
FdtError,
};

Expand Down Expand Up @@ -99,6 +100,13 @@ impl<'a, P: ParserWithMode<'a>> Node<'a, P> {
}
}

pub(crate) fn make_root<P2: Parser<'a, Granularity = P::Granularity>>(
self,
) -> Result<Root<'a, (P2, NoPanic)>, FdtError> {
let mut parser = <(P2, NoPanic)>::new(self.structs.0, self.strings, self.structs);
parser.parse_root().map(|node| Root { node })
}

#[inline]
pub fn name(&self) -> <P as PanicMode>::Output<NodeName<'a>> {
P::to_output(
Expand Down Expand Up @@ -139,8 +147,10 @@ impl<'a, P: ParserWithMode<'a>> Node<'a, P> {
}

#[track_caller]
pub fn property<Prop: Property<'a>>(&self) -> P::Output<Option<Prop>> {
P::to_output(Prop::parse(self.fallible()))
pub fn property<Prop: Property<'a, P>>(&self) -> P::Output<Option<Prop>> {
P::to_output(crate::tryblock! {
Prop::parse(self.alt(), self.make_root()?)
})
}

#[inline]
Expand Down
Loading

0 comments on commit 58016ad

Please sign in to comment.