Skip to content

Commit a4bcb98

Browse files
authored
Parse empty payee/narration as None (#34)
Fixes #33
1 parent 9398f18 commit a4bcb98

25 files changed

+21
-44
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "beancount-parser-lima"
3-
version = "0.11.1"
3+
version = "0.11.2"
44
edition = "2021"
55
license = "MIT OR Apache-2.0"
66
description = "A zero-copy parser for Beancount"

src/parsers.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,12 +219,31 @@ where
219219
// a single string is narration
220220
(Some(s1), None) => (None, Some(s1)),
221221
(s1, s2) => (s1, s2),
222+
})
223+
.map(|(payee, narration)| {
224+
(
225+
replace_some_empty_with_none(payee),
226+
replace_some_empty_with_none(narration),
227+
)
222228
}),
223229
tags_links(),
224230
))
225231
.then_ignore(just(Token::Eol))
226232
}
227233

234+
fn replace_some_empty_with_none(s: Option<Spanned<&str>>) -> Option<Spanned<&str>> {
235+
match s {
236+
Some(maybe_empty) => {
237+
if maybe_empty.is_empty() {
238+
None
239+
} else {
240+
s
241+
}
242+
}
243+
None => None,
244+
}
245+
}
246+
228247
/// Matches a price directive, including metadata, over several lines.
229248
pub(crate) fn price<'s, I>() -> impl Parser<'s, I, Directive<'s>, Extra<'s>>
230249
where

test-cases/Balance.TotalCost.txtpb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ directives {
22
date { year: 2013 month: 5 day: 18 }
33
transaction {
44
flag: "*"
5-
# ANOMALY: Lima distinguishes empty string from no string
6-
narration: ""
75
postings {
86
account: "Assets:Investments:MSFT"
97
spec {
@@ -23,8 +21,6 @@ directives {
2321
date { year: 2013 month: 5 day: 18 }
2422
transaction {
2523
flag: "*"
26-
# ANOMALY: Lima distinguishes empty string from no string
27-
narration: ""
2824
postings {
2925
account: "Assets:Investments:MSFT"
3026
spec {

test-cases/Balance.TotalPrice.txtpb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ directives {
22
date { year: 2013 month: 5 day: 18 }
33
transaction {
44
flag: "*"
5-
# ANOMALY: Lima distinguishes empty string from no string
6-
narration: ""
75
postings {
86
account: "Assets:Investments:MSFT"
97
spec {

test-cases/MetaData.MetadataDataTypes.txtpb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ directives {
1212
kv { key: "boolf" value { boolean: false } }
1313
}
1414
transaction {
15-
# ANOMALY: Lima distinguishes empty string from no string
16-
narration: ""
1715
flag: "*"
1816
}
1917
}

test-cases/MetaData.MetadataKeySyntax.txtpb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ directives {
77
kv { key: "name_on_card" value { text: "John" } }
88
}
99
transaction {
10-
# ANOMALY: Lima distinguishes empty string from no string
11-
narration: ""
1210
flag: "*"
1311
}
1412
}

test-cases/MetaData.MetadataTransactionBegin.txtpb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ directives {
44
kv { key: "test" value { text: "Something" } }
55
}
66
transaction {
7-
# ANOMALY: Lima distinguishes empty string from no string
8-
narration: ""
97
flag: "*"
108
postings {
119
account: "Assets:Investments:MSFT"

test-cases/MetaData.MetadataTransactionEnd.txtpb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
directives {
22
date { year: 2013 month: 5 day: 18 }
33
transaction {
4-
# ANOMALY: Lima distinguishes empty string from no string
5-
narration: ""
64
flag: "*"
75
postings {
86
account: "Assets:Investments:MSFT"

test-cases/MetaData.MetadataTransactionIndented.txtpb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ directives {
66
kv { key: "test1" value { text: "Something" } }
77
}
88
transaction {
9-
# ANOMALY: Lima distinguishes empty string from no string
10-
narration: ""
119
flag: "*"
1210
postings {
1311
account: "Assets:Investments:MSFT"

0 commit comments

Comments
 (0)