Skip to main content

Syntax

Enum Syntax 

Source
#[non_exhaustive]
pub enum Syntax { Plain, Keyword, String, Comment, Constant, Entity, Variable, Support, }
Expand description

What a run of source code is, once something has classified it.

The description carries the classification and never the source, which is the whole of decision 19d7602d (2026-09-02, option d). An app that browses source already has a lexer; a renderer does not and should not grow one, and three renderers each growing their own would disagree about the same file.

§Why the app classifies and the renderer colours

Measured on MNW’s source browser, which is the only consumer in the tree. It highlights server-side with syntect and had already reduced syntect’s scope space to seven colours held fixed across all 31 themes, because a reader recognises a highlighting palette and re-tinting it per theme costs that recognition to gain nothing. So the classification existed on the app side already: the only question was whether to throw it away at the seam and have each renderer redo it. This is the answer.

The precedent is docengine’s Emphasis, which crosses the same seam the same way: quasi-tui maps its four flags onto terminal modifiers, a webview maps them onto elements, and neither parses markdown to do it.

§The eight, and why these eight

The seven MNW’s palette fixes, plus Plain for a run nothing claimed. Plain is not an absence: a lexer that ran and found ordinary code is saying something a renderer wants, and an Option<Syntax> would have made “unclassified” and “not classified yet” one value.

#[non_exhaustive] from the first commit, deliberately. A ninth class is the obvious next request and it must not be a breaking release across three renderers and five apps.

§What it is not

A token type in a grammar. These are display classes, coarse on purpose: the distinctions a reader uses at a glance, not the ones a parser makes. A renderer wanting more has language on the node beside this and may do whatever it likes with it.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Plain

Ordinary code nothing else claimed.

The default, and a real answer rather than a missing one. See the type’s docs for why this is not an Option.

§

Keyword

A language keyword, and the storage and modifier words with it.

§

String

A string or character literal.

§

Comment

A comment.

§

Constant

A literal that is not a string: a number, a boolean, a constant name.

§

Entity

A name being defined: a function, a type, a module.

§

Variable

A name being used: a variable, a parameter, a field.

§

Support

Something the language or its library provides rather than this file.

Implementations§

Source§

impl Syntax

Source

pub const fn name(self) -> &'static str

The stable lowercase name, for a renderer keying its own palette off it.

Named here rather than agreed between each renderer and each host, for the reason every other spelling in this crate is: that is how one renderer ends up calling it str and the next string, and a theme written against one stops working under the other.

Not an Intent token, and the difference is worth stating. An intent resolves against a makeover theme token, and there are none for syntax colours: a highlighting palette is deliberately outside the theme, held fixed while everything around it changes. So this is a name a renderer maps however it can, and a renderer with no colours to spend maps every one of them onto the same face and is not wrong.

Trait Implementations§

Source§

impl Clone for Syntax

Source§

fn clone(&self) -> Syntax

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 Copy for Syntax

Source§

impl Debug for Syntax

Source§

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

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

impl Default for Syntax

Source§

fn default() -> Syntax

Returns the “default value” for a type. Read more
Source§

impl Eq for Syntax

Source§

impl Hash for Syntax

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Syntax

Source§

fn eq(&self, other: &Syntax) -> bool

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

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Syntax

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> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.