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:
		
					parent
					
						
							
								242a64e3b4
							
						
					
				
			
			
				commit
				
					
						34e74ddc43
					
				
			
		
					 1 changed files with 10 additions and 8 deletions
				
			
		
							
								
								
									
										18
									
								
								src/attr.rs
									
										
									
									
									
								
							
							
						
						
									
										18
									
								
								src/attr.rs
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -12,18 +12,20 @@ pub fn valid<I: Iterator<Item = char>>(chars: I) -> (usize, bool) {
 | 
			
		|||
    use State::*;
 | 
			
		||||
 | 
			
		||||
    let mut has_attr = false;
 | 
			
		||||
    let mut p = Parser::new();
 | 
			
		||||
    let mut n = 0;
 | 
			
		||||
    let mut state = Start;
 | 
			
		||||
    for c in chars {
 | 
			
		||||
        if p.step(c).is_some() {
 | 
			
		||||
            has_attr = true;
 | 
			
		||||
        }
 | 
			
		||||
        if matches!(p.state, Done | Invalid) {
 | 
			
		||||
            break;
 | 
			
		||||
        n += 1;
 | 
			
		||||
        state = state.step(c);
 | 
			
		||||
        match state {
 | 
			
		||||
            Class | Identifier | Value | ValueQuoted => has_attr = true,
 | 
			
		||||
            Done | Invalid => break,
 | 
			
		||||
            _ => {}
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if matches!(p.state, Done) {
 | 
			
		||||
        (p.pos, has_attr)
 | 
			
		||||
    if matches!(state, Done) {
 | 
			
		||||
        (n, has_attr)
 | 
			
		||||
    } else {
 | 
			
		||||
        (0, false)
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue