From 96bf3026173be48d13dc8e58670da3abe25a953d Mon Sep 17 00:00:00 2001 From: Kilerd Chan Date: Fri, 18 Oct 2024 15:21:51 +0800 Subject: [PATCH 1/4] test: add testcase for ledger syntax Signed-off-by: Kilerd Chan --- .../comments-between-postings/main.bean | 27 +++++++++++++++++++ .../comments-between-postings/main.zhang | 27 +++++++++++++++++++ .../validations.json | 23 ++++++++++++++++ .../inconsitent-indent-for-postings/main.bean | 11 ++++++++ .../main.zhang | 11 ++++++++ .../validations.json | 11 ++++++++ .../main.bean | 10 +++++++ .../main.zhang | 10 +++++++ .../validations.json | 11 ++++++++ 9 files changed, 141 insertions(+) create mode 100644 integration-tests/comments-between-postings/main.bean create mode 100644 integration-tests/comments-between-postings/main.zhang create mode 100644 integration-tests/comments-between-postings/validations.json create mode 100644 integration-tests/inconsitent-indent-for-postings/main.bean create mode 100644 integration-tests/inconsitent-indent-for-postings/main.zhang create mode 100644 integration-tests/inconsitent-indent-for-postings/validations.json create mode 100644 integration-tests/space-of-posting-uint-can-be-empty/main.bean create mode 100644 integration-tests/space-of-posting-uint-can-be-empty/main.zhang create mode 100644 integration-tests/space-of-posting-uint-can-be-empty/validations.json diff --git a/integration-tests/comments-between-postings/main.bean b/integration-tests/comments-between-postings/main.bean new file mode 100644 index 00000000..a3b3a68a --- /dev/null +++ b/integration-tests/comments-between-postings/main.bean @@ -0,0 +1,27 @@ +option "operating_currency" "CNY" + +1970-01-01 open Assets:BankCard CNY + +1970-01-01 open Expenses:Food CNY + +2023-12-06 "KFC" "VME50 Package" + ; comment here + Assets:BankCard -50 CNY + Expenses:Food + +2023-12-06 "KFC" "VME50 Package" + Assets:BankCard -50 CNY + ; comment here + Expenses:Food + ; comment here + +2023-12-06 "KFC" "VME50 Package" + Assets:BankCard -50 CNY + Expenses:Food + ; comment here + +2023-12-06 "KFC" "VME50 Package" + Assets:BankCard -50 CNY + Expenses:Food + ; comment here + ; comment here \ No newline at end of file diff --git a/integration-tests/comments-between-postings/main.zhang b/integration-tests/comments-between-postings/main.zhang new file mode 100644 index 00000000..a3b3a68a --- /dev/null +++ b/integration-tests/comments-between-postings/main.zhang @@ -0,0 +1,27 @@ +option "operating_currency" "CNY" + +1970-01-01 open Assets:BankCard CNY + +1970-01-01 open Expenses:Food CNY + +2023-12-06 "KFC" "VME50 Package" + ; comment here + Assets:BankCard -50 CNY + Expenses:Food + +2023-12-06 "KFC" "VME50 Package" + Assets:BankCard -50 CNY + ; comment here + Expenses:Food + ; comment here + +2023-12-06 "KFC" "VME50 Package" + Assets:BankCard -50 CNY + Expenses:Food + ; comment here + +2023-12-06 "KFC" "VME50 Package" + Assets:BankCard -50 CNY + Expenses:Food + ; comment here + ; comment here \ No newline at end of file diff --git a/integration-tests/comments-between-postings/validations.json b/integration-tests/comments-between-postings/validations.json new file mode 100644 index 00000000..baa801c4 --- /dev/null +++ b/integration-tests/comments-between-postings/validations.json @@ -0,0 +1,23 @@ +[ + { + "uri": "/api/journals", + "validations": [ + [ + "$.data.records[0].postings.length()", + 2 + ], + [ + "$.data.records[1].postings.length()", + 2 + ], + [ + "$.data.records[2].postings.length()", + 2 + ], + [ + "$.data.records[3].postings.length()", + 2 + ] + ] + } +] \ No newline at end of file diff --git a/integration-tests/inconsitent-indent-for-postings/main.bean b/integration-tests/inconsitent-indent-for-postings/main.bean new file mode 100644 index 00000000..4898547a --- /dev/null +++ b/integration-tests/inconsitent-indent-for-postings/main.bean @@ -0,0 +1,11 @@ +option "operating_currency" "CNY" + +1970-01-01 open Assets:BankCard CNY + +1970-01-01 open Expenses:Food CNY + +2023-12-06 "KFC" "VME50 Package" + Expenses:A -0.0CNY + Expenses:Food + Expenses:Fo + Expenses:A -0.0CNY \ No newline at end of file diff --git a/integration-tests/inconsitent-indent-for-postings/main.zhang b/integration-tests/inconsitent-indent-for-postings/main.zhang new file mode 100644 index 00000000..4898547a --- /dev/null +++ b/integration-tests/inconsitent-indent-for-postings/main.zhang @@ -0,0 +1,11 @@ +option "operating_currency" "CNY" + +1970-01-01 open Assets:BankCard CNY + +1970-01-01 open Expenses:Food CNY + +2023-12-06 "KFC" "VME50 Package" + Expenses:A -0.0CNY + Expenses:Food + Expenses:Fo + Expenses:A -0.0CNY \ No newline at end of file diff --git a/integration-tests/inconsitent-indent-for-postings/validations.json b/integration-tests/inconsitent-indent-for-postings/validations.json new file mode 100644 index 00000000..43407455 --- /dev/null +++ b/integration-tests/inconsitent-indent-for-postings/validations.json @@ -0,0 +1,11 @@ +[ + { + "uri": "/api/journals", + "validations": [ + [ + "$.data.records[0].postings.length()", + 4 + ] + ] + } +] \ No newline at end of file diff --git a/integration-tests/space-of-posting-uint-can-be-empty/main.bean b/integration-tests/space-of-posting-uint-can-be-empty/main.bean new file mode 100644 index 00000000..c36c20ee --- /dev/null +++ b/integration-tests/space-of-posting-uint-can-be-empty/main.bean @@ -0,0 +1,10 @@ +option "operating_currency" "CNY" + +1970-01-01 open Assets:BankCard CNY + +1970-01-01 open Expenses:Food CNY + +2023-12-06 "KFC" "VME50 Package" + Expenses:A -0.0CNY + Expenses:Food -0.0CNY@1USD + Expenses:Food -0.0CNY@@1USD diff --git a/integration-tests/space-of-posting-uint-can-be-empty/main.zhang b/integration-tests/space-of-posting-uint-can-be-empty/main.zhang new file mode 100644 index 00000000..c36c20ee --- /dev/null +++ b/integration-tests/space-of-posting-uint-can-be-empty/main.zhang @@ -0,0 +1,10 @@ +option "operating_currency" "CNY" + +1970-01-01 open Assets:BankCard CNY + +1970-01-01 open Expenses:Food CNY + +2023-12-06 "KFC" "VME50 Package" + Expenses:A -0.0CNY + Expenses:Food -0.0CNY@1USD + Expenses:Food -0.0CNY@@1USD diff --git a/integration-tests/space-of-posting-uint-can-be-empty/validations.json b/integration-tests/space-of-posting-uint-can-be-empty/validations.json new file mode 100644 index 00000000..fca2b05b --- /dev/null +++ b/integration-tests/space-of-posting-uint-can-be-empty/validations.json @@ -0,0 +1,11 @@ +[ + { + "uri": "/api/journals", + "validations": [ + [ + "$.data.records[0].postings.length()", + 3 + ] + ] + } +] \ No newline at end of file From fd222f30d47e76bec622ade053390a81c10b4991 Mon Sep 17 00:00:00 2001 From: Kilerd Chan Date: Fri, 18 Oct 2024 16:36:05 +0800 Subject: [PATCH 2/4] feat: support inconsistent space and optional space for posting Signed-off-by: Kilerd Chan --- extensions/beancount/src/beancount.pest | 31 ++++++++---------- extensions/beancount/src/parser.rs | 30 ++++------------- .../inconsitent-indent-for-postings/main.bean | 10 +++--- .../main.zhang | 10 +++--- .../main.bean | 6 ++-- .../main.zhang | 6 ++-- zhang-ast/src/data.rs | 1 - zhang-core/src/data_type/text/exporter.rs | 15 ++++----- zhang-core/src/data_type/text/parser.rs | 29 ++++------------- zhang-core/src/data_type/text/zhang.pest | 32 +++++++++---------- zhang-core/src/process/balance.rs | 3 -- zhang-server/src/routes/transaction.rs | 2 -- 12 files changed, 63 insertions(+), 112 deletions(-) diff --git a/extensions/beancount/src/beancount.pest b/extensions/beancount/src/beancount.pest index 41a99b98..ec93b049 100644 --- a/extensions/beancount/src/beancount.pest +++ b/extensions/beancount/src/beancount.pest @@ -33,7 +33,7 @@ valuable_comment = { space* ~ comment_prefix ~ space* ~ comment_value } comment_prefix = { ";" | "*" | "#" | "//" } comment_value = { (!line ~ ANY)* } -transaction = { date ~ transaction_flag? ~ (space+ ~ quote_string){0, 2} ~ tags_or_links? ~ space* ~ comment? ~ transaction_detail } +transaction = { date ~ transaction_flag? ~ (space+ ~ quote_string){0, 2} ~ tags_or_links? ~ space* ~ comment? ~ transaction_lines } transaction_flag = { space+ ~ ("!" | "*" | "#" | ASCII_ALPHA_UPPER) } @@ -41,38 +41,35 @@ tags_or_links = { (space* ~ (tag | link))* } tag = { "#" ~ unquote_string } link = { "^" ~ unquote_string } -transaction_detail = _{ indentation_push ~ transaction_lines ~ DROP } -transaction_lines = { transaction_line ~ (transaction_next_line)* } -transaction_line = { (transaction_posting | key_value_line) ~ space* ~ valuable_comment? } -transaction_posting = { transaction_flag? ~ account_name ~ (space+ ~ posting_unit)? ~ metas? } -transaction_next_line = _{ indentation ~ transaction_line } +transaction_lines = { transaction_line+} +transaction_line = { indentation ~ (transaction_posting | key_value_line)? ~ space* ~ valuable_comment? } +transaction_posting = { transaction_flag? ~ account_name ~ (space+ ~ posting_unit)? } posting_unit = { (posting_amount)? ~ posting_meta } -posting_amount = { number_expr ~ space+ ~ commodity_name } -posting_meta = { (space+ ~ posting_cost_prefix ~ space* ~ posting_cost? ~ price_cost_date? ~ space* ~ posting_cost_postfix)? ~ space* ~ posting_price? } +posting_amount = { number_expr ~ space* ~ commodity_name } +posting_meta = { (space* ~ posting_cost_prefix ~ space* ~ posting_cost? ~ price_cost_date? ~ space* ~ posting_cost_postfix)? ~ space* ~ posting_price? } + posting_cost_prefix = { "{" } posting_cost_postfix = { "}" } -posting_cost = { number_expr ~ space+ ~ commodity_name } +posting_cost = { number_expr ~ space* ~ commodity_name } price_cost_date = _{ space* ~ "," ~ space* ~ date } posting_price = { posting_single_price | posting_total_price } -posting_single_price = { "@" ~ space+ ~ number_expr ~ space+ ~ commodity_name } -posting_total_price = { "@@" ~ space+ ~ number_expr ~ space+ ~ commodity_name } +posting_single_price = { "@" ~ space* ~ number_expr ~ space* ~ commodity_name } +posting_total_price = { "@@" ~ space* ~ number_expr ~ space* ~ commodity_name } string_or_account = { account_name | string } -metas = { indentation_push ~ key_value_lines ~ DROP } +metas = { key_value_lines } booking_method = { "\"" ~ ("STRICT" | "FIFO" | "LIFO" | "AVERAGE" | "AVERAGE_ONLY" | "NONE") ~ "\"" } -indentation = _{ line ~ PEEK_ALL } -indentation_push = _{ indentation ~ PUSH(space+) } +indentation = _{ line ~ space+ } -key_value_lines = _{ key_value_line_with_comment ~ (key_value_next_line)* } -key_value_next_line = _{ indentation ~ key_value_line_with_comment } +key_value_lines = _{ (line ~ space+ ~ key_value_line_with_comment)+ } +key_value_line_with_comment = _{ key_value_line ~ space* ~ comment? } key_value_line = { string ~ space* ~ ":" ~ space* ~ string } -key_value_line_with_comment = _{ key_value_line ~ space* ~ comment? } date = { date_only } date_only = { ASCII_DIGIT{4} ~ "-" ~ ASCII_DIGIT{1, 2} ~ "-" ~ ASCII_DIGIT{1, 2} } diff --git a/extensions/beancount/src/parser.rs b/extensions/beancount/src/parser.rs index 4fec398e..b79fc93a 100644 --- a/extensions/beancount/src/parser.rs +++ b/extensions/beancount/src/parser.rs @@ -274,20 +274,14 @@ impl BeancountParser { Option, Account, Option<(Option, Option<(Option, Option)>)>, - Meta, ) = match_nodes!(input.into_children(); - [account_name(account_name)] => (None, account_name, None, Meta::default()), - [account_name(account_name), posting_unit(unit)] => (None, account_name, Some(unit), Meta::default()), - [transaction_flag(flag), account_name(account_name)] => (flag, account_name, None, Meta::default()), - [transaction_flag(flag), account_name(account_name), posting_unit(unit)] => (flag, account_name, Some(unit), Meta::default()), - - [account_name(account_name), metas(meta)] => (None, account_name, None, meta), - [account_name(account_name), posting_unit(unit), metas(meta)] => (None, account_name, Some(unit), meta), - [transaction_flag(flag), account_name(account_name), metas(meta)] => (flag, account_name, None, meta), - [transaction_flag(flag), account_name(account_name), posting_unit(unit), metas(meta)] => (flag, account_name, Some(unit), meta), + [account_name(account_name)] => (None, account_name, None), + [account_name(account_name), posting_unit(unit)] => (None, account_name, Some(unit)), + [transaction_flag(flag), account_name(account_name)] => (flag, account_name, None), + [transaction_flag(flag), account_name(account_name), posting_unit(unit)] => (flag, account_name, Some(unit)), ); - let (flag, account, unit, meta) = ret; + let (flag, account, unit) = ret; let mut line = Posting { flag, @@ -296,7 +290,6 @@ impl BeancountParser { cost: None, price: None, comment: None, - meta, }; if let Some((amount, meta)) = unit { @@ -316,7 +309,7 @@ impl BeancountParser { [transaction_posting(posting), valuable_comment(c)] => (Some(posting.set_comment(c)), None), [key_value_line(meta)] => (None, Some(meta)), [key_value_line(meta), valuable_comment(_)] => (None, Some(meta)), - + [valuable_comment(_)] => (None, None), ); Ok(ret) } @@ -763,16 +756,6 @@ mod test { use crate::parser::test::get_txn; - #[test] - fn should_parse_posting_meta() { - let directive = get_txn(indoc! {r#" - 1970-01-01 "Payee" "Narration" - Assets:Bank - a: b - "#}); - assert_eq!(directive.postings.first().unwrap().meta.get_one("a").cloned().unwrap().to_plain_string(), "b"); - } - #[test] fn should_parse_with_comment() { let directive = get_txn(indoc! {r#" @@ -783,7 +766,6 @@ mod test { a: b b: c ;123123 "#}); - assert_eq!(directive.postings.first().unwrap().meta.get_one("a").cloned().unwrap().to_plain_string(), "b"); assert_eq!(directive.postings.get(1).unwrap().comment.as_ref().unwrap(), "123213"); } diff --git a/integration-tests/inconsitent-indent-for-postings/main.bean b/integration-tests/inconsitent-indent-for-postings/main.bean index 4898547a..b102f8b9 100644 --- a/integration-tests/inconsitent-indent-for-postings/main.bean +++ b/integration-tests/inconsitent-indent-for-postings/main.bean @@ -4,8 +4,8 @@ option "operating_currency" "CNY" 1970-01-01 open Expenses:Food CNY -2023-12-06 "KFC" "VME50 Package" - Expenses:A -0.0CNY - Expenses:Food - Expenses:Fo - Expenses:A -0.0CNY \ No newline at end of file +2023-12-06 * "KFC" "VME50 Package" + Expenses:Food -0.1CNY + Assets:BankCard 0.1 CNY + Assets:BankCard + Expenses:Food -0.1CNY \ No newline at end of file diff --git a/integration-tests/inconsitent-indent-for-postings/main.zhang b/integration-tests/inconsitent-indent-for-postings/main.zhang index 4898547a..b102f8b9 100644 --- a/integration-tests/inconsitent-indent-for-postings/main.zhang +++ b/integration-tests/inconsitent-indent-for-postings/main.zhang @@ -4,8 +4,8 @@ option "operating_currency" "CNY" 1970-01-01 open Expenses:Food CNY -2023-12-06 "KFC" "VME50 Package" - Expenses:A -0.0CNY - Expenses:Food - Expenses:Fo - Expenses:A -0.0CNY \ No newline at end of file +2023-12-06 * "KFC" "VME50 Package" + Expenses:Food -0.1CNY + Assets:BankCard 0.1 CNY + Assets:BankCard + Expenses:Food -0.1CNY \ No newline at end of file diff --git a/integration-tests/space-of-posting-uint-can-be-empty/main.bean b/integration-tests/space-of-posting-uint-can-be-empty/main.bean index c36c20ee..a2e2acb5 100644 --- a/integration-tests/space-of-posting-uint-can-be-empty/main.bean +++ b/integration-tests/space-of-posting-uint-can-be-empty/main.bean @@ -5,6 +5,6 @@ option "operating_currency" "CNY" 1970-01-01 open Expenses:Food CNY 2023-12-06 "KFC" "VME50 Package" - Expenses:A -0.0CNY - Expenses:Food -0.0CNY@1USD - Expenses:Food -0.0CNY@@1USD + Expenses:A -0.1CNY + Expenses:Food -0.1CNY@1USD + Expenses:Food -0.1CNY@@1USD diff --git a/integration-tests/space-of-posting-uint-can-be-empty/main.zhang b/integration-tests/space-of-posting-uint-can-be-empty/main.zhang index c36c20ee..a2e2acb5 100644 --- a/integration-tests/space-of-posting-uint-can-be-empty/main.zhang +++ b/integration-tests/space-of-posting-uint-can-be-empty/main.zhang @@ -5,6 +5,6 @@ option "operating_currency" "CNY" 1970-01-01 open Expenses:Food CNY 2023-12-06 "KFC" "VME50 Package" - Expenses:A -0.0CNY - Expenses:Food -0.0CNY@1USD - Expenses:Food -0.0CNY@@1USD + Expenses:A -0.1CNY + Expenses:Food -0.1CNY@1USD + Expenses:Food -0.1CNY@@1USD diff --git a/zhang-ast/src/data.rs b/zhang-ast/src/data.rs index 554210fc..f6da46c7 100644 --- a/zhang-ast/src/data.rs +++ b/zhang-ast/src/data.rs @@ -100,7 +100,6 @@ pub struct Posting { pub cost: Option, pub price: Option, pub comment: Option, - pub meta: Meta, } impl Posting { pub fn set_comment(mut self, comment: String) -> Self { diff --git a/zhang-core/src/data_type/text/exporter.rs b/zhang-core/src/data_type/text/exporter.rs index 932c8ca5..9c887105 100644 --- a/zhang-core/src/data_type/text/exporter.rs +++ b/zhang-core/src/data_type/text/exporter.rs @@ -95,7 +95,7 @@ impl ZhangDataTypeExportable for Transaction { let mut transaction = self .postings .into_iter() - .flat_map(|posting| posting.export()) + .map(|posting| posting.export()) .map(|it| format!(" {}", it)) .collect_vec(); transaction.insert(0, header.into_iter().flatten().join(" ")); @@ -107,8 +107,8 @@ impl ZhangDataTypeExportable for Transaction { } impl ZhangDataTypeExportable for Posting { - type Output = Vec; - fn export(self) -> Vec { + type Output = String; + fn export(self) -> String { // todo cost and price let cost_string = self.cost.map(|it| it.export()); let vec1 = vec![ @@ -118,10 +118,7 @@ impl ZhangDataTypeExportable for Posting { cost_string, self.price.map(|it| it.export()), ]; - let mut ret = self.meta.export().into_iter().map(|it| format!(" {}", it)).collect_vec(); - ret.insert(0, vec1.into_iter().flatten().join(" ")); - - ret + vec1.into_iter().flatten().join(" ") } } @@ -540,12 +537,12 @@ mod test { ); assert_parse!( - "transaction posting with meta", + "transaction posting and meta", indoc! {r#" 1970-01-01 * "Payee" "Narration" ^link1 ^link-2 Assets:123 -1 CNY - a: b Expenses:TestCategory:One 1 CCC @@ 1 CNY + a: b "#} ); } diff --git a/zhang-core/src/data_type/text/parser.rs b/zhang-core/src/data_type/text/parser.rs index 5da5593c..b20e578b 100644 --- a/zhang-core/src/data_type/text/parser.rs +++ b/zhang-core/src/data_type/text/parser.rs @@ -283,20 +283,14 @@ impl ZhangParser { Option, Account, Option<(Option, Option<(Option, Option)>)>, - Meta, ) = match_nodes!(input.into_children(); - [account_name(account_name)] => (None, account_name, None, Meta::default()), - [account_name(account_name), posting_unit(unit)] => (None, account_name, Some(unit), Meta::default()), - [transaction_flag(flag), account_name(account_name)] => (flag, account_name, None, Meta::default()), - [transaction_flag(flag), account_name(account_name), posting_unit(unit)] => (flag, account_name, Some(unit), Meta::default()), - - [account_name(account_name), metas(meta)] => (None, account_name, None, meta), - [account_name(account_name), posting_unit(unit), metas(meta)] => (None, account_name, Some(unit), meta), - [transaction_flag(flag), account_name(account_name), metas(meta)] => (flag, account_name, None, meta), - [transaction_flag(flag), account_name(account_name), posting_unit(unit), metas(meta)] => (flag, account_name, Some(unit), meta), + [account_name(account_name)] => (None, account_name, None), + [account_name(account_name), posting_unit(unit)] => (None, account_name, Some(unit)), + [transaction_flag(flag), account_name(account_name)] => (flag, account_name, None), + [transaction_flag(flag), account_name(account_name), posting_unit(unit)] => (flag, account_name, Some(unit)), ); - let (flag, account, unit, meta) = ret; + let (flag, account, unit) = ret; let mut line = Posting { flag, @@ -305,7 +299,6 @@ impl ZhangParser { cost: None, price: None, comment: None, - meta, }; if let Some((amount, meta)) = unit { @@ -325,7 +318,7 @@ impl ZhangParser { [transaction_posting(posting), valuable_comment(comment)] => (Some(posting.set_comment(comment)), None), [key_value_line(meta)] => (None, Some(meta)), [key_value_line(meta), valuable_comment(_)] => (None, Some(meta)), - + [valuable_comment(_)] => (None, None), ); Ok(ret) } @@ -1163,16 +1156,6 @@ mod test { assert_eq!(Some(PostingCost { base: None, date: None }), posting.cost); assert_eq!(Some(SingleTotalPrice::Single(Amount::new(BigDecimal::from(7i32), "CNY"))), posting.price); } - #[test] - fn should_parse_metas_in_posting() { - let mut trx = get_first_posting(indoc! {r#" - 2022-06-02 "balanced transaction" - Assets:Card -100 USD - a: b - "#}); - let posting = trx.postings.pop().unwrap(); - assert_eq!("b", posting.meta.get_one("a").cloned().unwrap().to_plain_string()); - } #[test] fn should_support_comma_char_for_human_readable_number() { diff --git a/zhang-core/src/data_type/text/zhang.pest b/zhang-core/src/data_type/text/zhang.pest index 9ea662d9..847f0b20 100644 --- a/zhang-core/src/data_type/text/zhang.pest +++ b/zhang-core/src/data_type/text/zhang.pest @@ -25,7 +25,7 @@ budget_add = { date ~ space+ ~ "budget-add" ~ space+ ~ unquote_string ~ sp budget_transfer = { date ~ space+ ~ "budget-transfer" ~ space+ ~ unquote_string ~ space+ ~ unquote_string ~ space+ ~ posting_amount ~ metas? } budget_close = { date ~ space+ ~ "budget-close" ~ space+ ~ unquote_string ~ metas? } -transaction = { date ~ transaction_flag? ~ (space+ ~ quote_string){0, 2} ~ tags_or_links? ~ space* ~ comment? ~ transaction_detail } +transaction = { date ~ transaction_flag? ~ (space+ ~ quote_string){0, 2} ~ tags_or_links? ~ space* ~ comment? ~ transaction_lines } comment = _{(";" | "*" | "#" | "//") ~ (!line ~ ANY)* } valuable_comment = { space* ~ comment_prefix ~ space* ~ comment_value } @@ -38,37 +38,35 @@ tags_or_links = { (space* ~ (tag | link))* } tag = { "#" ~ unquote_string } link = { "^" ~ unquote_string } -transaction_detail = _{ indentation_push ~ transaction_lines ~ DROP } -transaction_lines = { transaction_line ~ (transaction_next_line)* } -transaction_line = { (transaction_posting | key_value_line) ~ space* ~ valuable_comment? } -transaction_posting = { transaction_flag? ~ account_name ~ (space+ ~ posting_unit)? ~ metas? } -transaction_next_line = _{ indentation ~ transaction_line } +transaction_lines = { transaction_line+} +transaction_line = { indentation ~ (transaction_posting | key_value_line)? ~ space* ~ valuable_comment? } +transaction_posting = { transaction_flag? ~ account_name ~ (space+ ~ posting_unit)? } + posting_unit = { (posting_amount)? ~ posting_meta } -posting_amount = { number_expr ~ space+ ~ commodity_name } -posting_meta = { (space+ ~ posting_cost_prefix ~ space* ~ posting_cost? ~ price_cost_date? ~ space* ~ posting_cost_postfix)? ~ space* ~ posting_price? } +posting_amount = { number_expr ~ space* ~ commodity_name } +posting_meta = { (space* ~ posting_cost_prefix ~ space* ~ posting_cost? ~ price_cost_date? ~ space* ~ posting_cost_postfix)? ~ space* ~ posting_price? } posting_cost_prefix = { "{" } posting_cost_postfix = { "}" } -posting_cost = { number_expr ~ space+ ~ commodity_name } +posting_cost = { number_expr ~ space* ~ commodity_name } price_cost_date = _{ space* ~ "," ~ space* ~ date } posting_price = { posting_single_price | posting_total_price } -posting_single_price = { "@" ~ space+ ~ number_expr ~ space+ ~ commodity_name } -posting_total_price = { "@@" ~ space+ ~ number_expr ~ space+ ~ commodity_name } +posting_single_price = { "@" ~ space* ~ number_expr ~ space* ~ commodity_name } +posting_total_price = { "@@" ~ space* ~ number_expr ~ space* ~ commodity_name } string_or_account = { account_name | string } -metas = { indentation_push ~ key_value_lines ~ DROP } +metas = { key_value_lines } -indentation = _{ line ~ PEEK_ALL } -indentation_push = _{ indentation ~ PUSH(space+) } -key_value_lines = _{ key_value_line_with_comment ~ (key_value_next_line)* } -key_value_next_line = _{ indentation ~ key_value_line_with_comment } -key_value_line = { string ~ space* ~ ":" ~ space* ~ string } +indentation = _{ line ~ space+ } + +key_value_lines = _{ (line ~ space+ ~ key_value_line_with_comment)+ } key_value_line_with_comment = _{ key_value_line ~ space* ~ comment? } +key_value_line = { string ~ space* ~ ":" ~ space* ~ string } date = { datetime | date_hour | date_only } diff --git a/zhang-core/src/process/balance.rs b/zhang-core/src/process/balance.rs index 86d8ac34..2f86ea65 100644 --- a/zhang-core/src/process/balance.rs +++ b/zhang-core/src/process/balance.rs @@ -47,7 +47,6 @@ impl DirectiveProcess for BalancePad { cost: None, price: None, comment: None, - meta: Default::default(), }, Posting { flag: None, @@ -56,7 +55,6 @@ impl DirectiveProcess for BalancePad { cost: None, price: None, comment: None, - meta: Default::default(), }, ], meta: Default::default(), @@ -109,7 +107,6 @@ impl DirectiveProcess for BalanceCheck { cost: None, price: None, comment: None, - meta: Default::default(), }], meta: Default::default(), }; diff --git a/zhang-server/src/routes/transaction.rs b/zhang-server/src/routes/transaction.rs index a367cbab..6aa17def 100644 --- a/zhang-server/src/routes/transaction.rs +++ b/zhang-server/src/routes/transaction.rs @@ -139,7 +139,6 @@ pub async fn create_new_transaction( cost: None, price: None, comment: None, - meta: Default::default(), }); } @@ -238,7 +237,6 @@ pub async fn update_single_transaction( cost: None, price: None, comment: None, - meta: Default::default(), }); } let mut metas = Meta::default(); From 78ef4fc3f643efa2a21a7a9240254df7973a5692 Mon Sep 17 00:00:00 2001 From: Kilerd Chan Date: Fri, 18 Oct 2024 20:38:23 +0800 Subject: [PATCH 3/4] chore: lock python version Signed-off-by: Kilerd Chan --- .github/workflows/build-latest.yml | 3 +++ .github/workflows/release.yml | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/.github/workflows/build-latest.yml b/.github/workflows/build-latest.yml index ae03ba62..06d3a2f4 100644 --- a/.github/workflows/build-latest.yml +++ b/.github/workflows/build-latest.yml @@ -68,6 +68,9 @@ jobs: - name: fake frontend build run: mkdir -p dist working-directory: ./frontend + - uses: actions/setup-python@v5 + with: + python-version: '3.10' - name: Run test run: cargo test --features ${{matrix.features}} wasm-test: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 68c403c9..e9d4ce67 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -121,6 +121,10 @@ jobs: if: startsWith(matrix.os, 'ubuntu') run: sudo apt install pkg-config libssl-dev + - uses: actions/setup-python@v5 + with: + python-version: '3.10' + - name: cargo build uses: houseabsolute/actions-rust-cross@v0 with: From 0e137082cfe2f164286e68880680e74a62f52bf2 Mon Sep 17 00:00:00 2001 From: Kilerd Chan Date: Fri, 18 Oct 2024 20:52:41 +0800 Subject: [PATCH 4/4] refact: fix the typo of folder Signed-off-by: Kilerd Chan --- .../main.bean | 0 .../main.zhang | 0 .../validations.json | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename integration-tests/{inconsitent-indent-for-postings => inconsistent-indent-for-postings}/main.bean (100%) rename integration-tests/{inconsitent-indent-for-postings => inconsistent-indent-for-postings}/main.zhang (100%) rename integration-tests/{inconsitent-indent-for-postings => inconsistent-indent-for-postings}/validations.json (100%) diff --git a/integration-tests/inconsitent-indent-for-postings/main.bean b/integration-tests/inconsistent-indent-for-postings/main.bean similarity index 100% rename from integration-tests/inconsitent-indent-for-postings/main.bean rename to integration-tests/inconsistent-indent-for-postings/main.bean diff --git a/integration-tests/inconsitent-indent-for-postings/main.zhang b/integration-tests/inconsistent-indent-for-postings/main.zhang similarity index 100% rename from integration-tests/inconsitent-indent-for-postings/main.zhang rename to integration-tests/inconsistent-indent-for-postings/main.zhang diff --git a/integration-tests/inconsitent-indent-for-postings/validations.json b/integration-tests/inconsistent-indent-for-postings/validations.json similarity index 100% rename from integration-tests/inconsitent-indent-for-postings/validations.json rename to integration-tests/inconsistent-indent-for-postings/validations.json