Token

Enum Token 

Source
pub enum Token<'src> {
Show 55 variants Date(&'src str), Number(&'src str), String(&'src str), Account(&'src str), Currency(&'src str), Tag(&'src str), Link(&'src str), Txn, Balance, Open, Close, Commodity, Pad, Event, Query, Note, Document, Price, Custom, Option_, Include, Plugin, Pushtag, Poptag, Pushmeta, Popmeta, True, False, Null, LDoubleBrace, RDoubleBrace, LBraceHash, LBrace, RBrace, LParen, RParen, AtAt, At, Colon, Comma, Tilde, Plus, Minus, Star, Slash, Pending, Flag(&'src str), Newline, Comment(&'src str), Shebang(&'src str), EmacsDirective(&'src str), MetaKey(&'src str), Indent(usize), DeepIndent(usize), Error,
}
Expand description

Token types produced by the Logos lexer.

Variants§

§

Date(&'src str)

A date in YYYY-MM-DD or YYYY/MM/DD format.

§

Number(&'src str)

A number with optional sign, thousands separators, and decimals. Examples: 123, -456, 1,234.56, 1234.5678, .50, -.50

§

String(&'src str)

A double-quoted string (handles escape sequences). The slice includes the quotes.

§

Account(&'src str)

An account name like Assets:Bank:Checking or Assets:401k:Fidelity. Must start with one of the 5 account types and have at least one sub-account. Sub-accounts can start with uppercase letter or digit.

§

Currency(&'src str)

A currency/commodity code like USD, EUR, AAPL, BTC. Uppercase letters, can contain digits, apostrophes, dots, underscores, hyphens. Note: This pattern is lower priority than Account, Keywords, and Flags. Currency must have at least 2 characters to avoid conflict with single-letter flags. Also supports / prefix for options/futures contracts (e.g., /LOX21_211204_P100.25).

§

Tag(&'src str)

A tag like #tag-name.

A link like ^link-name.

§

Txn

The txn keyword for transactions.

§

Balance

The balance directive keyword.

§

Open

The open directive keyword.

§

Close

The close directive keyword.

§

Commodity

The commodity directive keyword.

§

Pad

The pad directive keyword.

§

Event

The event directive keyword.

§

Query

The query directive keyword.

§

Note

The note directive keyword.

§

Document

The document directive keyword.

§

Price

The price directive keyword.

§

Custom

The custom directive keyword.

§

Option_

The option directive keyword.

§

Include

The include directive keyword.

§

Plugin

The plugin directive keyword.

§

Pushtag

The pushtag directive keyword.

§

Poptag

The poptag directive keyword.

§

Pushmeta

The pushmeta directive keyword.

§

Popmeta

The popmeta directive keyword.

§

True

The TRUE boolean literal (also True, true).

§

False

The FALSE boolean literal (also False, false).

§

Null

The NULL literal.

§

LDoubleBrace

Double left brace {{ for cost specifications (legacy total cost).

§

RDoubleBrace

Double right brace }} for cost specifications.

§

LBraceHash

Left brace with hash {# for total cost (new syntax).

§

LBrace

Left brace { for cost specifications.

§

RBrace

Right brace } for cost specifications.

§

LParen

Left parenthesis ( for expressions.

§

RParen

Right parenthesis ) for expressions.

§

AtAt

Double at-sign @@ for total cost.

§

At

At-sign @ for unit cost.

§

Colon

Colon : separator.

§

Comma

Comma , separator.

§

Tilde

Tilde ~ for tolerance.

§

Plus

Plus + operator.

§

Minus

Minus - operator.

§

Star

Star * for cleared transactions and multiplication.

§

Slash

Slash / for division.

§

Pending

Pending flag ! for incomplete transactions.

§

Flag(&'src str)

Other transaction flags: P S T C U R M # ? % & Note: # is only a flag when NOT followed by tag characters

§

Newline

Newline (significant in Beancount for directive boundaries).

§

Comment(&'src str)

A comment starting with semicolon. The slice includes the semicolon.

§

Shebang(&'src str)

Shebang line at start of file (e.g., #!/usr/bin/env bean-web). Treated as a comment-like directive to skip.

§

EmacsDirective(&'src str)

Emacs org-mode directive (e.g., “#+STARTUP: showall”). These are Emacs configuration lines that should be skipped.

§

MetaKey(&'src str)

A metadata key (identifier followed by colon). Examples: filename:, lineno:, custom-key:, nameOnCard: The slice includes the trailing colon. Keys can use camelCase or snake_case.

§

Indent(usize)

Indentation token (inserted by post-processing, not by Logos). Contains the number of leading spaces. This is a placeholder - actual indentation detection happens in tokenize.

§

DeepIndent(usize)

Deep indentation (4+ spaces) - used for posting-level metadata.

§

Error

Error token for unrecognized input.

Implementations§

Source§

impl Token<'_>

Source

pub const fn is_txn_flag(&self) -> bool

Returns true if this is a transaction flag (* or !).

Source

pub const fn is_directive_keyword(&self) -> bool

Returns true if this is a keyword that starts a directive.

Trait Implementations§

Source§

impl<'src> Clone for Token<'src>

Source§

fn clone(&self) -> Token<'src>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'src> Debug for Token<'src>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Token<'_>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'s> Logos<'s> for Token<'s>

Source§

type Error = ()

Error type returned by the lexer. This can be set using #[logos(error = MyError)]. Defaults to () if not set.
Source§

type Extras = ()

Associated type Extras for the particular lexer. This can be set using #[logos(extras = MyExtras)] and accessed inside callbacks.
Source§

type Source = str

Source type this token can be lexed from. This will default to str, unless one of the defined patterns explicitly uses non-unicode byte values or byte slices, in which case that implementation will use [u8].
Source§

fn lex(lex: &mut Lexer<'s, Self>)

The heart of Logos. Called by the Lexer. The implementation for this function is generated by the logos-derive crate.
Source§

fn lexer(source: &'source Self::Source) -> Lexer<'source, Self>
where Self::Extras: Default,

Create a new instance of a Lexer that will produce tokens implementing this Logos.
Source§

fn lexer_with_extras( source: &'source Self::Source, extras: Self::Extras, ) -> Lexer<'source, Self>

Create a new instance of a Lexer with the provided Extras that will produce tokens implementing this Logos.
Source§

impl<'src> PartialEq for Token<'src>

Source§

fn eq(&self, other: &Token<'src>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'src> Eq for Token<'src>

Source§

impl<'src> StructuralPartialEq for Token<'src>

Auto Trait Implementations§

§

impl<'src> Freeze for Token<'src>

§

impl<'src> RefUnwindSafe for Token<'src>

§

impl<'src> Send for Token<'src>

§

impl<'src> Sync for Token<'src>

§

impl<'src> Unpin for Token<'src>

§

impl<'src> UnwindSafe for Token<'src>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. 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<'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> Pointee for T

Source§

type Metadata = ()

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

impl<'p, T> Seq<'p, T> for T
where T: Clone,

Source§

type Item<'a> = &'a T where T: 'a

The item yielded by the iterator.
Source§

type Iter<'a> = Once<&'a T> where T: 'a

An iterator over the items within this container, by reference.
Source§

fn seq_iter(&self) -> <T as Seq<'p, T>>::Iter<'_>

Iterate over the elements of the container.
Source§

fn contains(&self, val: &T) -> bool
where T: PartialEq,

Check whether an item is contained within this sequence.
Source§

fn to_maybe_ref<'b>(item: <T as Seq<'p, T>>::Item<'b>) -> Maybe<T, &'p T>
where 'p: 'b,

Convert an item of the sequence into a MaybeRef.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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<T> OrderedSeq<'_, T> for T
where T: Clone,