Skip to content

Commit 50bcef5

Browse files
authored
Merge pull request #1 from servo/m5e
markup5ever followups
2 parents 261bf36 + 0a87717 commit 50bcef5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1077
-1562
lines changed

html5ever/Cargo.toml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,25 +31,18 @@ harness = false
3131

3232
[features]
3333
unstable = ["tendril/unstable"]
34-
heap_size = ["heapsize", "heapsize_derive", "markup5ever/heap_size"]
34+
heap_size = ["markup5ever/heap_size"]
3535

3636
[dependencies]
3737
log = "0"
38-
phf = "0.7"
3938
mac = "0"
4039
tendril = "0.2.2"
41-
heapsize = { version = "0.3", optional = true }
42-
heapsize_derive = { version = "0.1", optional = true }
4340
markup5ever = { version = "0.1", path = "../markup5ever" }
4441

4542
[dev-dependencies]
4643
rustc-serialize = "0.3.15"
4744
rustc-test = "0.1.3"
4845

4946
[build-dependencies]
50-
phf_codegen = "0.7.3"
5147
quote = "0.3.3"
52-
rustc-serialize = "0.3.15"
5348
syn = { version = "0.11", features = ["full", "visit"] }
54-
55-

html5ever/build.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
// option. This file may not be copied, modified, or distributed
88
// except according to those terms.
99

10-
extern crate phf_codegen;
1110
#[macro_use] extern crate quote;
1211
extern crate syn;
1312

@@ -26,4 +25,4 @@ fn main() {
2625
&Path::new(&env::var("OUT_DIR").unwrap()).join("rules.rs"));
2726

2827
println!("cargo:rerun-if-changed={}", rules_rs.display());
29-
}
28+
}

html5ever/examples/noop-tree-builder.rs

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,16 @@
77
// option. This file may not be copied, modified, or distributed
88
// except according to those terms.
99

10-
#[macro_use]
11-
extern crate markup5ever;
12-
13-
extern crate html5ever;
10+
#[macro_use] extern crate html5ever;
1411

1512
use std::io;
1613
use std::default::Default;
1714
use std::collections::HashMap;
1815
use std::borrow::Cow;
1916

20-
use html5ever::{Attribute, QualName};
17+
use html5ever::{Attribute, QualName, ExpandedName};
2118
use html5ever::parse_document;
22-
use html5ever::tree_builder::{TreeSink, QuirksMode, NodeOrText};
19+
use html5ever::tree_builder::{TreeSink, QuirksMode, NodeOrText, ElementFlags};
2320
use html5ever::tendril::*;
2421

