Skip to main content

GraphQLTokenKind

Enum GraphQLTokenKind 

Source
pub enum GraphQLTokenKind<'src> {
Show 23 variants Ampersand, At, Bang, Colon, CurlyBraceClose, CurlyBraceOpen, Dollar, Ellipsis, Equals, ParenClose, ParenOpen, Pipe, SquareBracketClose, SquareBracketOpen, Name(Cow<'src, str>), IntValue(Cow<'src, str>), FloatValue(Cow<'src, str>), StringValue(Cow<'src, str>), True, False, Null, Eof, Error { message: String, error_notes: GraphQLErrorNotes, },
}
Expand description

The kind of a GraphQL token.

Literal values (IntValue, FloatValue, StringValue) store only the raw source text.

§Lifetime Parameter

The 'src lifetime enables zero-copy lexing: StrGraphQLTokenSource can borrow string slices directly from the source text using Cow::Borrowed, while RustMacroGraphQLTokenSource uses Cow::Owned since proc_macro2 doesn’t expose contiguous source text.

§Negative Numeric Literals

Negative numbers like -123 are lexed as single tokens (e.g. IntValue("-123")), not as separate minus and number tokens. This matches the GraphQL spec’s grammar for IntValue/FloatValue.

Variants§

§

Ampersand

&

§

At

@

§

Bang

!

§

Colon

:

§

CurlyBraceClose

}

§

CurlyBraceOpen

{

§

Dollar

$

§

Ellipsis

...

§

Equals

=

§

ParenClose

)

§

ParenOpen

(

§

Pipe

|

§

SquareBracketClose

]

§

SquareBracketOpen

[

§

Name(Cow<'src, str>)

A GraphQL name/identifier.

Uses Cow<'src, str> to enable zero-copy lexing from string sources.

§

IntValue(Cow<'src, str>)

Raw source text of an integer literal, including optional negative sign (e.g. "-123", "0").

Use parse_int_value() to parse the raw text into an i64. Uses Cow<'src, str> to enable zero-copy lexing from string sources.

§

FloatValue(Cow<'src, str>)

Raw source text of a float literal, including optional negative sign (e.g. "-1.23e-4", "0.5").

Use parse_float_value() to parse the raw text into an f64. Uses Cow<'src, str> to enable zero-copy lexing from string sources.

§

StringValue(Cow<'src, str>)

Raw source text of a string literal, including quotes (e.g. "\"hello\\nworld\"", "\"\"\"block\"\"\"")

Use parse_string_value() to process escape sequences and get the unescaped content. Uses Cow<'src, str> to enable zero-copy lexing from string sources.

§

True

The true literal.

§

False

The false literal.

§

Null

The null literal.

§

Eof

End of input. The associated GraphQLToken may carry trailing trivia.

§

Error

A lexer error. This allows the parser to continue and collect multiple errors in a single pass.

TODO: Explore replacing error_notes with a richer diagnostics structure that includes things like severity level and “fix action” for IDE integration.

Fields

§message: String

A human-readable error message.

§error_notes: GraphQLErrorNotes

Optional notes providing additional context or suggestions.

Implementations§

Source§

impl<'src> GraphQLTokenKind<'src>

Source

pub fn name_borrowed(s: &'src str) -> Self

Create a Name token from a borrowed string slice (zero-copy).

Use this in StrGraphQLTokenSource where the source text can be borrowed directly.

Source

pub fn name_owned(s: String) -> Self

Create a Name token from an owned String.

Use this in RustMacroGraphQLTokenSource where the string must be allocated (e.g., from ident.to_string()).

Source

pub fn int_value_borrowed(s: &'src str) -> Self

Create an IntValue token from a borrowed string slice (zero-copy).

Source

pub fn int_value_owned(s: String) -> Self

Create an IntValue token from an owned String.

Source

pub fn float_value_borrowed(s: &'src str) -> Self

Create a FloatValue token from a borrowed string slice (zero-copy).

Source

pub fn float_value_owned(s: String) -> Self

Create a FloatValue token from an owned String.

Source

pub fn string_value_borrowed(s: &'src str) -> Self

Create a StringValue token from a borrowed string slice (zero-copy).

Source

pub fn string_value_owned(s: String) -> Self

Create a StringValue token from an owned String.

Source

pub fn error(message: impl Into<String>, error_notes: GraphQLErrorNotes) -> Self

Create an Error token.

Error messages are always dynamically constructed, so they use plain String rather than Cow.

Source

pub fn is_punctuator(&self) -> bool

Returns true if this token is a punctuator.

Source

pub fn as_punctuator_str(&self) -> Option<&'static str>

Returns the string representation of this token if it is a punctuator.

Source

pub fn is_value(&self) -> bool

Returns true if this token is a value literal (IntValue, FloatValue, StringValue, True, False, or Null).

Source

pub fn is_error(&self) -> bool

Returns true if this token represents a lexer error.

Source

pub fn parse_int_value(&self) -> Option<Result<i64, ParseIntError>>

Parse an IntValue’s raw text to i64.

Returns None if this is not an IntValue, or Some(Err(...)) if parsing fails.

Source

pub fn parse_float_value(&self) -> Option<Result<f64, ParseFloatError>>

Parse a FloatValue’s raw text to f64.

Returns None if this is not a FloatValue, or Some(Err(...)) if parsing fails.

Source

pub fn parse_string_value( &self, ) -> Option<Result<String, GraphQLStringParsingError>>

Parse a StringValue’s raw text to unescaped content.

Handles escape sequences per the GraphQL spec:

  • For single-line strings ("..."): processes \n, \r, \t, \\, \", \/, \b, \f, \uXXXX (fixed 4-digit), and \u{X...} (variable length).
  • For block strings ("""..."""): applies the indentation stripping algorithm per spec, then processes \""" escape only.

Returns None if this is not a StringValue, or Some(Err(...)) if parsing fails.

Trait Implementations§

Source§

impl<'src> Clone for GraphQLTokenKind<'src>

Source§

fn clone(&self) -> GraphQLTokenKind<'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 GraphQLTokenKind<'src>

Source§

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

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

impl<'src> PartialEq for GraphQLTokenKind<'src>

Source§

fn eq(&self, other: &GraphQLTokenKind<'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> StructuralPartialEq for GraphQLTokenKind<'src>

Auto Trait Implementations§

§

impl<'src> Freeze for GraphQLTokenKind<'src>

§

impl<'src> RefUnwindSafe for GraphQLTokenKind<'src>

§

impl<'src> Send for GraphQLTokenKind<'src>

§

impl<'src> Sync for GraphQLTokenKind<'src>

§

impl<'src> Unpin for GraphQLTokenKind<'src>

§

impl<'src> UnwindSafe for GraphQLTokenKind<'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> 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.