mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
Move parsers and lexers to css/ and html/ top-level dirs; fix some s/import/use/
This commit is contained in:
parent
10f1729a71
commit
977389d2a3
9 changed files with 87 additions and 86 deletions
|
@ -7,43 +7,43 @@ export ContentTask;
|
||||||
export ControlMsg, ExecuteMsg, ParseMsg, ExitMsg, Timer;
|
export ControlMsg, ExecuteMsg, ParseMsg, ExitMsg, Timer;
|
||||||
export PingMsg, PongMsg;
|
export PingMsg, PongMsg;
|
||||||
|
|
||||||
import std::arc::{ARC, clone};
|
use std::arc::{ARC, clone};
|
||||||
import comm::{Port, Chan, listen, select2};
|
use comm::{Port, Chan, listen, select2};
|
||||||
import task::{spawn, spawn_listener};
|
use task::{spawn, spawn_listener};
|
||||||
import io::{read_whole_file, println};
|
use io::{read_whole_file, println};
|
||||||
|
|
||||||
import dom::base::{Document, Node, NodeScope, Window, define_bindings};
|
use dom::base::{Document, Node, NodeScope, Window, define_bindings};
|
||||||
import dom::event::{Event, ResizeEvent, ReflowEvent};
|
use dom::event::{Event, ResizeEvent, ReflowEvent};
|
||||||
import gfx::compositor::Compositor;
|
use gfx::compositor::Compositor;
|
||||||
import parser::html_lexer::spawn_html_lexer_task;
|
use html::lexer::spawn_html_lexer_task;
|
||||||
import parser::html_builder::build_dom;
|
use html::dom_builder::build_dom;
|
||||||
import layout::layout_task;
|
use layout::layout_task;
|
||||||
import layout_task::{LayoutTask, BuildMsg};
|
use layout_task::{LayoutTask, BuildMsg};
|
||||||
|
|
||||||
import css::styles::Stylesheet;
|
use css::styles::Stylesheet;
|
||||||
|
|
||||||
import jsrt = js::rust::rt;
|
use jsrt = js::rust::rt;
|
||||||
import js::rust::{cx, methods};
|
use js::rust::{cx, methods};
|
||||||
import js::global::{global_class, debug_fns};
|
use js::global::{global_class, debug_fns};
|
||||||
|
|
||||||
import either::{Either, Left, Right};
|
use either::{Either, Left, Right};
|
||||||
|
|
||||||
import dom::bindings::utils::rust_box;
|
use dom::bindings::utils::rust_box;
|
||||||
import js::rust::compartment;
|
use js::rust::compartment;
|
||||||
|
|
||||||
import resource::resource_task;
|
use resource::resource_task;
|
||||||
import resource_task::{ResourceTask};
|
use resource_task::{ResourceTask};
|
||||||
|
|
||||||
import std::net::url::Url;
|
use std::net::url::Url;
|
||||||
import url_to_str = std::net::url::to_str;
|
use url_to_str = std::net::url::to_str;
|
||||||
import util::url::make_url;
|
use util::url::make_url;
|
||||||
import task::{task, SingleThreaded};
|
use task::{task, SingleThreaded};
|
||||||
|
|
||||||
import js::glue::bindgen::RUST_JSVAL_TO_OBJECT;
|
use js::glue::bindgen::RUST_JSVAL_TO_OBJECT;
|
||||||
import js::JSVAL_NULL;
|
use js::JSVAL_NULL;
|
||||||
import js::jsapi::jsval;
|
use js::jsapi::jsval;
|
||||||
import js::jsapi::bindgen::JS_CallFunctionValue;
|
use js::jsapi::bindgen::JS_CallFunctionValue;
|
||||||
import ptr::null;
|
use ptr::null;
|
||||||
|
|
||||||
enum ControlMsg {
|
enum ControlMsg {
|
||||||
ParseMsg(Url),
|
ParseMsg(Url),
|
||||||
|
@ -149,9 +149,9 @@ struct Content<C:Compositor> {
|
||||||
let css_rules = style_port.recv();
|
let css_rules = style_port.recv();
|
||||||
let js_scripts = js_port.recv();*/
|
let js_scripts = js_port.recv();*/
|
||||||
|
|
||||||
let result = parser::hubbub_html_parser::parse_html(self.scope,
|
let result = html::hubbub_html_parser::parse_html(self.scope,
|
||||||
url,
|
url,
|
||||||
self.resource_task);
|
self.resource_task);
|
||||||
|
|
||||||
let root = result.root;
|
let root = result.root;
|
||||||
let css_rules = result.style_port.recv();
|
let css_rules = result.style_port.recv();
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
#[doc = "Code to lex and tokenize css files."]
|
#[doc = "Code to lex and tokenize css files."]
|
||||||
|
|
||||||
import option::is_none;
|
use option::is_none;
|
||||||
import str::from_bytes;
|
use str::from_bytes;
|
||||||
import vec::push;
|
use vec::push;
|
||||||
|
|
||||||
import pipes::{Port, Chan};
|
use pipes::{Port, Chan};
|
||||||
|
|
||||||
import lexer_util::*;
|
use html::lexer_util::*;
|
||||||
|
|
||||||
import std::net::url::Url;
|
use std::net::url::Url;
|
||||||
import resource::resource_task::{ResourceTask, ProgressMsg, Load};
|
use resource::resource_task::{ResourceTask, ProgressMsg, Load};
|
||||||
|
|
||||||
enum ParserState {
|
enum ParserState {
|
||||||
CssElement,
|
CssElement,
|
|
@ -3,18 +3,18 @@
|
||||||
// TODO: fail according to the css spec instead of failing when things
|
// TODO: fail according to the css spec instead of failing when things
|
||||||
// are not as expected
|
// are not as expected
|
||||||
|
|
||||||
import css::values::{DisInline, DisBlock, DisNone, Display, TextColor, BackgroundColor, FontSize,
|
use css::values::{DisInline, DisBlock, DisNone, Display, TextColor, BackgroundColor, FontSize,
|
||||||
Height, Width, StyleDeclaration};
|
Height, Width, StyleDeclaration};
|
||||||
// Disambiguate parsed Selector, Rule values from tokens
|
// Disambiguate parsed Selector, Rule values from tokens
|
||||||
import css = css::values;
|
use css = css::values;
|
||||||
import tok = parser::css_lexer;
|
use tok = lexer;
|
||||||
import parser::css_lexer::Token;
|
use lexer::Token;
|
||||||
import comm::recv;
|
use comm::recv;
|
||||||
import option::{map, is_none};
|
use option::{map, is_none};
|
||||||
import vec::push;
|
use vec::push;
|
||||||
import parser::parser_util::{parse_display_type, parse_font_size, parse_size};
|
use parser_util::*;
|
||||||
import util::color::parsing::parse_color;
|
use util::color::parsing::parse_color;
|
||||||
import vec::push;
|
use vec::push;
|
||||||
|
|
||||||
type TokenReader = {stream : pipes::Port<Token>, mut lookahead : Option<Token>};
|
type TokenReader = {stream : pipes::Port<Token>, mut lookahead : Option<Token>};
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
#[doc="Constructs a DOM tree from an incoming token stream."]
|
#[doc="Constructs a DOM tree from an incoming token stream."]
|
||||||
|
|
||||||
import dom::base::{Attr, Element, ElementData, ElementKind, HTMLDivElement, HTMLHeadElement,
|
use dom::base::{Attr, Element, ElementData, ElementKind, HTMLDivElement, HTMLHeadElement,
|
||||||
HTMLScriptElement};
|
HTMLScriptElement};
|
||||||
import dom::base::{HTMLImageElement, Node, NodeScope, Text, UnknownElement};
|
use dom::base::{HTMLImageElement, Node, NodeScope, Text, UnknownElement};
|
||||||
import geom::size::Size2D;
|
use geom::size::Size2D;
|
||||||
import gfx::geometry;
|
use gfx::geometry;
|
||||||
import gfx::geometry::au;
|
use gfx::geometry::au;
|
||||||
import parser = parser::html_lexer;
|
use html::lexer;
|
||||||
import parser::Token;
|
use html::lexer::Token;
|
||||||
import css::values::Stylesheet;
|
use css::values::Stylesheet;
|
||||||
import vec::{push, push_all_move, flat_map};
|
use vec::{push, push_all_move, flat_map};
|
||||||
import std::net::url::Url;
|
use std::net::url::Url;
|
||||||
import resource::resource_task::{ResourceTask, Load, Payload, Done};
|
use resource::resource_task::{ResourceTask, Load, Payload, Done};
|
||||||
import to_str::ToStr;
|
use to_str::ToStr;
|
||||||
|
|
||||||
enum CSSMessage {
|
enum CSSMessage {
|
||||||
File(Url),
|
File(Url),
|
||||||
|
@ -105,8 +105,8 @@ fn css_link_listener(to_parent : comm::Chan<Stylesheet>, from_parent : comm::Por
|
||||||
let url = copy url;
|
let url = copy url;
|
||||||
task::spawn(|| {
|
task::spawn(|| {
|
||||||
// TODO: change copy to move once we can move into closures
|
// TODO: change copy to move once we can move into closures
|
||||||
let css_stream = css_lexer::spawn_css_lexer_task(copy url, resource_task);
|
let css_stream = css::lexer::spawn_css_lexer_task(copy url, resource_task);
|
||||||
let mut css_rules = css_builder::build_stylesheet(css_stream);
|
let mut css_rules = css::parser::build_stylesheet(css_stream);
|
||||||
result_chan.send(css_rules);
|
result_chan.send(css_rules);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -192,24 +192,24 @@ fn build_dom(scope: NodeScope, stream: comm::Port<Token>, url: Url,
|
||||||
loop {
|
loop {
|
||||||
let token = stream.recv();
|
let token = stream.recv();
|
||||||
match token {
|
match token {
|
||||||
parser::Eof => { break; }
|
lexer::Eof => { break; }
|
||||||
parser::StartOpeningTag(tag_name) => {
|
lexer::StartOpeningTag(tag_name) => {
|
||||||
#debug["starting tag %s", tag_name];
|
#debug["starting tag %s", tag_name];
|
||||||
let element_kind = build_element_kind(tag_name);
|
let element_kind = build_element_kind(tag_name);
|
||||||
let new_node = scope.new_node(Element(ElementData(copy tag_name, element_kind)));
|
let new_node = scope.new_node(Element(ElementData(copy tag_name, element_kind)));
|
||||||
scope.add_child(cur_node, new_node);
|
scope.add_child(cur_node, new_node);
|
||||||
cur_node = new_node;
|
cur_node = new_node;
|
||||||
}
|
}
|
||||||
parser::Attr(key, value) => {
|
lexer::Attr(key, value) => {
|
||||||
#debug["attr: %? = %?", key, value];
|
#debug["attr: %? = %?", key, value];
|
||||||
link_up_attribute(scope, cur_node, copy key, copy value);
|
link_up_attribute(scope, cur_node, copy key, copy value);
|
||||||
}
|
}
|
||||||
parser::EndOpeningTag => {
|
lexer::EndOpeningTag => {
|
||||||
#debug("end opening tag");
|
#debug("end opening tag");
|
||||||
}
|
}
|
||||||
// TODO: Fail more gracefully (i.e. according to the HTML5
|
// TODO: Fail more gracefully (i.e. according to the HTML5
|
||||||
// spec) if we close more tags than we open.
|
// spec) if we close more tags than we open.
|
||||||
parser::SelfCloseTag => {
|
lexer::SelfCloseTag => {
|
||||||
//TODO: check for things other than the link tag
|
//TODO: check for things other than the link tag
|
||||||
scope.read(cur_node, |n| {
|
scope.read(cur_node, |n| {
|
||||||
match *n.kind {
|
match *n.kind {
|
||||||
|
@ -234,7 +234,7 @@ fn build_dom(scope: NodeScope, stream: comm::Port<Token>, url: Url,
|
||||||
});
|
});
|
||||||
cur_node = scope.get_parent(cur_node).get();
|
cur_node = scope.get_parent(cur_node).get();
|
||||||
}
|
}
|
||||||
parser::EndTag(*) => {
|
lexer::EndTag(*) => {
|
||||||
// TODO: Assert that the closing tag has the right name.
|
// TODO: Assert that the closing tag has the right name.
|
||||||
scope.read(cur_node, |n| {
|
scope.read(cur_node, |n| {
|
||||||
match *n.kind {
|
match *n.kind {
|
||||||
|
@ -253,14 +253,14 @@ fn build_dom(scope: NodeScope, stream: comm::Port<Token>, url: Url,
|
||||||
});
|
});
|
||||||
cur_node = scope.get_parent(cur_node).get();
|
cur_node = scope.get_parent(cur_node).get();
|
||||||
}
|
}
|
||||||
parser::Text(s) if !s.is_whitespace() => {
|
lexer::Text(s) if !s.is_whitespace() => {
|
||||||
let new_node = scope.new_node(Text(copy s));
|
let new_node = scope.new_node(Text(copy s));
|
||||||
scope.add_child(cur_node, new_node);
|
scope.add_child(cur_node, new_node);
|
||||||
}
|
}
|
||||||
parser::Text(_) => {
|
lexer::Text(_) => {
|
||||||
// FIXME: Whitespace should not be ignored.
|
// FIXME: Whitespace should not be ignored.
|
||||||
}
|
}
|
||||||
parser::Doctype => {
|
lexer::Doctype => {
|
||||||
// TODO: Do something here...
|
// TODO: Do something here...
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -4,13 +4,13 @@ use dom::base::{Node, NodeScope, Text, UnknownElement};
|
||||||
use css::values::Stylesheet;
|
use css::values::Stylesheet;
|
||||||
use geom::size::Size2D;
|
use geom::size::Size2D;
|
||||||
use gfx::geometry::px_to_au;
|
use gfx::geometry::px_to_au;
|
||||||
use parser::html_builder::CSSMessage;
|
use html::dom_builder::CSSMessage;
|
||||||
use resource::resource_task::{Done, Load, Payload, ResourceTask};
|
use resource::resource_task::{Done, Load, Payload, ResourceTask};
|
||||||
use CSSExitMessage = parser::html_builder::Exit;
|
use CSSExitMessage = html::dom_builder::Exit;
|
||||||
use CSSFileMessage = parser::html_builder::File;
|
use CSSFileMessage = html::dom_builder::File;
|
||||||
use JSExitMessage = parser::html_builder::js_exit;
|
use JSExitMessage = html::dom_builder::js_exit;
|
||||||
use JSFileMessage = parser::html_builder::js_file;
|
use JSFileMessage = html::dom_builder::js_file;
|
||||||
use JSMessage = parser::html_builder::js_message;
|
use JSMessage = html::dom_builder::js_message;
|
||||||
|
|
||||||
use comm::{Chan, Port};
|
use comm::{Chan, Port};
|
||||||
use str::from_slice;
|
use str::from_slice;
|
||||||
|
@ -52,8 +52,8 @@ fn css_link_listener(to_parent : comm::Chan<Stylesheet>, from_parent : comm::Por
|
||||||
let url = copy url;
|
let url = copy url;
|
||||||
task::spawn(|| {
|
task::spawn(|| {
|
||||||
// TODO: change copy to move once we can move into closures
|
// TODO: change copy to move once we can move into closures
|
||||||
let css_stream = css_lexer::spawn_css_lexer_task(copy url, resource_task);
|
let css_stream = css::lexer::spawn_css_lexer_task(copy url, resource_task);
|
||||||
let mut css_rules = css_builder::build_stylesheet(css_stream);
|
let mut css_rules = css::parser::build_stylesheet(css_stream);
|
||||||
result_chan.send(css_rules);
|
result_chan.send(css_rules);
|
||||||
});
|
});
|
||||||
|
|
|
@ -39,6 +39,10 @@ mod content {
|
||||||
}
|
}
|
||||||
|
|
||||||
mod css {
|
mod css {
|
||||||
|
mod lexer;
|
||||||
|
mod parser;
|
||||||
|
mod parser_util;
|
||||||
|
|
||||||
mod values;
|
mod values;
|
||||||
mod styles;
|
mod styles;
|
||||||
mod resolve {
|
mod resolve {
|
||||||
|
@ -74,13 +78,10 @@ mod image {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mod parser {
|
mod html {
|
||||||
|
mod lexer;
|
||||||
mod lexer_util;
|
mod lexer_util;
|
||||||
mod parser_util;
|
mod dom_builder;
|
||||||
mod css_lexer;
|
|
||||||
mod html_lexer;
|
|
||||||
mod html_builder;
|
|
||||||
mod css_builder;
|
|
||||||
mod hubbub_html_parser;
|
mod hubbub_html_parser;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue