Skip to content

Commit

Permalink
Improve currency regex for lexer to avoid stealing numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
tesujimath committed Feb 5, 2024
1 parent 99c2552 commit 45e15db
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions beancount-parser-lima/examples/data/full.beancount
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ pushmeta price: "expensive"

2012-01-09 * "VISA DDA PUR 444500 WHOLEFDS -- VISA DDA PUR 444500 WHOLEFDS HOU 10236 NEW YORK * NY"

; Martin
2013-01-01 * "Buy CRA shares" ^old-transactions-008
Assets:CA:RBC-Investing:Taxable-CAD:Cash -1395.43 CAD @ 1/1.4576 USD

2023-05-29 * "New World Gardens North East Va ;" ^newworld.co.nz
Assets:Bank:Current -30 -9.65 NZD
ofxid: "0.12-3456-1234567-01.29May2023.1" ; from ledger-autosync
Expand Down
2 changes: 1 addition & 1 deletion beancount-parser-lima/src/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use time::{Date, Month, Time};
#[logos(error = LexerError, skip r"[ \t]+")]
#[logos(subpattern ignored_whole_line= r"([*:!&#?%][^\n]*\n)")] // rolled into end-of-line handling below
#[logos(subpattern comment_to_eol= r"(;[^\n]*)")] // rolled into end-of-line handling below
#[logos(subpattern currency = r"[A-Z][A-Z0-9'\._-]*|/[A-Z0-9'\._-]+")] // not all matches are valid so we lean on the validation provided by try_from
#[logos(subpattern currency = r"[A-Z][A-Z0-9'\._-]*|/[0-9'\._-]*[A-Z][A-Z0-9'\._-]*")]
#[logos(subpattern date = r"\d{4}[\-/]\d{2}[\-/]\d{2}")]
#[logos(subpattern time = r"\d{1,2}:\d{2}(:\d{2})?")]
#[logos(subpattern account_type = r"[\p{Lu}\p{Lo}][\p{L}\p{N}\-]*")]
Expand Down

0 comments on commit 45e15db

Please sign in to comment.