2522
struct Sink {
@@ -44,35 +41,27 @@ impl TreeSink for Sink {
4441
0
4542
}
4643

47-
fn get_template_contents(&mut self, target: usize) -> usize {
48-
if let Some(&qualname!(html, "template")) = self.names.get(&target) {
44+
fn get_template_contents(&mut self, target: &usize) -> usize {
45+
if let Some(expanded_name!(html "template")) = self.names.get(&target).map(|n| n.expanded()) {
4946
target + 1
5047
} else {
5148
panic!("not a template element")
5249
}
5350
}
5451

55-
fn same_node(&self, x: usize, y: usize) -> bool {
56-
x == y
57-
}
58-
59-
fn same_node_ref(&self, x: &usize, y: &usize) -> bool {
52+
fn same_node(&self, x: &usize, y: &usize) -> bool {
6053
x == y
6154
}
6255

63-
fn same_tree(&self, _x: usize, _y: usize) -> bool {
56+
fn same_tree(&self, _x: &usize, _y: &usize) -> bool {
6457
true
6558
}
6659

67-
fn elem_name(&self, target: usize) -> QualName {
68-
self.names.get(&target).expect("not an element").clone()
69-
}
70-
71-
fn elem_name_ref(&self, target: &usize) -> QualName {
72-
self.names.get(target).expect("not an element").clone()
60+
fn elem_name(&self, target: &usize) -> ExpandedName {
61+
self.names.get(target).expect("not an element").expanded()
7362
}
7463

75-
fn create_element(&mut self, name: QualName, _attrs: Vec<Attribute>) -> usize {
64+
fn create_element(&mut self, name: QualName, _: Vec<Attribute>, _: ElementFlags) -> usize {
7665
let id = self.get_id();
7766
self.names.insert(id, name);
7867
id
@@ -87,27 +76,27 @@ impl TreeSink for Sink {
8776
unimplemented!()
8877
}
8978

90-
fn has_parent_node(&self, _node: usize) -> bool {
79+
fn has_parent_node(&self, _node: &usize) -> bool {
9180
// `node` will have a parent unless a script moved it, and we're
9281
// not running scripts. Therefore we can aways return true.
9382
true
9483
}
9584

9685
fn append_before_sibling(&mut self,
97-
_sibling: usize,
86+
_sibling: &usize,
9887
_new_node: NodeOrText<usize>) { }
9988

10089
fn parse_error(&mut self, _msg: Cow<'static, str>) { }
10190
fn set_quirks_mode(&mut self, _mode: QuirksMode) { }
102-
fn append(&mut self, _parent: usize, _child: NodeOrText<usize>) { }
91+
fn append(&mut self, _parent: &usize, _child: NodeOrText<usize>) { }
10392

10493
fn append_doctype_to_document(&mut self, _: StrTendril, _: StrTendril, _: StrTendril) { }
105-
fn add_attrs_if_missing(&mut self, target: usize, _attrs: Vec<Attribute>) {
94+
fn add_attrs_if_missing(&mut self, target: &usize, _attrs: Vec<Attribute>) {
10695
assert!(self.names.contains_key(&target), "not an element");
10796
}
108-
fn remove_from_parent(&mut self, _target: usize) { }
109-
fn reparent_children(&mut self, _node: usize, _new_parent: usize) { }
110-
fn mark_script_already_started(&mut self, _node: usize) { }
97+
fn remove_from_parent(&mut self, _target: &usize) { }
98+
fn reparent_children(&mut self, _node: &usize, _new_parent: &usize) { }
99+
fn mark_script_already_started(&mut self, _node: &usize) { }
111100
}
112101

113102
fn main() {

html5ever/examples/print-rcdom.rs

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@
77
// option. This file may not be copied, modified, or distributed
88
// except according to those terms.
99

10-
#[macro_use]
11-
extern crate markup5ever;
12-
13-
extern crate html5ever;
10+
#[macro_use] extern crate html5ever;
1411
extern crate tendril;
1512

1613
use std::io;
@@ -20,39 +17,41 @@ use std::string::String;
2017

2118
use tendril::TendrilSink;
2219
use html5ever::parse_document;
23-
use html5ever::rcdom::{Document, Doctype, Text, Comment, Element, RcDom, Handle};
20+
use html5ever::rcdom::{NodeData, RcDom, Handle};
2421

2522
// This is not proper HTML serialization, of course.
2623

2724
fn walk(indent: usize, handle: Handle) {
28-
let node = handle.borrow();
25+
let node = handle;
2926
// FIXME: don't allocate
3027
print!("{}", repeat(" ").take(indent).collect::<String>());
31-
match node.node {
32-
Document
28+
match node.data {
29+
NodeData::Document
3330
=> println!("#Document"),
3431

35-
Doctype(ref name, ref public, ref system)
36-
=> println!("<!DOCTYPE {} \"{}\" \"{}\">", *name, *public, *system),
32+
NodeData::Doctype { ref name, ref public_id, ref system_id }
33+
=> println!("<!DOCTYPE {} \"{}\" \"{}\">", name, public_id, system_id),
3734

38-
Text(ref text)
39-
=> println!("#text: {}", escape_default(text)),
35+
NodeData::Text { ref contents }
36+
=> println!("#text: {}", escape_default(&contents.borrow())),
4037

41-
Comment(ref text)
42-
=> println!("<!-- {} -->", escape_default(text)),
38+
NodeData::Comment { ref contents }
39+
=> println!("<!-- {} -->", escape_default(contents)),
4340

44-
Element(ref name, _, ref attrs) => {
41+
NodeData::Element { ref name, ref attrs, .. } => {
4542
assert!(name.ns == ns!(html));
4643
print!("<{}", name.local);
47-
for attr in attrs.iter() {
44+
for attr in attrs.borrow().iter() {
4845
assert!(attr.name.ns == ns!());
4946
print!(" {}=\"{}\"", attr.name.local, attr.value);
5047
}
5148
println!(">");
5249
}
50+
51+
NodeData::ProcessingInstruction { .. } => unreachable!()
5352
}
5453

55-
for child in node.children.iter() {
54+
for child in node.children.borrow().iter() {
5655
walk(indent+4, child.clone());
5756
}
5857
}

html5ever/examples/print-tree-actions.rs

Lines changed: 19 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,15 @@
77
// option. This file may not be copied, modified, or distributed
88
// except according to those terms.
99

10-
#[macro_use]
11-
extern crate markup5ever;
12-
13-
extern crate html5ever;
10+
#[macro_use] extern crate html5ever;
1411

1512
use std::io;
1613
use std::default::Default;
1714
use std::collections::HashMap;
1815
use std::borrow::Cow;
1916

20-
use html5ever::{QualName, Attribute};
21-
use html5ever::tree_builder::{TreeSink, QuirksMode, NodeOrText, AppendNode, AppendText};
17+
use html5ever::{QualName, ExpandedName, Attribute};
18+
use html5ever::tree_builder::{TreeSink, QuirksMode, NodeOrText, AppendNode, AppendText, ElementFlags};
2219
use html5ever::parse_document;
2320
use html5ever::tendril::*;
2421

@@ -48,8 +45,8 @@ impl TreeSink for Sink {
4845
0
4946
}
5047

51-
fn get_template_contents(&mut self, target: usize) -> usize {
52-
if let Some(&qualname!(html, "template")) = self.names.get(&target) {
48+
fn get_template_contents(&mut self, target: &usize) -> usize {
49+
if let Some(expanded_name!(html "template")) = self.names.get(target).map(|n| n.expanded()) {
5350
target + 1
5451
} else {
5552
panic!("not a template element")
@@ -60,24 +57,15 @@ impl TreeSink for Sink {
6057
println!("Set quirks mode to {:?}", mode);
6158
}
6259

63-
fn same_node(&self, x: usize, y: usize) -> bool {
64-
x == y
65-
}
66-
67-
fn same_node_ref(&self, x: &usize, y: &usize) -> bool {
60+
fn same_node(&self, x: &usize, y: &usize) -> bool {
6861
x == y
6962
}
7063

71-
fn elem_name(&self, target: usize) -> QualName {
72-
self.names.get(&target).expect("not an element").clone()
64+
fn elem_name(&self, target: &usize) -> ExpandedName {
65+
self.names.get(target).expect("not an element").expanded()
7366
}
7467

75-
fn elem_name_ref(&self, target: &usize) -> QualName {
76-
self.names.get(target).expect("not an element").clone()
77-
}
78-
79-
80-
fn create_element(&mut self, name: QualName, _attrs: Vec<Attribute>) -> usize {
68+
fn create_element(&mut self, name: QualName, _: Vec<Attribute>, _: ElementFlags) -> usize {
8169
let id = self.get_id();
8270
println!("Created {:?} as {}", name, id);
8371
self.names.insert(id, name);
@@ -95,13 +83,13 @@ impl TreeSink for Sink {
9583
unimplemented!()
9684
}
9785

98-
fn has_parent_node(&self, _node: usize) -> bool {
86+
fn has_parent_node(&self, _node: &usize) -> bool {
9987
// `node` will have a parent unless a script moved it, and we're
10088
// not running scripts. Therefore we can aways return true
10189
true
10290
}
10391

104-
fn append(&mut self, parent: usize, child: NodeOrText<usize>) {
92+
fn append(&mut self, parent: &usize, child: NodeOrText<usize>) {
10593
match child {
10694
AppendNode(n)
10795
=> println!("Append node {} to {}", n, parent),
@@ -111,7 +99,7 @@ impl TreeSink for Sink {
11199
}
112100

113101
fn append_before_sibling(&mut self,
114-
sibling: usize,
102+
sibling: &usize,
115103
new_node: NodeOrText<usize>) {
116104
match new_node {
117105
AppendNode(n)
@@ -128,37 +116,37 @@ impl TreeSink for Sink {
128116
println!("Append doctype: {} {} {}", name, public_id, system_id);
129117
}
130118

131-
fn add_attrs_if_missing(&mut self, target: usize, attrs: Vec<Attribute>) {
132-
assert!(self.names.contains_key(&target), "not an element");
119+
fn add_attrs_if_missing(&mut self, target: &usize, attrs: Vec<Attribute>) {
120+
assert!(self.names.contains_key(target), "not an element");
133121
println!("Add missing attributes to {}:", target);
134122
for attr in attrs.into_iter() {
135123
println!(" {:?} = {}", attr.name, attr.value);
136124
}
137125
}
138126

139-
fn associate_with_form(&mut self, _target: usize, _form: usize) {
127+
fn associate_with_form(&mut self, _target: &usize, _form: &usize) {
140128
// No form owner support. Since same_tree always returns
141129
// true we cannot be sure that this associate_with_form call is
142130
// valid
143131
}
144132

145-
fn remove_from_parent(&mut self, target: usize) {
133+
fn remove_from_parent(&mut self, target: &usize) {
146134
println!("Remove {} from parent", target);
147135
}
148136

149-
fn reparent_children(&mut self, node: usize, new_parent: usize) {
137+
fn reparent_children(&mut self, node: &usize, new_parent: &usize) {
150138
println!("Move children from {} to {}", node, new_parent);
151139
}
152140

153-
fn mark_script_already_started(&mut self, node: usize) {
141+
fn mark_script_already_started(&mut self, node: &usize) {
154142
println!("Mark script {} as already started", node);
155143
}
156144

157145
fn set_current_line(&mut self, line_number: u64) {
158146
println!("Set current line to {}", line_number);
159147
}
160148

161-
fn pop(&mut self, elem: usize) {
149+
fn pop(&mut self, elem: &usize) {
162150
println!("Popped element {}", elem);
163151
}
164152
}

html5ever/src/driver.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99

1010
//! High-level interface to the parser.
1111
12+
use {Attribute, QualName};
13+
use buffer_queue::BufferQueue;
1214
use tokenizer::{Tokenizer, TokenizerOpts, TokenizerResult};
13-
use markup5ever::util::buffer_queue::BufferQueue;
14-
use tree_builder::{TreeBuilderOpts, TreeBuilder, TreeSink};
15+
use tree_builder::{TreeBuilderOpts, TreeBuilder, TreeSink, create_element};
1516

1617
use std::borrow::Cow;
1718
use std::mem;
@@ -20,7 +21,6 @@ use encoding::{self, EncodingRef};
2021
use tendril;
2122
use tendril::{StrTendril, ByteTendril};
2223
use tendril::stream::{TendrilSink, Utf8LossyDecoder, LossyDecoder};
23-
use markup5ever::{Attribute, QualName};
2424

2525
/// All-encompassing options struct for the parser.
2626
#[derive(Clone, Default)]
@@ -56,7 +56,7 @@ pub fn parse_fragment<Sink>(mut sink: Sink, opts: ParseOpts,
5656
context_name: QualName, context_attrs: Vec<Attribute>)
5757
-> Parser<Sink>
5858
where Sink: TreeSink {
59-
let context_elem = sink.create_element(context_name, context_attrs);
59+
let context_elem = create_element(&mut sink, context_name, context_attrs);
6060
parse_fragment_for_element(sink, opts, context_elem, None)
6161
}
6262

html5ever/src/lib.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,10 @@
1313
#![cfg_attr(test, deny(warnings))]
1414
#![allow(unused_parens)]
1515

16-
#![cfg_attr(feature = "heap_size", feature(proc_macro))]
17-
#[cfg(feature = "heap_size")] #[macro_use] extern crate heapsize_derive;
18-
#[cfg(feature = "heap_size")] extern crate heapsize;
19-
2016
#[macro_use] extern crate log;
2117
#[macro_use] extern crate markup5ever;
2218
#[macro_use] extern crate mac;
2319

24-
extern crate phf;
25-
2620
pub use markup5ever::*;
2721
pub use driver::{ParseOpts, parse_document, parse_fragment, Parser};
2822

@@ -39,7 +33,6 @@ pub mod serialize;
3933
pub mod tokenizer;
4034
pub mod tree_builder;
4135
pub mod driver;
42-
pub mod rcdom;
4336

4437
/// Re-export the tendril crate.
4538
pub mod tendril {

0 commit comments

Comments
 (0)