Skip to content

Commit

Permalink
feat(null-filter): initial implementation
Browse files Browse the repository at this point in the history
It is known to not work in all cases, i.e. it can only take one
key-value pair at a time (no consecutive ones), but besides that
is a pretty optimal implementation (even though it aint a pretty one).

However, the test still fails, we match nothing for some reason.
Must be evaluated later.
  • Loading branch information
Byron committed May 7, 2015
1 parent f952f08 commit 97adcb8
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 4 deletions.
69 changes: 66 additions & 3 deletions src/filter_null.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
use super::Token;
use super::{Token, TokenType};
use std::collections::VecDeque;

pub struct FilterNull<I: Iterator<Item=Token>> {
src: I,
buf: VecDeque<Token>,
}

impl<I: Iterator<Item=Token>> FilterNull<I> {
pub fn new(src: I) -> FilterNull<I> {
FilterNull {
src: src
src: src,
buf: VecDeque::with_capacity(3),
}
}
}
Expand All @@ -16,7 +19,67 @@ impl<I> Iterator for FilterNull<I> where I: Iterator<Item=Token>{
type Item = Token;

fn next(&mut self) -> Option<Token> {
None
if self.buf.len() > 0 {
return self.buf.pop_front()
}

let token = self.src.next();
match token {
Some(first_str_candidate) => {
match first_str_candidate.kind {
TokenType::String => {
// self.buf.push_back(token);
let first_str_token = first_str_candidate;
match self.src.next() {
Some(colon_candidate) => {
// self.buf.push_back(token);
match colon_candidate.kind {
TokenType::Colon => {
match self.src.next() {
Some(second_str_candidate) => {
// self.buf.push_back(token);
match second_str_candidate.kind {
TokenType::String => {
// WE HAVE A STR : STR triplete, and we forget it
// This works by just not putting it onto the ringbuffer
// See if there is a (optional) comma
match self.src.next() {
Some(comma_candidate) => {
match comma_candidate.kind {
TokenType::Comma => self.src.next(),
_ => Some(comma_candidate)
}
},
None => None,
}
},
_ => {
self.buf.push_back(colon_candidate);
self.buf.push_back(second_str_candidate);
Some(first_str_token)
}
}
},
None => {
self.buf.push_back(colon_candidate);
Some(first_str_token)
}
}
},
_ => {
self.buf.push_back(colon_candidate);
Some(first_str_token)
}
}// end is colon token
},// end have token (colon?)
None => Some(first_str_token),
}// end match next token (colon?)
}// end is string token,
_ => Some(first_str_candidate),
}// end match token kind (string?)
},// end have token
None => None,
}
}
}

2 changes: 1 addition & 1 deletion src/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ impl<I> Iterator for Lexer<I>
},
Mode::Number => {
match c {
'0'
'0'
|'1'
|'2'
|'3'
Expand Down

0 comments on commit 97adcb8

Please sign in to comment.