attr: impl valid without Parser

only State fsm is needed

try to use Parser only when attributes need to be stored
This commit is contained in:
Noah Hellman 2023-02-18 20:59:24 +01:00
parent 242a64e3b4
commit 34e74ddc43

View file

@ -12,18 +12,20 @@ pub fn valid<I: Iterator<Item = char>>(chars: I) -> (usize, bool) {
use State::*; use State::*;
let mut has_attr = false; let mut has_attr = false;
let mut p = Parser::new(); let mut n = 0;
let mut state = Start;
for c in chars { for c in chars {
if p.step(c).is_some() { n += 1;
has_attr = true; state = state.step(c);
} match state {
if matches!(p.state, Done | Invalid) { Class | Identifier | Value | ValueQuoted => has_attr = true,
break; Done | Invalid => break,
_ => {}
} }
} }
if matches!(p.state, Done) { if matches!(state, Done) {
(p.pos, has_attr) (n, has_attr)
} else { } else {
(0, false) (0, false)
} }