|
@@ -8,39 +8,6 @@ use chumsky::{prelude::*, text::inline_whitespace};
|
|
|
|
|
|
type InputWithContext<'a> = chumsky::input::WithContext<Span, &'a str>;
|
|
|
|
|
|
-/*
|
|
|
-#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
|
|
|
-struct InputWrap<'a>(SourceFile, &'a str);
|
|
|
-
|
|
|
-impl<'a> chumsky::input::Input<'a> for InputWrap<'a> {
|
|
|
- type Token = char;
|
|
|
- type Span = Span;
|
|
|
- type Cache = ();
|
|
|
- type Cursor = usize;
|
|
|
- type MaybeToken = char;
|
|
|
-
|
|
|
- fn begin(self) -> (Self::Cursor, Self::Cache) {
|
|
|
- (0, ())
|
|
|
- }
|
|
|
-
|
|
|
- fn cursor_location(cursor: &Self::Cursor) -> usize {
|
|
|
- *cursor
|
|
|
- }
|
|
|
-
|
|
|
- unsafe fn span(_cache: &mut Self::Cache, range: std::ops::Range<&Self::Cursor>) -> Self::Span {
|
|
|
- let e : &[u8] = &[];
|
|
|
- Span::new(stringstore::StoredOsString::from(e), (*range.start..*range.end))
|
|
|
- }
|
|
|
-
|
|
|
- unsafe fn next_maybe(
|
|
|
- cache: &mut Self::Cache,
|
|
|
- cursor: &mut Self::Cursor,
|
|
|
- ) -> Option<Self::MaybeToken> {
|
|
|
- None
|
|
|
- }
|
|
|
-}
|
|
|
-*/
|
|
|
-
|
|
|
fn ledger_parser<'a>() -> impl Parser<
|
|
|
'a,
|
|
|
InputWithContext<'a>,
|
|
@@ -71,7 +38,7 @@ fn ledger_parser<'a>() -> impl Parser<
|
|
|
.try_map(|s: &str, span| {
|
|
|
Ok(Spanned::new(
|
|
|
Decimal::from_str_exact(s.trim()).map_err(|e| {
|
|
|
- Rich::custom(span, format!("Failed to parse '{s}' as a decimal number"))
|
|
|
+ Rich::custom(span, format!("Failed to parse '{s}' as a decimal number: {e}"))
|
|
|
})?,
|
|
|
span,
|
|
|
))
|
|
@@ -79,7 +46,7 @@ fn ledger_parser<'a>() -> impl Parser<
|
|
|
|
|
|
let balance = group((
|
|
|
mark('-'),
|
|
|
- none_of(": \n\t").repeated().to_slice().map_with(|v, e| Spanned(stringstore::StoredString::new(v), e.span())),
|
|
|
+ none_of(": \n\t").repeated().to_slice().map_with(|v, e| Spanned(AccountName::new(v), e.span())),
|
|
|
mark(':'),
|
|
|
decimal,
|
|
|
choice((
|
|
@@ -113,15 +80,8 @@ fn ledger_parser<'a>() -> impl Parser<
|
|
|
unit1
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
};
|
|
|
|
|
|
- /*let unit = match unit {
|
|
|
- Some(sunit) => sunit,
|
|
|
- None => acc_spec.default_unit.map(|u| Spanned(u, span)).ok_or_else(||
|
|
|
- chumsky::error::Rich::custom(span, format!("No unit specified and no default unit specified for account '{}'", acc.as_ref())))?
|
|
|
- };*/
|
|
|
-
|
|
|
if !spec.units.contains_key(&unit) {
|
|
|
return Err(chumsky::error::Rich::custom(unit.span(), format!("no such unit '{unit}' found")))
|
|
|
}
|