aboutsummaryrefslogtreecommitdiff
path: root/examples/tokenize.rs
blob: 791db0fe716c08ce4d8bae46c7bebeb953b29456 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
//! Let's you easily try out the tokenizer with e.g.
//! printf '<h1>Hello world!</h1>' | cargo run --example=tokenize

use html5tokenizer::{Tokenizer, TracingEmitter};
use std::io::BufReader;

fn main() {
    let mut tokenizer = Tokenizer::new(
        BufReader::new(std::io::stdin().lock()),
        TracingEmitter::default(),
    );
    while let Some(token) = tokenizer.next() {
        for (error, _) in tokenizer.emitter_mut().drain_errors() {
            eprintln!("error: {:?}", error);
        }
        let token = token.unwrap();
        println!("{:?}", token);
    }
}