Skip to content

Commit

Permalink
inline: parse multiline attributes
Browse files Browse the repository at this point in the history
reimplement after broken by "take str per line instead of full inline
iter" commit

also resolves #18 and #34
  • Loading branch information
hellux committed Apr 4, 2023
1 parent a726be6 commit 4a9b555
Show file tree
Hide file tree
Showing 4 changed files with 352 additions and 113 deletions.
33 changes: 32 additions & 1 deletion src/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,37 @@ impl<'s> std::fmt::Debug for Attributes<'s> {
}
}

pub struct Validator {
state: State,
}

impl Validator {
pub fn new() -> Self {
Self {
state: State::Start,
}
}

pub fn restart(&mut self) {
self.state = State::Start;
}

/// Returns number of valid bytes parsed (0 means invalid) if finished, otherwise more input is
/// needed.
pub fn parse(&mut self, input: &str) -> Option<usize> {
let mut chars = input.chars();
for c in &mut chars {
self.state = self.state.step(c);
match self.state {
State::Done => return Some(input.len() - chars.as_str().len()),
State::Invalid => return Some(0),
_ => {}
}
}
None
}
}

/// Attributes parser, take input of one or more consecutive attributes and create an `Attributes`
/// object.
///
Expand Down Expand Up @@ -302,7 +333,7 @@ impl<'s> Parser<'s> {
}
}

fn finish(self) -> Attributes<'s> {
pub fn finish(self) -> Attributes<'s> {
self.attrs
}
}
Expand Down
Loading

0 comments on commit 4a9b555

Please sign in to comment.