mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Remove lexer_util's dependency on resource_task
This commit is contained in:
parent
2ea80e2407
commit
86ce867a1c
2 changed files with 17 additions and 7 deletions
|
@ -9,7 +9,7 @@ use pipes::{Port, Chan};
|
|||
use lexer_util::*;
|
||||
|
||||
use std::net::url::Url;
|
||||
use resource::resource_task::{ResourceTask, ProgressMsg, Load};
|
||||
use resource::resource_task::{ResourceTask, ProgressMsg, Load, Payload, Done};
|
||||
|
||||
enum ParserState {
|
||||
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 {
|
||||
return {
|
||||
input_state: {
|
||||
mut lookahead: None,
|
||||
mut buffer: ~[],
|
||||
input_port: input_port,
|
||||
input: resource_port_to_lexer_stream(input_port),
|
||||
mut eof: false
|
||||
},
|
||||
mut parser_state: state
|
||||
|
|
|
@ -6,13 +6,14 @@ use option::is_none;
|
|||
use str::from_bytes;
|
||||
use vec::push;
|
||||
use comm::Port;
|
||||
use resource::resource_task::{ProgressMsg, Payload, Done};
|
||||
|
||||
enum CharOrEof {
|
||||
CoeChar(u8),
|
||||
CoeEof
|
||||
}
|
||||
|
||||
pub type DataStream = @fn() -> Option<~[u8]>;
|
||||
|
||||
impl CharOrEof: cmp::Eq {
|
||||
pure fn eq(other: &CharOrEof) -> bool {
|
||||
match (self, *other) {
|
||||
|
@ -29,7 +30,7 @@ impl CharOrEof: cmp::Eq {
|
|||
type InputState = {
|
||||
mut lookahead: Option<CharOrEof>,
|
||||
mut buffer: ~[u8],
|
||||
input_port: Port<ProgressMsg>,
|
||||
input: DataStream,
|
||||
mut eof: bool
|
||||
};
|
||||
|
||||
|
@ -82,13 +83,13 @@ impl InputState : InputStateUtil {
|
|||
return CoeEof;
|
||||
}
|
||||
|
||||
match self.input_port.recv() {
|
||||
Payload(data) => {
|
||||
match self.input() {
|
||||
Some(data) => {
|
||||
// TODO: change copy to move once we have match move
|
||||
self.buffer = copy data;
|
||||
return CoeChar(vec::shift(&mut self.buffer));
|
||||
}
|
||||
Done(*) => {
|
||||
None => {
|
||||
self.eof = true;
|
||||
return CoeEof;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue