pub struct ParsedLedger { /* private fields */ }Expand description
A parsed and validated single-file ledger with editor features.
Use this class for single-file ledgers where you need completions, hover, go-to-definition, and other editor integration features.
For multi-file ledgers, use Ledger instead.
§Example (JavaScript)
const ledger = new ParsedLedger(source);
if (ledger.isValid()) {
const balances = ledger.query("BALANCES");
const completions = ledger.getCompletions(line, char);
}Implementations§
Source§impl ParsedLedger
impl ParsedLedger
Sourcepub fn new(source: &str) -> Self
pub fn new(source: &str) -> Self
Create a new ParsedLedger from a single source string.
Parses, books, and validates the source. Call isValid() to check for errors.
Sourcepub fn get_errors(&self) -> Result<JsValue, JsError>
pub fn get_errors(&self) -> Result<JsValue, JsError>
Get all errors (parse + validation).
Sourcepub fn get_parse_errors(&self) -> Result<JsValue, JsError>
pub fn get_parse_errors(&self) -> Result<JsValue, JsError>
Get parse errors only.
Sourcepub fn get_validation_errors(&self) -> Result<JsValue, JsError>
pub fn get_validation_errors(&self) -> Result<JsValue, JsError>
Get validation errors only.
Sourcepub fn get_directives(&self) -> Result<JsValue, JsError>
pub fn get_directives(&self) -> Result<JsValue, JsError>
Get the parsed directives.
Sourcepub fn get_options(&self) -> Result<JsValue, JsError>
pub fn get_options(&self) -> Result<JsValue, JsError>
Get the ledger options.
Sourcepub fn directive_count(&self) -> usize
pub fn directive_count(&self) -> usize
Get the number of directives.
Sourcepub fn query(&self, query_str: &str) -> Result<JsValue, JsError>
pub fn query(&self, query_str: &str) -> Result<JsValue, JsError>
Run a BQL query on this ledger.
Sourcepub fn balances(&self) -> Result<JsValue, JsError>
pub fn balances(&self) -> Result<JsValue, JsError>
Get account balances (shorthand for query(“BALANCES”)).
Sourcepub fn format(&self) -> Result<JsValue, JsError>
pub fn format(&self) -> Result<JsValue, JsError>
Format the ledger source.
Reformats the original source preserving comments, blank lines, and non-directive content with file-wide aligned columns.
Sourcepub fn expand_pads(&self) -> Result<JsValue, JsError>
pub fn expand_pads(&self) -> Result<JsValue, JsError>
Expand pad directives.
Sourcepub fn run_plugin(&self, plugin_name: &str) -> Result<JsValue, JsError>
pub fn run_plugin(&self, plugin_name: &str) -> Result<JsValue, JsError>
Run a native plugin on this ledger.
Sourcepub fn get_completions(
&self,
line: u32,
character: u32,
) -> Result<JsValue, JsError>
pub fn get_completions( &self, line: u32, character: u32, ) -> Result<JsValue, JsError>
Get completions at the given position.
Sourcepub fn get_hover_info(
&self,
line: u32,
character: u32,
) -> Result<JsValue, JsError>
pub fn get_hover_info( &self, line: u32, character: u32, ) -> Result<JsValue, JsError>
Get hover information at the given position.
Sourcepub fn get_definition(
&self,
line: u32,
character: u32,
) -> Result<JsValue, JsError>
pub fn get_definition( &self, line: u32, character: u32, ) -> Result<JsValue, JsError>
Get the definition location for the symbol at the given position.
Sourcepub fn get_document_symbols(&self) -> Result<JsValue, JsError>
pub fn get_document_symbols(&self) -> Result<JsValue, JsError>
Get all document symbols for the outline view.
Sourcepub fn get_references(
&self,
line: u32,
character: u32,
) -> Result<JsValue, JsError>
pub fn get_references( &self, line: u32, character: u32, ) -> Result<JsValue, JsError>
Find all references to the symbol at the given position.
Sourcepub fn serialize(&self) -> Result<Vec<u8>, JsError>
pub fn serialize(&self) -> Result<Vec<u8>, JsError>
Serialize this ledger to a compact binary blob (rkyv).
Store the bytes in OPFS or IndexedDB alongside a source fingerprint
(see crate::hash_sources) and restore later with ParsedLedger::from_cache.
Sourcepub fn from_cache(bytes: &[u8], source: &str) -> Result<Self, JsError>
pub fn from_cache(bytes: &[u8], source: &str) -> Result<Self, JsError>
Restore a ParsedLedger from bytes produced by ParsedLedger::serialize.
The source parameter must be the same source text used when the cache
was created; it is re-parsed (but not re-booked or re-validated) so that
editor features continue to work.
§Errors
Returns an error if the bytes are invalid or were produced by a different library version.
Trait Implementations§
Source§impl From<ParsedLedger> for JsValue
impl From<ParsedLedger> for JsValue
Source§fn from(value: ParsedLedger) -> Self
fn from(value: ParsedLedger) -> Self
Source§impl FromWasmAbi for ParsedLedger
impl FromWasmAbi for ParsedLedger
Source§impl IntoWasmAbi for ParsedLedger
impl IntoWasmAbi for ParsedLedger
Source§impl LongRefFromWasmAbi for ParsedLedger
impl LongRefFromWasmAbi for ParsedLedger
Source§type Abi = WasmPtr<WasmRefCell<ParsedLedger>>
type Abi = WasmPtr<WasmRefCell<ParsedLedger>>
RefFromWasmAbi::AbiSource§type Anchor = RcRef<ParsedLedger>
type Anchor = RcRef<ParsedLedger>
RefFromWasmAbi::AnchorSource§unsafe fn long_ref_from_abi(js: Self::Abi) -> Self::Anchor
unsafe fn long_ref_from_abi(js: Self::Abi) -> Self::Anchor
RefFromWasmAbi::ref_from_abiSource§impl OptionFromWasmAbi for ParsedLedger
impl OptionFromWasmAbi for ParsedLedger
Source§impl OptionIntoWasmAbi for ParsedLedger
impl OptionIntoWasmAbi for ParsedLedger
Source§impl RefFromWasmAbi for ParsedLedger
impl RefFromWasmAbi for ParsedLedger
Source§type Abi = WasmPtr<WasmRefCell<ParsedLedger>>
type Abi = WasmPtr<WasmRefCell<ParsedLedger>>
Self are recovered from.Source§type Anchor = RcRef<ParsedLedger>
type Anchor = RcRef<ParsedLedger>
Self for the duration of the
invocation of the function that has an &Self parameter. This is
required to ensure that the lifetimes don’t persist beyond one function
call, and so that they remain anonymous.Source§impl RefMutFromWasmAbi for ParsedLedger
impl RefMutFromWasmAbi for ParsedLedger
Source§type Abi = WasmPtr<WasmRefCell<ParsedLedger>>
type Abi = WasmPtr<WasmRefCell<ParsedLedger>>
RefFromWasmAbi::AbiSource§type Anchor = RcRefMut<ParsedLedger>
type Anchor = RcRefMut<ParsedLedger>
RefFromWasmAbi::AnchorSource§unsafe fn ref_mut_from_abi(js: Self::Abi) -> Self::Anchor
unsafe fn ref_mut_from_abi(js: Self::Abi) -> Self::Anchor
RefFromWasmAbi::ref_from_abiimpl SupportsConstructor for ParsedLedger
impl SupportsInstanceProperty for ParsedLedger
impl SupportsStaticProperty for ParsedLedger
Source§impl TryFromJsValue for ParsedLedger
impl TryFromJsValue for ParsedLedger
Source§impl VectorFromWasmAbi for ParsedLedger
impl VectorFromWasmAbi for ParsedLedger
type Abi = <Box<[JsValue]> as FromWasmAbi>::Abi
unsafe fn vector_from_abi(js: Self::Abi) -> Box<[ParsedLedger]>
Source§impl VectorIntoWasmAbi for ParsedLedger
impl VectorIntoWasmAbi for ParsedLedger
type Abi = <Box<[JsValue]> as IntoWasmAbi>::Abi
fn vector_into_abi(vector: Box<[ParsedLedger]>) -> Self::Abi
Source§impl WasmDescribeVector for ParsedLedger
impl WasmDescribeVector for ParsedLedger
Auto Trait Implementations§
impl Freeze for ParsedLedger
impl RefUnwindSafe for ParsedLedger
impl Send for ParsedLedger
impl Sync for ParsedLedger
impl Unpin for ParsedLedger
impl UnsafeUnpin for ParsedLedger
impl UnwindSafe for ParsedLedger
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
Source§type Abi = <T as IntoWasmAbi>::Abi
type Abi = <T as IntoWasmAbi>::Abi
IntoWasmAbi::AbiSource§fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
IntoWasmAbi::into_abi, except that it may throw and never
return in the case of Err.