Skip to main content

Token

Enum Token 

Source
pub enum Token<'a> {
Show 39 variants Identifier(&'a str), Number(f64), Text(&'a str), LeftRoundBracket, RightRoundBracket, LeftSquareBracket, RightSquareBracket, LeftCurlyBracket, RightCurlyBracket, PairingOp, AssignmentOp, LabellingOp, MappingOp, ThenOp, ReverseCompositionOp, CompositionOp, FunctionDefinitionOp, AlternativeOp, ConditionalOp, OrOp, AndOp, EqualToOp, NotEqualToOp, LessThanOp, LessThanOrEqualToOp, GreaterThanOp, GreaterThanOrEqualToOp, PlusOp, MinusOp, ProductOp, DivisionOp, ModuloOp, PowerOp, SubcontextingOp, NotOp, LiftingOp, Undefined(&'a str), Comment(&'a str), EndOfExpression,
}
Expand description

All token kinds produced by the Lexer.

The lifetime 'a is tied to the source string: Identifier, Text, Comment, and Undefined variants borrow slices directly from it, so no heap allocation is needed for those payloads.

Variants§

§

Identifier(&'a str)

A name — starts with a letter or _, continues with letters, digits, or _. Examples: foo, _bar, myVar1.

§

Number(f64)

A floating-point numeric literal. Integer, decimal, and scientific notation are all parsed into an f64. Examples: 42, 3.14, 1.5e-3.

§

Text(&'a str)

A double-quoted string literal. The slice contains only the content between the quotes — the delimiters are not included. Example: "hello" → Text("hello").

There are no escape sequences: a backslash is an ordinary character, and a text literal cannot contain ". A literal may span several lines.

Note: if the closing " is absent the slice extends to the end of the source string (the lexer does not error on unterminated strings).

§

LeftRoundBracket

(

§

RightRoundBracket

)

§

LeftSquareBracket

[ — opens a list literal.

§

RightSquareBracket

] — closes a list literal.

§

LeftCurlyBracket

{ — opens a namespace literal.

§

RightCurlyBracket

} — closes a namespace literal.

§

PairingOp

, (precedence 10) — pairing / tuple construction.

§

AssignmentOp

= (precedence 12) — assignment.

§

LabellingOp

: (precedence 12) — labelling / named argument.

§

MappingOp

=> (precedence 13, right-associative) — mapping: applies the right-hand function(s) to each item of the left-hand tuple.

§

ThenOp

~> (precedence 13, left-associative) — then: chains a function to a promise.

§

ReverseCompositionOp

>> (precedence 14) — reverse composition / pipe (left-to-right).

§

CompositionOp

<< (precedence 14) — composition (right-to-left).

§

FunctionDefinitionOp

-> (precedence 15) — function definition (right-associative).

§

AlternativeOp

; (precedence 21) — alternative: evaluates the right-hand side only when the left-hand side is Nothing.

§

ConditionalOp

? (precedence 22) — conditional: evaluates the right-hand side only when the left-hand side is truthy.

§

OrOp

| (precedence 23) — logical OR.

§

AndOp

& (precedence 23) — logical AND.

§

EqualToOp

== (precedence 24) — equality comparison.

§

NotEqualToOp

!= (precedence 24) — inequality comparison.

§

LessThanOp

< (precedence 24) — less-than comparison.

§

LessThanOrEqualToOp

<= (precedence 24) — less-than-or-equal comparison.

§

GreaterThanOp

> (precedence 24) — greater-than comparison.

§

GreaterThanOrEqualToOp

>= (precedence 24) — greater-than-or-equal comparison.

§

PlusOp

+ (precedence 25) — addition.

§

MinusOp

- (precedence 25) — subtraction.

§

ProductOp

* (precedence 26) — multiplication.

§

DivisionOp

/ (precedence 26) — division.

§

ModuloOp

% (precedence 26) — modulo.

§

PowerOp

^ (precedence 27) — exponentiation.

§

SubcontextingOp

. (precedence 30) — sub-contexting: looks up the right-hand name inside the namespace produced by the left-hand expression. Example: math.sin retrieves sin from the math namespace.

§

NotOp

! (prefix) — logical negation.

§

LiftingOp

$ (prefix) — lifting: looks a name up starting from the outermost scope.

§

Undefined(&'a str)

A character sequence the lexer could not classify as any valid token. The slice covers exactly the unrecognised source characters.

Examples: ', @, a malformed number like 1e+ or 12abc.

§

Comment(&'a str)

A #-prefixed line comment. The slice contains the comment text after the # and before the terminating \n (or end of source).

The lexer yields comments as tokens so that a tool such as a formatter can use them. The Parser skips them.

§

EndOfExpression

Signals that the source string has been fully consumed.

next_token returns this sentinel instead of Option::None so that call-sites do not need to handle two distinct “no more input” states. The Iterator impl converts it to None.

Trait Implementations§

Source§

impl<'a> Clone for Token<'a>

Source§

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

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for Token<'a>

Source§

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

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

impl<'a> PartialEq for Token<'a>

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl<'a> StructuralPartialEq for Token<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for Token<'a>

§

impl<'a> RefUnwindSafe for Token<'a>

§

impl<'a> Send for Token<'a>

§

impl<'a> Sync for Token<'a>

§

impl<'a> Unpin for Token<'a>

§

impl<'a> UnsafeUnpin for Token<'a>

§

impl<'a> UnwindSafe for Token<'a>

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> 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<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> 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, 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.