Skip to content

Commit

Permalink
trying new parsing algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
alensiljak committed Jul 27, 2023
1 parent 158f54d commit 87e0390
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 4 deletions.
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ keywords = ["library", "finance", "wasm"]
# For WASM:
# [target.'cfg(target_arch = "wasm32")'.lib]
[lib]
crate-type = ["cdylib"]
# , "rlib"
crate-type = ["cdylib", "rlib"]

[dependencies]
anyhow = "1.0.71"
Expand Down
26 changes: 26 additions & 0 deletions src/journalreader.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*!
* Journal Reader reads lines from the journal string and keeps track of the
* line number.
*/

/// Reads the input text line by line and keeps track of the line number.
struct JournalReader {}

impl JournalReader {
pub fn new() -> Self {
JournalReader { }
}
}

#[cfg(test)]
mod tests {
use super::JournalReader;

#[test]
fn test_instantiation() {
let x = JournalReader::new();

// if no exceptions
assert!(true);
}
}
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ pub mod commodity;
pub mod history;
mod iterator;
pub mod journal;
mod journalreader;
mod option;
pub mod parser;
mod parser_experiment;
pub mod pool;
pub mod post;
pub mod report;
Expand Down Expand Up @@ -153,8 +155,6 @@ pub fn parse_text(text: &str, journal: &mut Journal) {
parser::read_into_journal(source, journal);
}

// #[cfg(target_arch = "wasm32")]
// #[wasm_bindgen]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen)]
pub fn wasm_test() -> String {
"hello from wasm".to_owned()
Expand Down
24 changes: 24 additions & 0 deletions src/parser_experiment.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*!
* A different approach to parsing.
* Tailored to Wasm usage.
* Break down steps into logical units.
* Use the iterator?
*/

use std::io::{BufReader, Read};

use crate::iterator::DirectiveType;

/// Read Journal, convert to directives
pub fn text_to_directives() {
// reader: BufReader<T>
// todo

// read line from the Journal
// determine the type
// DirectiveType
// scan the line
// parse into a model instance
// read additional lines, as needed. Ie for Xact/Posts.
// return the directive with the entity, if created
}
3 changes: 3 additions & 0 deletions tests/tests-for-wasm.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/*!
* Tests for the functionality used in Wasm.
*/

0 comments on commit 87e0390

Please sign in to comment.