Skip to main content

libgraphql_parser/ast/
boolean_value.rs

1use crate::ast::ast_node::append_span_source_slice;
2use crate::ast::AstNode;
3use crate::ByteSpan;
4use crate::SourceMap;
5use crate::SourceSpan;
6use crate::token::GraphQLToken;
7use inherent::inherent;
8
9/// A GraphQL boolean value (`true` or `false`).
10///
11/// See the
12/// [Boolean Value](https://spec.graphql.org/September2025/#sec-Boolean-Value)
13/// section of the spec.
14#[derive(Clone, Debug, PartialEq)]
15pub struct BooleanValue<'src> {
16    pub span: ByteSpan,
17    pub syntax: Option<Box<BooleanValueSyntax<'src>>>,
18    pub value: bool,
19}
20
21/// Syntax detail for a [`BooleanValue`].
22#[derive(Clone, Debug, PartialEq)]
23pub struct BooleanValueSyntax<'src> {
24    pub token: GraphQLToken<'src>,
25}
26
27#[inherent]
28impl AstNode for BooleanValue<'_> {
29    /// See [`AstNode::append_source()`](crate::ast::AstNode::append_source).
30    pub fn append_source(
31        &self,
32        sink: &mut String,
33        source: Option<&str>,
34    ) {
35        if let Some(src) = source {
36            append_span_source_slice(
37                self.span, sink, src,
38            );
39        }
40    }
41
42    /// Returns this boolean value's byte-offset span within the
43    /// source text.
44    ///
45    /// The returned [`ByteSpan`] can be resolved to line/column
46    /// positions via [`source_span()`](Self::source_span) or
47    /// [`ByteSpan::resolve()`].
48    #[inline]
49    pub fn byte_span(&self) -> ByteSpan {
50        self.span
51    }
52
53    /// Resolves this boolean value's position to line/column
54    /// coordinates using the given [`SourceMap`].
55    ///
56    /// Returns [`None`] if the byte offsets cannot be resolved
57    /// (e.g. the span was synthetically constructed without
58    /// valid position data).
59    #[inline]
60    pub fn source_span(
61        &self,
62        source_map: &SourceMap,
63    ) -> Option<SourceSpan> {
64        self.byte_span().resolve(source_map)
65    }
66}