Skip to main content

limbo_sqlite3_parser/parser/ast/
parameterinfo_traits.rs

1//! # `ParameterInfo` - Trait Implementations
2//!
3//! This module contains trait implementations for `ParameterInfo`.
4//!
5//! ## Implemented Traits
6//!
7//! - `TokenStream`
8//!
9//! 🤖 Generated with [SplitRS](https://github.com/cool-japan/splitrs)
10
11use super::fmt::TokenStream;
12use crate::dialect::TokenType::{self, *};
13use std::num::ParseIntError;
14use std::str::{self, FromStr};
15
16use super::types_11::ParameterInfo;
17
18// https://sqlite.org/lang_expr.html#parameters
19impl TokenStream for ParameterInfo {
20    type Error = ParseIntError;
21
22    fn append(&mut self, ty: TokenType, value: Option<&str>) -> Result<(), Self::Error> {
23        if ty == TK_VARIABLE {
24            if let Some(variable) = value {
25                if variable == "?" {
26                    self.count = self.count.saturating_add(1);
27                } else if variable.as_bytes()[0] == b'?' {
28                    let n = u32::from_str(&variable[1..])?;
29                    if n > self.count {
30                        self.count = n;
31                    }
32                } else if self.names.insert(variable.to_owned()) {
33                    self.count = self.count.saturating_add(1);
34                }
35            }
36        }
37        Ok(())
38    }
39}