Remove lexer_util's dependency on resource_task

This commit is contained in:
Brian Anderson 2012-10-30 13:30:13 -07:00
parent 2ea80e2407
commit 86ce867a1c
2 changed files with 17 additions and 7 deletions

View file

@ -9,7 +9,7 @@ use pipes::{Port, Chan};
use lexer_util::*; use lexer_util::*;
use std::net::url::Url; use std::net::url::Url;
use resource::resource_task::{ResourceTask, ProgressMsg, Load}; use resource::resource_task::{ResourceTask, ProgressMsg, Load, Payload, Done};
enum ParserState { enum ParserState {
CssElement, CssElement,
@ -225,12 +225,21 @@ impl CssLexer : CssLexerMethods {
} }
} }
fn resource_port_to_lexer_stream(input_port: comm::Port<ProgressMsg>) -> DataStream {
return || {
match input_port.recv() {
Payload(move data) => Some(move data),
Done(*) => None
}
}
}
fn parser(input_port: comm::Port<ProgressMsg>, state : ParserState) -> CssLexer { fn parser(input_port: comm::Port<ProgressMsg>, state : ParserState) -> CssLexer {
return { return {
input_state: { input_state: {
mut lookahead: None, mut lookahead: None,
mut buffer: ~[], mut buffer: ~[],
input_port: input_port, input: resource_port_to_lexer_stream(input_port),
mut eof: false mut eof: false
}, },
mut parser_state: state mut parser_state: state

View file

@ -6,13 +6,14 @@ use option::is_none;
use str::from_bytes; use str::from_bytes;
use vec::push; use vec::push;
use comm::Port; use comm::Port;
use resource::resource_task::{ProgressMsg, Payload, Done};
enum CharOrEof { enum CharOrEof {
CoeChar(u8), CoeChar(u8),
CoeEof CoeEof
} }
pub type DataStream = @fn() -> Option<~[u8]>;
impl CharOrEof: cmp::Eq { impl CharOrEof: cmp::Eq {
pure fn eq(other: &CharOrEof) -> bool { pure fn eq(other: &CharOrEof) -> bool {
match (self, *other) { match (self, *other) {
@ -29,7 +30,7 @@ impl CharOrEof: cmp::Eq {
type InputState = { type InputState = {
mut lookahead: Option<CharOrEof>, mut lookahead: Option<CharOrEof>,
mut buffer: ~[u8], mut buffer: ~[u8],
input_port: Port<ProgressMsg>, input: DataStream,
mut eof: bool mut eof: bool
}; };
@ -82,13 +83,13 @@ impl InputState : InputStateUtil {
return CoeEof; return CoeEof;
} }
match self.input_port.recv() { match self.input() {
Payload(data) => { Some(data) => {
// TODO: change copy to move once we have match move // TODO: change copy to move once we have match move
self.buffer = copy data; self.buffer = copy data;
return CoeChar(vec::shift(&mut self.buffer)); return CoeChar(vec::shift(&mut self.buffer));
} }
Done(*) => { None => {
self.eof = true; self.eof = true;
return CoeEof; return CoeEof;
} }