Skip to content

Suspend the whole tokenizer and tree builder on </script> #231

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]

name = "html5ever"
version = "0.9.0"
version = "0.10.0"
authors = [ "The html5ever Project Developers" ]
license = "MIT / Apache-2.0"
repository = "https://github.com/servo/html5ever"
Expand Down
7 changes: 5 additions & 2 deletions examples/noop-tokenize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,19 @@ use std::default::Default;

use tendril::{ByteTendril, ReadExt};

use html5ever::tokenizer::{TokenSink, Token, Tokenizer};
use html5ever::tokenizer::{TokenSinkResult, TokenSink, Token, Tokenizer};
use html5ever::tokenizer::buffer_queue::BufferQueue;

struct Sink(Vec<Token>);

impl TokenSink for Sink {
fn process_token(&mut self, token: Token) {
type Handle = ();

fn process_token(&mut self, token: Token) -> TokenSinkResult<()> {
// Don't use the token, but make sure we don't get
// optimized out entirely.
self.0.push(token);
TokenSinkResult::Continue
}
}

Expand Down
7 changes: 5 additions & 2 deletions examples/tokenize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use std::default::Default;

use tendril::{ByteTendril, ReadExt};

use html5ever::tokenizer::{TokenSink, Tokenizer, Token, TokenizerOpts, ParseError};
use html5ever::tokenizer::{TokenSink, Tokenizer, Token, TokenizerOpts, ParseError, TokenSinkResult};
use html5ever::tokenizer::{CharacterTokens, NullCharacterToken, TagToken, StartTag, EndTag};
use html5ever::tokenizer::buffer_queue::BufferQueue;

Expand All @@ -41,7 +41,9 @@ impl TokenPrinter {
}

impl TokenSink for TokenPrinter {
fn process_token(&mut self, token: Token) {
type Handle = ();

fn process_token(&mut self, token: Token) -> TokenSinkResult<()> {
match token {
CharacterTokens(b) => {
for c in b.chars() {
Expand Down Expand Up @@ -74,6 +76,7 @@ impl TokenSink for TokenPrinter {
println!("OTHER: {:?}", token);
}
}
TokenSinkResult::Continue
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ pub struct Parser<Sink> where Sink: TreeSink {
impl<Sink: TreeSink> TendrilSink<tendril::fmt::UTF8> for Parser<Sink> {
fn process(&mut self, t: StrTendril) {
self.input_buffer.push_front(t);
self.tokenizer.feed(&mut self.input_buffer)
let _ = self.tokenizer.feed(&mut self.input_buffer);
}

// FIXME: Is it too noisy to report every character decoding error?
Expand Down
20 changes: 9 additions & 11 deletions src/tokenizer/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,21 @@ pub enum Token {
// FIXME: rust-lang/rust#22629
unsafe impl Send for Token { }

pub enum StateChangeQuery {
#[derive(Debug, PartialEq)]
#[must_use]
pub enum TokenSinkResult<Handle> {
Continue,
Script(Handle),
Plaintext,
Quiescent,
RawData(states::RawKind),
RawData(states::RawKind)
}

/// Types which can receive tokens from the tokenizer.
pub trait TokenSink {
type Handle;

/// Process a token.
fn process_token(&mut self, token: Token);
fn process_token(&mut self, token: Token) -> TokenSinkResult<Self::Handle>;

/// Used in the markup declaration open state. By default, this always
/// returns false and thus all CDATA sections are tokenized as bogus
Expand All @@ -115,11 +120,4 @@ pub trait TokenSink {
fn adjusted_current_node_present_but_not_in_html_namespace(&self) -> bool {
false
}

/// The tokenizer will call this after emitting any tag.
/// This allows the tree builder to change the tokenizer's state.
/// By default no state changes occur.
fn query_state_change(&mut self) -> Option<StateChangeQuery> {
None
}
}
Loading