-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
more work: change to Cursor, start tokenizer
- Loading branch information
1 parent
1f2824a
commit 7b402ab
Showing
7 changed files
with
124 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,6 @@ | ||
use crate::index_file::Index; | ||
use crate::index_file::{Index, IndexFile}; | ||
use std::io::Seek; | ||
|
||
pub trait DataHandler: Seek { | ||
fn synchronize( | ||
&mut self, | ||
indexes: &mut Vec<Index>, | ||
end_byte_offsets: &mut Vec<u64>, | ||
checksums: &mut Vec<u64>, | ||
) -> Result<(), String>; | ||
fn synchronize(&mut self, index_file: &mut IndexFile) -> Result<(), String>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
pub enum Token { | ||
OpenBracket, | ||
CloseBracket, | ||
Colon, | ||
Comma, | ||
String(String), | ||
Number(String), | ||
Boolean(bool), | ||
OpenArray, | ||
CloseArray, | ||
Null, | ||
} | ||
|
||
pub struct JSONTokenizer { | ||
input: Vec<u8>, | ||
position: usize, | ||
} | ||
|
||
impl JSONTokenizer { | ||
pub(crate) fn new(input: Vec<u8>) -> Self { | ||
Self { input, position: 0 } | ||
} | ||
|
||
pub(crate) fn next(&mut self) -> Result<Option<(Token, usize)>, String> { | ||
// edge case: check if we've reached the end of line | ||
if self.position >= self.input.len() { | ||
Ok(None) | ||
} else { | ||
let current_byte = self.input[self.position]; | ||
|
||
return match current_byte { | ||
b'{' => { | ||
self.position += 1; | ||
Ok(Some((Token::OpenBracket, self.position - 1))) | ||
} | ||
b'}' => { | ||
self.position += 1; | ||
Ok(Some((Token::CloseBracket, self.position - 1))) | ||
} | ||
b'[' => { | ||
self.position += 1; | ||
Ok(Some((Token::OpenArray, self.position - 1))) | ||
} | ||
b']' => { | ||
self.position += 1; | ||
Ok(Some((Token::CloseArray, self.position - 1))) | ||
} | ||
b'\"' => { | ||
self.position += 1; | ||
self.tokenize_string() | ||
} | ||
b':' => { | ||
self.position += 1; | ||
Ok(Some((Token::Colon, self.position - 1))) | ||
} | ||
_ => Err(format!( | ||
"Unexpected character at position {}", | ||
self.position - 1 | ||
)), | ||
}; | ||
} | ||
} | ||
|
||
fn tokenize_string(&mut self) -> Result<Option<(Token, usize)>, String> { | ||
let start_position = self.position; | ||
|
||
while self.position < self.input.len() { | ||
let current_byte = self.input[start_position]; | ||
|
||
match current_byte { | ||
b'\"' => { | ||
self.position += 1; | ||
Ok(Some((Token::String, start_position))) | ||
} | ||
b'\\' => { | ||
self.position += 2; // skip \n | ||
continue; | ||
} | ||
_ => { | ||
self.position += 1; | ||
} | ||
} | ||
} | ||
|
||
Err("Unterminated string".to_string()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
pub mod index_file; | ||
pub mod io; | ||
mod json_tokenizer; | ||
|
||
pub mod tests { | ||
pub mod jsonl_index_file; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters