Skip to main content

ParsedLedger

Struct ParsedLedger 

Source
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

Source

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.

Source

pub fn is_valid(&self) -> bool

Check if the ledger is valid (no parse or validation errors).

Source

pub fn get_errors(&self) -> Result<JsValue, JsError>

Get all errors (parse + validation).

Source

pub fn get_parse_errors(&self) -> Result<JsValue, JsError>

Get parse errors only.

Source

pub fn get_validation_errors(&self) -> Result<JsValue, JsError>

Get validation errors only.

Source

pub fn get_directives(&self) -> Result<JsValue, JsError>

Get the parsed directives.

Source

pub fn get_options(&self) -> Result<JsValue, JsError>

Get the ledger options.

Source

pub fn directive_count(&self) -> usize

Get the number of directives.

Source

pub fn query(&self, query_str: &str) -> Result<JsValue, JsError>

Run a BQL query on this ledger.

Source

pub fn balances(&self) -> Result<JsValue, JsError>

Get account balances (shorthand for query(“BALANCES”)).

Source

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.

Source

pub fn expand_pads(&self) -> Result<JsValue, JsError>

Expand pad directives.

Source

pub fn run_plugin(&self, plugin_name: &str) -> Result<JsValue, JsError>

Run a native plugin on this ledger.

Source

pub fn get_completions( &self, line: u32, character: u32, ) -> Result<JsValue, JsError>

Get completions at the given position.

Source

pub fn get_hover_info( &self, line: u32, character: u32, ) -> Result<JsValue, JsError>

Get hover information at the given position.

Source

pub fn get_definition( &self, line: u32, character: u32, ) -> Result<JsValue, JsError>

Get the definition location for the symbol at the given position.

Source

pub fn get_document_symbols(&self) -> Result<JsValue, JsError>

Get all document symbols for the outline view.

Source

pub fn get_references( &self, line: u32, character: u32, ) -> Result<JsValue, JsError>

Find all references to the symbol at the given position.

Source

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.

Source

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

Source§

fn from(value: ParsedLedger) -> Self

Converts to this type from the input type.
Source§

impl FromWasmAbi for ParsedLedger

Source§

type Abi = WasmPtr<WasmRefCell<ParsedLedger>>

The Wasm ABI type that this converts from when coming back out from the ABI boundary.
Source§

unsafe fn from_abi(js: Self::Abi) -> Self

Recover a Self from Self::Abi. Read more
Source§

impl IntoWasmAbi for ParsedLedger

Source§

type Abi = WasmPtr<WasmRefCell<ParsedLedger>>

The Wasm ABI type that this converts into when crossing the ABI boundary.
Source§

fn into_abi(self) -> Self::Abi

Convert self into Self::Abi so that it can be sent across the wasm ABI boundary.
Source§

impl LongRefFromWasmAbi for ParsedLedger

Source§

type Abi = WasmPtr<WasmRefCell<ParsedLedger>>

Same as RefFromWasmAbi::Abi
Source§

type Anchor = RcRef<ParsedLedger>

Same as RefFromWasmAbi::Anchor
Source§

unsafe fn long_ref_from_abi(js: Self::Abi) -> Self::Anchor

Same as RefFromWasmAbi::ref_from_abi
Source§

impl OptionFromWasmAbi for ParsedLedger

Source§

fn is_none(abi: &Self::Abi) -> bool

Tests whether the argument is a “none” instance. If so it will be deserialized as None, and otherwise it will be passed to FromWasmAbi.
Source§

impl OptionIntoWasmAbi for ParsedLedger

Source§

fn none() -> Self::Abi

Returns an ABI instance indicating “none”, which JS will interpret as the None branch of this option. Read more
Source§

impl RefFromWasmAbi for ParsedLedger

Source§

type Abi = WasmPtr<WasmRefCell<ParsedLedger>>

The Wasm ABI type references to Self are recovered from.
Source§

type Anchor = RcRef<ParsedLedger>

The type that holds the reference to 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§

unsafe fn ref_from_abi(js: Self::Abi) -> Self::Anchor

Recover a Self::Anchor from Self::Abi. Read more
Source§

impl RefMutFromWasmAbi for ParsedLedger

Source§

type Abi = WasmPtr<WasmRefCell<ParsedLedger>>

Same as RefFromWasmAbi::Abi
Source§

type Anchor = RcRefMut<ParsedLedger>

Same as RefFromWasmAbi::Anchor
Source§

unsafe fn ref_mut_from_abi(js: Self::Abi) -> Self::Anchor

Same as RefFromWasmAbi::ref_from_abi
Source§

impl SupportsConstructor for ParsedLedger

Source§

impl SupportsInstanceProperty for ParsedLedger

Source§

impl SupportsStaticProperty for ParsedLedger

Source§

impl TryFromJsValue for ParsedLedger

Source§

fn try_from_js_value(value: JsValue) -> Result<Self, JsValue>

Performs the conversion.
Source§

fn try_from_js_value_ref(value: &JsValue) -> Option<Self>

Performs the conversion.
Source§

impl VectorFromWasmAbi for ParsedLedger

Source§

impl VectorIntoWasmAbi for ParsedLedger

Source§

impl WasmDescribe for ParsedLedger

Source§

impl WasmDescribeVector for ParsedLedger

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> ArchivePointee for T

Source§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
Source§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<'src, T> IntoMaybe<'src, T> for T
where T: 'src,

Source§

type Proj<U: 'src> = U

Source§

fn map_maybe<R>( self, _f: impl FnOnce(&'src T) -> &'src R, g: impl FnOnce(T) -> R, ) -> <T as IntoMaybe<'src, T>>::Proj<R>
where R: 'src,

Source§

impl<T> LayoutRaw for T

Source§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Returns the layout of the type.
Source§

impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
where T: SharedNiching<N1, N2>, N1: Niching<T>, N2: Niching<T>,

Source§

unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool

Returns whether the given value has been niched. Read more
Source§

fn resolve_niched(out: Place<NichedOption<T, N1>>)

Writes data to out indicating that a T is niched.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Pointee for T

Source§

type Metadata = ()

The metadata type for pointers and references to this type.
Source§

impl<T> ReturnWasmAbi for T
where T: IntoWasmAbi,

Source§

type Abi = <T as IntoWasmAbi>::Abi

Same as IntoWasmAbi::Abi
Source§

fn return_abi(self) -> <T as ReturnWasmAbi>::Abi

Same as IntoWasmAbi::into_abi, except that it may throw and never return in the case of Err.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more