1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
use crateSourceMap;
use crateGraphQLToken;
/// Trait for [`GraphQLToken`] lexers (iterators that generate
/// [`GraphQLToken`]).
///
/// This trait enables extensibility over different sources of GraphQL text to
/// be parsed. For example:
/// [`StrGraphQLTokenSource`](crate::token::StrGraphQLTokenSource) is a
/// lexer over `&str` types,
/// [`libgraphql_macros::RustMacroGraphQLTokenSource`](https://github.com/jeffmo/libgraphql/blob/59aa00fe928249c9d7abcd2576e2e37e45345955/crates/libgraphql-macros/src/rust_macro_graphql_token_source.rs#L101)
/// is a lexer over
/// [`proc_macro2::Span`](https://docs.rs/proc-macro2/latest/proc_macro2/struct.Span.html)
/// (for lexing Rust procedural macro input), etc.
///
/// Implementors define an [`Iterator`] that produces tokens one at a time.
/// All lookahead, buffering, and peeking is handled by `GraphQLTokenStream`.
///
/// Lexers are responsible for:
/// - Skipping whitespace (an "ignored token" per the GraphQL spec)
/// - Accumulating trivia (comments, commas) and attaching to the next token
/// - Emitting [`GraphQLTokenKind::Error`](crate::token::GraphQLTokenKind::Error)
/// for lexer errors (enables error recovery)
/// - Emitting a final token with
/// [`GraphQLTokenKind::Eof`](crate::token::GraphQLTokenKind::Eof) carrying
/// any trailing trivia
///
/// # Lifetime Parameter
///
/// The `'src` lifetime represents the source text that tokens are lexed from.
/// For string-based lexers, this enables zero-copy lexing where token values
/// can borrow directly from the input. For proc-macro lexers that must
/// allocate strings, use `'static` as the lifetime.
///
/// # SourceMap
///
/// Each token source carries a [`SourceMap`] that maps byte offsets (stored
/// compactly in [`ByteSpan`](crate::ByteSpan)) to resolved line/column
/// positions. The `source_map()` method borrows it for mid-stream lookups
/// (e.g. IDE hover), and `into_source_map()` transfers ownership to
/// `ParseResult` after parsing completes.