#[non_exhaustive]pub enum TokenType<'input> {
Show 23 variants
#[non_exhaustive] StreamStart,
#[non_exhaustive] StreamEnd,
#[non_exhaustive] VersionDirective {
major: u32,
minor: u32,
},
#[non_exhaustive] TagDirective {
handle: Cow<'input, str>,
prefix: Cow<'input, str>,
},
#[non_exhaustive] DocumentStart,
#[non_exhaustive] DocumentEnd,
#[non_exhaustive] BlockSequenceStart,
#[non_exhaustive] BlockMappingStart,
#[non_exhaustive] BlockEnd,
#[non_exhaustive] FlowSequenceStart,
#[non_exhaustive] FlowSequenceEnd,
#[non_exhaustive] FlowMappingStart,
#[non_exhaustive] FlowMappingEnd,
#[non_exhaustive] BlockEntry,
#[non_exhaustive] FlowEntry,
#[non_exhaustive] Key,
#[non_exhaustive] Value,
#[non_exhaustive] Alias {
name: Cow<'input, str>,
},
#[non_exhaustive] Anchor {
name: Cow<'input, str>,
},
#[non_exhaustive] Tag {
handle: Cow<'input, str>,
suffix: Cow<'input, str>,
},
#[non_exhaustive] Scalar {
style: ScalarStyle,
value: Cow<'input, str>,
},
#[non_exhaustive] Comment {
comment: Comment<'input>,
},
#[non_exhaustive] ReservedDirective {
name: String,
parameters: Vec<String>,
},
}Expand description
The contents of a scanner token.
Use matches!, if let, or match with { .. } to inspect a token variant. Every
variant is non-exhaustive, even if it currently has no fields, so the library can add
metadata without changing those patterns. A complete match also needs a fallback arm.
Normal builds provide no whole-token equality; the opt-in test_equality feature enables
equality for tests. It compares token variants and payloads, but scalar styles compare only
their notation category, ignoring optional extended_details source metadata. This keeps
equality independent of whether a dependency enables metadata capture; compare syntax
fields explicitly when they matter. Constructors support synthetic token streams and
scanner adapters.
use granit_parser::{Scanner, StrInput, TokenType};
let token = Scanner::new(StrInput::new("value")).next().unwrap().unwrap();
assert!(matches!(token.token_type(), TokenType::StreamStart { .. }));use granit_parser::TokenType;
fn equal_tokens(left: TokenType<'_>, right: TokenType<'_>) -> bool {
left == right
}use granit_parser::TokenType;
let token = TokenType::alias("name".into());
assert!(matches!(token, TokenType::Alias { name, .. } if name == "name"));Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
#[non_exhaustive]StreamStart
Start of the stream.
#[non_exhaustive]StreamEnd
End of the stream.
#[non_exhaustive]VersionDirective
A YAML version directive.
Fields
This variant is marked as non-exhaustive
#[non_exhaustive]TagDirective
A YAML tag directive.
Fields
This variant is marked as non-exhaustive
#[non_exhaustive]DocumentStart
Explicit document start marker (---).
#[non_exhaustive]DocumentEnd
Explicit document end marker (...).
#[non_exhaustive]BlockSequenceStart
Start of a block sequence.
#[non_exhaustive]BlockMappingStart
Start of a block mapping.
#[non_exhaustive]BlockEnd
End of a block collection.
#[non_exhaustive]FlowSequenceStart
Opening [ of a flow sequence.
#[non_exhaustive]FlowSequenceEnd
Closing ] of a flow sequence.
#[non_exhaustive]FlowMappingStart
Opening { of a flow mapping.
#[non_exhaustive]FlowMappingEnd
Closing } of a flow mapping.
#[non_exhaustive]BlockEntry
Block sequence entry indicator.
#[non_exhaustive]FlowEntry
Flow collection entry separator.
#[non_exhaustive]Key
Mapping key indicator.
#[non_exhaustive]Value
Mapping value indicator.
#[non_exhaustive]Alias
Alias name without the leading *.
Fields
This variant is marked as non-exhaustive
#[non_exhaustive]Anchor
Anchor name without the leading &.
Fields
This variant is marked as non-exhaustive
#[non_exhaustive]Tag
A YAML tag.
Fields
This variant is marked as non-exhaustive
#[non_exhaustive]Scalar
A decoded YAML scalar and its source syntax.
Fields
This variant is marked as non-exhaustive
style: ScalarStyleScalar source syntax.
#[non_exhaustive]Comment
A source comment, including its placement hint.
Fields
This variant is marked as non-exhaustive
#[non_exhaustive]ReservedDirective
A reserved directive and its whitespace-separated parameters.
Fields
This variant is marked as non-exhaustive
Implementations§
Source§impl<'input> TokenType<'input>
impl<'input> TokenType<'input>
Sourcepub const fn stream_start() -> Self
pub const fn stream_start() -> Self
Return a Self::StreamStart token payload.
Sourcepub const fn stream_end() -> Self
pub const fn stream_end() -> Self
Return a Self::StreamEnd token payload.
Sourcepub const fn document_start() -> Self
pub const fn document_start() -> Self
Return a Self::DocumentStart token payload.
Sourcepub const fn document_end() -> Self
pub const fn document_end() -> Self
Return a Self::DocumentEnd token payload.
Sourcepub const fn block_sequence_start() -> Self
pub const fn block_sequence_start() -> Self
Return a Self::BlockSequenceStart token payload.
Sourcepub const fn block_mapping_start() -> Self
pub const fn block_mapping_start() -> Self
Return a Self::BlockMappingStart token payload.
Sourcepub const fn block_end() -> Self
pub const fn block_end() -> Self
Return a Self::BlockEnd token payload.
Sourcepub const fn flow_sequence_start() -> Self
pub const fn flow_sequence_start() -> Self
Return a Self::FlowSequenceStart token payload.
Sourcepub const fn flow_sequence_end() -> Self
pub const fn flow_sequence_end() -> Self
Return a Self::FlowSequenceEnd token payload.
Sourcepub const fn flow_mapping_start() -> Self
pub const fn flow_mapping_start() -> Self
Return a Self::FlowMappingStart token payload.
Sourcepub const fn flow_mapping_end() -> Self
pub const fn flow_mapping_end() -> Self
Return a Self::FlowMappingEnd token payload.
Sourcepub const fn block_entry() -> Self
pub const fn block_entry() -> Self
Return a Self::BlockEntry token payload.
Sourcepub const fn flow_entry() -> Self
pub const fn flow_entry() -> Self
Return a Self::FlowEntry token payload.
Sourcepub const fn value() -> Self
pub const fn value() -> Self
Return a Self::Value token payload.
Sourcepub fn version_directive(major: u32, minor: u32) -> Self
pub fn version_directive(major: u32, minor: u32) -> Self
Return a Self::VersionDirective token payload.
major: Major version number.minor: Minor version number.
Sourcepub fn tag_directive(handle: Cow<'input, str>, prefix: Cow<'input, str>) -> Self
pub fn tag_directive(handle: Cow<'input, str>, prefix: Cow<'input, str>) -> Self
Return a Self::TagDirective token payload.
handle: Tag handle.prefix: Tag URI prefix.
Sourcepub fn alias(name: Cow<'input, str>) -> Self
pub fn alias(name: Cow<'input, str>) -> Self
Return a Self::Alias token payload.
name: Original name without an indicator.
Sourcepub fn anchor(name: Cow<'input, str>) -> Self
pub fn anchor(name: Cow<'input, str>) -> Self
Return a Self::Anchor token payload.
name: Original name without an indicator.
Sourcepub fn tag(handle: Cow<'input, str>, suffix: Cow<'input, str>) -> Self
pub fn tag(handle: Cow<'input, str>, suffix: Cow<'input, str>) -> Self
Return a Self::Tag token payload.
handle: Tag handle.suffix: Tag suffix.
Sourcepub fn scalar(style: ScalarStyle, value: Cow<'input, str>) -> Self
pub fn scalar(style: ScalarStyle, value: Cow<'input, str>) -> Self
Return a Self::Scalar token payload.
style: Scalar source syntax.value: Decoded scalar value.
Sourcepub fn comment(comment: Comment<'input>) -> Self
pub fn comment(comment: Comment<'input>) -> Self
Return a Self::Comment token payload.
comment: Captured comment metadata.
Sourcepub fn reserved_directive(name: String, parameters: Vec<String>) -> Self
pub fn reserved_directive(name: String, parameters: Vec<String>) -> Self
Return a Self::ReservedDirective token payload.
name: Original name without an indicator.parameters: Directive parameters split on YAML whitespace.