Skip to content

Commit 96d2452

Browse files
jburnettjb-intellinetjburnett
authored
Merge from Dev (#2)
* Add pta link to readme * create CI workflow * Initial code migrated from other project * Rm'd extraneous ledger module; minor edits * Add CLI to verify accessibility and for future impl * WIP: Cli parses basic ledger * Fix commodity directive * WIP: multiple comment tokens; CLI output * trans block parses * Refactor parser tests * add simple transactions to ledger file * Consolidate pest rules to simplify * WIP: consuming parser * Removed pest_consume * vscode settings * moving parse handling to builder; refactor cli to use it * WIP: LedgerBuilder, logging * Fix warnings * Begin multiple grammar support * v0.2.0 - multi-grammar support * pkg upgrades * Upgrade log to 0.4.21 & adapt warn macro * Rm warnings on unused workspace repos info --------- Co-authored-by: jburnett <[email protected]> Co-authored-by: jburnett <[email protected]>
1 parent dd5bb83 commit 96d2452

22 files changed

+1368
-0
lines changed

.vscode/settings.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"rust-analyzer.linkedProjects": [
3+
"./cli/Cargo.toml",
4+
"./pta-ledger/Cargo.toml",
5+
"./pta-parser/Cargo.toml",
6+
"./pta-types/Cargo.toml"
7+
]
8+
}

Cargo.toml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Copyright (C) 2023, AltaModa Technologies, LLC. All rights reserved.
2+
#
3+
# This project is licensed under the terms of the MIT license (cf. LICENSE file in root).
4+
5+
[workspace]
6+
resolver = "2"
7+
members = [
8+
"cli"
9+
,"pta-ledger"
10+
,"pta-parser"
11+
,'pta-types',
12+
]
13+
14+
# Default values for workspace projects
15+
[workspace.package]
16+
edition = "2021"
17+
version = "0.2.0"
18+
authors = ["AltaModa Technologies"]
19+
# respository = "https://github.com/altamodatech/pta-parser"

cli/Cargo.toml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Copyright (C) 2023, AltaModa Technologies, LLC. All rights reserved.
2+
#
3+
# This project is licensed under the terms of the MIT license (cf. LICENSE file in root).
4+
5+
[package]
6+
name = "cli"
7+
version.workspace = true
8+
authors.workspace = true
9+
# respository.workspace = true
10+
edition.workspace = true
11+
12+
13+
[dependencies]
14+
log = "0.4.21"
15+
pest = "2.7.3"
16+
pretty_env_logger = "0.5.0"
17+
pta-ledger = { path = "../pta-ledger" }
18+
pta-parser = { path = "../pta-parser" }
19+
pta-types = { path = "../pta-types" }

cli/src/main.rs

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// Copyright (C) 2023, AltaModa Technologies, LLC. All rights reserved.
2+
//
3+
// This project is licensed under the terms of the MIT license (cf. LICENSE file in root).
4+
//
5+
6+
extern crate pta_ledger;
7+
extern crate pta_parser;
8+
9+
10+
use log::{info, warn, error};
11+
12+
// TODO: how to isolate pest so clients can just use lib (w/o requiring pest as here)
13+
use pta_ledger::ledger_builder::LedgerBuilder;
14+
15+
16+
17+
fn main() -> Result<(), Box<dyn std::error::Error>> {
18+
// TODO: CLI improvements
19+
// - exec with path of file to parse
20+
// - optionally output parse results (should be equivalent to input file)
21+
22+
// TODO: consider flag to use init_timed to include time per line
23+
pretty_env_logger::init();
24+
25+
let pb = std::env::current_dir()?;
26+
let p = pb.join("testdata/basic-ledger");
27+
28+
info!("Input file: {:?}", p);
29+
30+
let mut bldr = LedgerBuilder::default();
31+
match std::fs::read_to_string(p) {
32+
Ok(ledger) => {
33+
info!("String length from input: {}", ledger.len());
34+
match bldr.from_string(&ledger) {
35+
Ok(_parsed) => {
36+
info!("Successfully parsed into ParsedLedger");
37+
return Ok(());
38+
},
39+
40+
Err(e) => {
41+
error!("LedgerBuilder failed with {:}", e);
42+
return Err(e);
43+
}
44+
}
45+
}
46+
47+
Err(e) => {
48+
warn!("failed to read file as string; {e}");
49+
return Err(Box::new(e));
50+
}
51+
}
52+
53+
}
54+
55+
56+
57+
#[cfg(test)]
58+
mod cli_tests {
59+
60+
use pta_parser::parsers::generic::Parser;
61+
62+
#[test]
63+
fn can_create_parser() {
64+
// simply verifies that the parser can be instantiated, ensuring accessibility
65+
let _ = Parser{};
66+
}
67+
}

journal.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Plain-Text Accounting Parser
2+
3+
## History
4+
5+
### 10/18/2023
6+
7+
Abandonded effort to integrate [pest_consume](https://lib.rs/crates/pest_consume) since the author is no longer maintaining it.

pta-ledger/Cargo.toml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Copyright (C) 2023, AltaModa Technologies, LLC. All rights reserved.
2+
#
3+
# This project is licensed under the terms of the MIT license (cf. LICENSE file in root).
4+
5+
[package]
6+
name = "pta-ledger"
7+
version.workspace = true
8+
authors.workspace = true
9+
# respository.workspace = true
10+
edition.workspace = true
11+
12+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
13+
[lib]
14+
bench = false
15+
16+
[dependencies]
17+
log = { version = "0.4.20", features = ["kv_unstable", "kv_unstable_serde"] }
18+
pest = "2.7.3"
19+
pest_derive = "2.7.3"
20+
pta-parser = { path = "../pta-parser" }
21+
pta-types ={ path = "../pta-types" }
22+
23+
[dev-dependencies]
24+
rstest = "0.19.0"

0 commit comments

Comments
 (0)