Skip to main content

Crate rustledger_parser

Crate rustledger_parser 

Source
Expand description

Beancount parser built on a Logos lexer + structured CST.

parse tokenizes via logos_lexer, constructs a lossless CST through parse_structured, and walks it via the converter in cst::convert to produce a ParseResult with the typed AST plus errors, options, includes, plugins, comments, and currency occurrences.

§Features

  • Full Beancount syntax support (all 12 directive types)
  • Error recovery (continues parsing after errors)
  • Precise source locations for error reporting
  • Support for includes, options, plugins

§Example

use rustledger_parser::parse;

let source = r#"
2024-01-15 * "Coffee Shop" "Morning coffee"
  Expenses:Food:Coffee  5.00 USD
  Assets:Cash
"#;

let result = parse(source);
assert!(result.errors.is_empty());
assert_eq!(result.directives.len(), 1);

Re-exports§

pub use cst::BeancountLanguage;
pub use cst::SyntaxElement;
pub use cst::SyntaxKind;
pub use cst::SyntaxNode;
pub use cst::SyntaxToken;
pub use cst::lossless_kind_tokens;
pub use cst::parse_flat;
pub use cst::parse_structured;
pub use cst::parse_via_cst;

Modules§

bom
Canonical UTF-8 BOM handling — single source of truth.
cst
Lossless concrete syntax tree (CST) for Beancount.
format
Opinionated CST-backed formatter entries.
logos_lexer
SIMD-accelerated lexer using Logos.

Structs§

InternedStr
An interned string reference.
ParseError
A parse error with location information.
ParseResult
Result of parsing a beancount file.
ParseWarning
A warning from the parser (non-fatal).
Span
A span in the source code, represented as a byte range.
Spanned
A value with an associated source location (span and file).
TextRange
A range in text, represented as a pair of TextSize.
TextSize
A measure of text length. Also, equivalently, an index into text.

Enums§

Direction
NodeOrToken
ParseErrorKind
Kinds of parse errors.
TokenAtOffset
There might be zero, one or two leaves at a given offset.
WalkEvent
WalkEvent describes tree walking process.

Constants§

SYNTHESIZED_FILE_ID
Sentinel file_id indicating a directive was synthesized by a plugin rather than parsed from a source file.

Functions§

parse
Parse beancount source code.
parse_directives
Parse beancount source code, returning only directives and errors.