/* This is a generated file! */
/* Generated by `utils/build_lexers.py` via `utils/rustify.py` */
/* This process can be run via tox: `tox -e generate-rs` */
#![cfg_attr(rustfmt, rustfmt_skip)]
use once_cell::sync::Lazy;
use sqlfluffrs_types::{LexMatcher, LexMatcherConfig};
use sqlfluffrs_types::{Token, RegexModeGroup};
use sqlfluffrs_types::token::CaseFold;
use sqlfluffrs_types::{BracketPairEntry, BracketPairSet};

pub static SOQL_KEYWORDS: Lazy<Vec<String>> = Lazy::new(|| { vec![
    "CASE".to_string(),
    "CROSS".to_string(),
    "FULL".to_string(),
    "IGNORE".to_string(),
    "INNER".to_string(),
    "INTERVAL".to_string(),
    "JOIN".to_string(),
    "LAST_90_DAYS".to_string(),
    "LAST_FISCAL_QUARTER".to_string(),
    "LAST_FISCAL_YEAR".to_string(),
    "LAST_MONTH".to_string(),
    "LAST_N_DAYS".to_string(),
    "LAST_N_FISCAL_QUARTERS".to_string(),
    "LAST_N_FISCAL_YEARS".to_string(),
    "LAST_N_MONTHS".to_string(),
    "LAST_N_QUARTERS".to_string(),
    "LAST_N_WEEKS".to_string(),
    "LAST_N_YEARS".to_string(),
    "LAST_QUARTER".to_string(),
    "LAST_WEEK".to_string(),
    "LAST_YEAR".to_string(),
    "LEFT".to_string(),
    "NATURAL".to_string(),
    "NEXT_90_DAYS".to_string(),
    "NEXT_FISCAL_QUARTER".to_string(),
    "NEXT_FISCAL_YEAR".to_string(),
    "NEXT_MONTH".to_string(),
    "NEXT_N_DAYS".to_string(),
    "NEXT_N_FISCAL_QUARTERS".to_string(),
    "NEXT_N_FISCAL_YEARS".to_string(),
    "NEXT_N_MONTHS".to_string(),
    "NEXT_N_QUARTERS".to_string(),
    "NEXT_N_WEEKS".to_string(),
    "NEXT_N_YEARS".to_string(),
    "NEXT_QUARTER".to_string(),
    "NEXT_WEEK".to_string(),
    "NEXT_YEAR".to_string(),
    "NOT".to_string(),
    "NULL".to_string(),
    "ON".to_string(),
    "ORDER".to_string(),
    "OUTER".to_string(),
    "PARTITION".to_string(),
    "RESPECT".to_string(),
    "RIGHT".to_string(),
    "ROWS".to_string(),
    "SELECT".to_string(),
    "SET".to_string(),
    "THIS_FISCAL_QUARTER".to_string(),
    "THIS_FISCAL_YEAR".to_string(),
    "THIS_MONTH".to_string(),
    "THIS_QUARTER".to_string(),
    "THIS_WEEK".to_string(),
    "THIS_YEAR".to_string(),
    "TODAY".to_string(),
    "TOMORROW".to_string(),
    "UNION".to_string(),
    "USING".to_string(),
    "YESTERDAY".to_string(),
]});

pub static SOQL_LEXERS: Lazy<Vec<LexMatcher>> = Lazy::new(|| { vec![

    LexMatcher::regex_lexer(
        "whitespace",
        r#"[^\S\r\n]+"#,Token::whitespace_token,
        None,
        |_| true,
        LexMatcherConfig {
        subdivider: None,
        trim_post_subdivide: None,
        trim_start: None,
        trim_chars: None,
        quoted_value: None,
        escape_replacements: None,
        casefold: CaseFold::None,
        kwarg_type: None,
    },
    ),

    LexMatcher::regex_lexer(
        "inline_comment",
        r#"(--|#)[^\n]*"#,Token::comment_token,
        None,
        |input| input.starts_with(['#','-','/']),
        LexMatcherConfig {
        subdivider: None,
        trim_post_subdivide: None,
        trim_start: Some(vec![String::from("--"), String::from("#")]),
        trim_chars: None,
        quoted_value: None,
        escape_replacements: None,
        casefold: CaseFold::None,
        kwarg_type: None,
    },
    ),

    LexMatcher::regex_lexer(
        "block_comment",
        r#"\/\*([^\*]|\*(?!\/))*\*\/"#,Token::comment_token,
        Some(extract_nested_block_comment),
        |input| input.starts_with("/"),
        LexMatcherConfig {
        subdivider: Some(Box::new(
    LexMatcher::regex_subdivider(
        "newline",
        r#"\r\n|\n"#,Token::newline_token,
        None,
        |_| true,
        LexMatcherConfig {
        subdivider: None,
        trim_post_subdivide: None,
        trim_start: None,
        trim_chars: None,
        quoted_value: None,
        escape_replacements: None,
        casefold: CaseFold::None,
        kwarg_type: None,
    },
    ))),
        trim_post_subdivide: Some(Box::new(
    LexMatcher::regex_subdivider(
        "whitespace",
        r#"[^\S\r\n]+"#,Token::whitespace_token,
        None,
        |_| true,
        LexMatcherConfig {
        subdivider: None,
        trim_post_subdivide: None,
        trim_start: None,
        trim_chars: None,
        quoted_value: None,
        escape_replacements: None,
        casefold: CaseFold::None,
        kwarg_type: None,
    },
    ))),
        trim_start: None,
        trim_chars: None,
        quoted_value: None,
        escape_replacements: None,
        casefold: CaseFold::None,
        kwarg_type: None,
    },
    ),

    LexMatcher::regex_lexer(
        "single_quote",
        r#"'([^'\\]|\\.|'')*'"#,Token::code_token,
        None,
        |input| match input.as_bytes() {
        [b'\'', ..] => true,                     // Single quote case
        [b'R' | b'r', b'\'', ..] => true,        // r' or R'
        [b'B' | b'b', b'\'', ..] => true,        // b' or B'
        [b'R' | b'r', b'B' | b'b', b'\'', ..] => true, // rb', RB', etc.
        [b'B' | b'b', b'R' | b'r', b'\'', ..] => true, // br', Br', etc.
        _ => false,
    },
        LexMatcherConfig {
        subdivider: None,
        trim_post_subdivide: None,
        trim_start: None,
        trim_chars: None,
        quoted_value: Some((r#"'((?:[^'\\]|\\.|'')*)'"#.to_string(), RegexModeGroup::Index(1))),
        escape_replacements: Some(std::sync::Arc::new(vec![(r#"\\'|''"#.to_string(), r#"'"#.to_string())])),
        casefold: CaseFold::None,
        kwarg_type: None,
    },
    ),

    LexMatcher::regex_lexer(
        "double_quote",
        r#""(""|[^"\\]|\\.)*""#,Token::code_token,
        None,
        |input| match input.as_bytes() {
        [b'"', ..] => true,                     // Just a double quote
        [b'R' | b'r', b'"', ..] => true,        // r" or R"
        [b'B' | b'b', b'"', ..] => true,        // b" or B"
        [b'R' | b'r', b'B' | b'b', b'"', ..] => true, // rb", RB", etc.
        [b'B' | b'b', b'R' | b'r', b'"', ..] => true, // br", Br", etc.
        _ => false,
    },
        LexMatcherConfig {
        subdivider: None,
        trim_post_subdivide: None,
        trim_start: None,
        trim_chars: None,
        quoted_value: Some((r#""((?:[^"\\]|\\.)*)""#.to_string(), RegexModeGroup::Index(1))),
        escape_replacements: Some(std::sync::Arc::new(vec![(r#"\\"|"""#.to_string(), r#"""#.to_string())])),
        casefold: CaseFold::None,
        kwarg_type: None,
    },
    ),

    LexMatcher::regex_lexer(
        "back_quote",
        r#"`(?:[^`\\]|\\.)*`"#,Token::code_token,
        None,
        |_| true,
        LexMatcherConfig {
        subdivider: None,
        trim_post_subdivide: None,
        trim_start: None,
        trim_chars: None,
        quoted_value: Some((r#"`((?:[^`\\]|\\.)*)`"#.to_string(), RegexModeGroup::Index(1))),
        escape_replacements: Some(std::sync::Arc::new(vec![(r#"\\`"#.to_string(), r#"`"#.to_string())])),
        casefold: CaseFold::None,
        kwarg_type: None,
    },
    ),

    LexMatcher::regex_lexer(
        "dollar_quote",
        r#"\$(\w*)\$(.*?)\$\1\$"#,Token::code_token,
        None,
        |input| input.starts_with("$"),
        LexMatcherConfig {
        subdivider: None,
        trim_post_subdivide: None,
        trim_start: None,
        trim_chars: None,
        quoted_value: Some((r#"\$(\w*)\$(.*?)\$\1\$"#.to_string(), RegexModeGroup::Index(2))),
        escape_replacements: None,
        casefold: CaseFold::None,
        kwarg_type: None,
    },
    ),

    LexMatcher::regex_lexer(
        "datetime_literal",
        r#"[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(Z|(\+|\-)[0-9]{2}:[0-9]{2})"#,Token::code_token,
        None,
        |_| true,
        LexMatcherConfig {
        subdivider: None,
        trim_post_subdivide: None,
        trim_start: None,
        trim_chars: None,
        quoted_value: None,
        escape_replacements: None,
        casefold: CaseFold::None,
        kwarg_type: None,
    },
    ),

    LexMatcher::regex_lexer(
        "date_literal",
        r#"[0-9]{4}-[0-9]{2}-[0-9]{2}"#,Token::code_token,
        None,
        |_| true,
        LexMatcherConfig {
        subdivider: None,
        trim_post_subdivide: None,
        trim_start: None,
        trim_chars: None,
        quoted_value: None,
        escape_replacements: None,
        casefold: CaseFold::None,
        kwarg_type: None,
    },
    ),

    LexMatcher::regex_lexer(
        "numeric_literal",
        r#"(?>\d+\.\d+|\d+\.(?![\.\w])|\.\d+|\d+)(\.?[eE][+-]?\d+)?((?<=\.)|(?=\b))"#,Token::literal_token,
        None,
        |input| input.starts_with(['x','X','.','0','1','2','3','4','5','6','7','8','9', '-', '+', '$', '¢', '£', '¤', '¥', '৲', '৳', '฿', '៛', '₠', '₡', '₢', '₣', '₤', '₥', '₦', '₧', '₨', '₩', '₪', '₫', '€', '₭', '₮', '₯', '₰', '₱', '﹩', '＄', '￠', '￡', '￥', '￦']),
        LexMatcherConfig {
        subdivider: None,
        trim_post_subdivide: None,
        trim_start: None,
        trim_chars: None,
        quoted_value: None,
        escape_replacements: None,
        casefold: CaseFold::None,
        kwarg_type: None,
    },
    ),

    LexMatcher::regex_lexer(
        "obevo_annotation",
        r#"////\s*(CHANGE|BODY|METADATA)[^\n]*"#,Token::comment_token,
        None,
        |_| true,
        LexMatcherConfig {
        subdivider: None,
        trim_post_subdivide: None,
        trim_start: None,
        trim_chars: None,
        quoted_value: None,
        escape_replacements: None,
        casefold: CaseFold::None,
        kwarg_type: None,
    },
    ),

    LexMatcher::string_lexer(
        "glob_operator",
        "~~~",Token::comparison_operator_token,
        LexMatcherConfig {
        subdivider: None,
        trim_post_subdivide: None,
        trim_start: None,
        trim_chars: None,
        quoted_value: None,
        escape_replacements: None,
        casefold: CaseFold::None,
        kwarg_type: None,
    },
    ),

    LexMatcher::regex_lexer(
        "like_operator",
        r#"!?~~?\*?"#,Token::comparison_operator_token,
        None,
        |_| true,
        LexMatcherConfig {
        subdivider: None,
        trim_post_subdivide: None,
        trim_start: None,
        trim_chars: None,
        quoted_value: None,
        escape_replacements: None,
        casefold: CaseFold::None,
        kwarg_type: None,
    },
    ),

    LexMatcher::regex_lexer(
        "newline",
        r#"\r\n|\n"#,Token::newline_token,
        None,
        |_| true,
        LexMatcherConfig {
        subdivider: None,
        trim_post_subdivide: None,
        trim_start: None,
        trim_chars: None,
        quoted_value: None,
        escape_replacements: None,
        casefold: CaseFold::None,
        kwarg_type: None,
    },
    ),

    LexMatcher::string_lexer(
        "casting_operator",
        "::",Token::code_token,
        LexMatcherConfig {
        subdivider: None,
        trim_post_subdivide: None,
        trim_start: None,
        trim_chars: None,
        quoted_value: None,
        escape_replacements: None,
        casefold: CaseFold::None,
        kwarg_type: None,
    },
    ),

    LexMatcher::string_lexer(
        "equals",
        "=",Token::code_token,
        LexMatcherConfig {
        subdivider: None,
        trim_post_subdivide: None,
        trim_start: None,
        trim_chars: None,
        quoted_value: None,
        escape_replacements: None,
        casefold: CaseFold::None,
        kwarg_type: None,
    },
    ),

    LexMatcher::string_lexer(
        "greater_than",
        ">",Token::code_token,
        LexMatcherConfig {
        subdivider: None,
        trim_post_subdivide: None,
        trim_start: None,
        trim_chars: None,
        quoted_value: None,
        escape_replacements: None,
        casefold: CaseFold::None,
        kwarg_type: None,
    },
    ),

    LexMatcher::string_lexer(
        "less_than",
        "<",Token::code_token,
        LexMatcherConfig {
        subdivider: None,
        trim_post_subdivide: None,
        trim_start: None,
        trim_chars: None,
        quoted_value: None,
        escape_replacements: None,
        casefold: CaseFold::None,
        kwarg_type: None,
    },
    ),

    LexMatcher::string_lexer(
        "not",
        "!",Token::code_token,
        LexMatcherConfig {
        subdivider: None,
        trim_post_subdivide: None,
        trim_start: None,
        trim_chars: None,
        quoted_value: None,
        escape_replacements: None,
        casefold: CaseFold::None,
        kwarg_type: None,
    },
    ),

    LexMatcher::string_lexer(
        "dot",
        ".",Token::code_token,
        LexMatcherConfig {
        subdivider: None,
        trim_post_subdivide: None,
        trim_start: None,
        trim_chars: None,
        quoted_value: None,
        escape_replacements: None,
        casefold: CaseFold::None,
        kwarg_type: None,
    },
    ),

    LexMatcher::string_lexer(
        "comma",
        ",",Token::code_token,
        LexMatcherConfig {
        subdivider: None,
        trim_post_subdivide: None,
        trim_start: None,
        trim_chars: None,
        quoted_value: None,
        escape_replacements: None,
        casefold: CaseFold::None,
        kwarg_type: None,
    },
    ),

    LexMatcher::string_lexer(
        "plus",
        "+",Token::code_token,
        LexMatcherConfig {
        subdivider: None,
        trim_post_subdivide: None,
        trim_start: None,
        trim_chars: None,
        quoted_value: None,
        escape_replacements: None,
        casefold: CaseFold::None,
        kwarg_type: None,
    },
    ),

    LexMatcher::string_lexer(
        "minus",
        "-",Token::code_token,
        LexMatcherConfig {
        subdivider: None,
        trim_post_subdivide: None,
        trim_start: None,
        trim_chars: None,
        quoted_value: None,
        escape_replacements: None,
        casefold: CaseFold::None,
        kwarg_type: None,
    },
    ),

    LexMatcher::string_lexer(
        "divide",
        "/",Token::code_token,
        LexMatcherConfig {
        subdivider: None,
        trim_post_subdivide: None,
        trim_start: None,
        trim_chars: None,
        quoted_value: None,
        escape_replacements: None,
        casefold: CaseFold::None,
        kwarg_type: None,
    },
    ),

    LexMatcher::string_lexer(
        "percent",
        "%",Token::code_token,
        LexMatcherConfig {
        subdivider: None,
        trim_post_subdivide: None,
        trim_start: None,
        trim_chars: None,
        quoted_value: None,
        escape_replacements: None,
        casefold: CaseFold::None,
        kwarg_type: None,
    },
    ),

    LexMatcher::string_lexer(
        "question",
        "?",Token::code_token,
        LexMatcherConfig {
        subdivider: None,
        trim_post_subdivide: None,
        trim_start: None,
        trim_chars: None,
        quoted_value: None,
        escape_replacements: None,
        casefold: CaseFold::None,
        kwarg_type: None,
    },
    ),

    LexMatcher::string_lexer(
        "ampersand",
        "&",Token::code_token,
        LexMatcherConfig {
        subdivider: None,
        trim_post_subdivide: None,
        trim_start: None,
        trim_chars: None,
        quoted_value: None,
        escape_replacements: None,
        casefold: CaseFold::None,
        kwarg_type: None,
    },
    ),

    LexMatcher::string_lexer(
        "vertical_bar",
        "|",Token::code_token,
        LexMatcherConfig {
        subdivider: None,
        trim_post_subdivide: None,
        trim_start: None,
        trim_chars: None,
        quoted_value: None,
        escape_replacements: None,
        casefold: CaseFold::None,
        kwarg_type: None,
    },
    ),

    LexMatcher::string_lexer(
        "caret",
        "^",Token::code_token,
        LexMatcherConfig {
        subdivider: None,
        trim_post_subdivide: None,
        trim_start: None,
        trim_chars: None,
        quoted_value: None,
        escape_replacements: None,
        casefold: CaseFold::None,
        kwarg_type: None,
    },
    ),

    LexMatcher::string_lexer(
        "star",
        "*",Token::code_token,
        LexMatcherConfig {
        subdivider: None,
        trim_post_subdivide: None,
        trim_start: None,
        trim_chars: None,
        quoted_value: None,
        escape_replacements: None,
        casefold: CaseFold::None,
        kwarg_type: None,
    },
    ),

    LexMatcher::string_lexer(
        "start_bracket",
        "(",Token::code_token,
        LexMatcherConfig {
        subdivider: None,
        trim_post_subdivide: None,
        trim_start: None,
        trim_chars: None,
        quoted_value: None,
        escape_replacements: None,
        casefold: CaseFold::None,
        kwarg_type: None,
    },
    ),

    LexMatcher::string_lexer(
        "end_bracket",
        ")",Token::code_token,
        LexMatcherConfig {
        subdivider: None,
        trim_post_subdivide: None,
        trim_start: None,
        trim_chars: None,
        quoted_value: None,
        escape_replacements: None,
        casefold: CaseFold::None,
        kwarg_type: None,
    },
    ),

    LexMatcher::string_lexer(
        "start_square_bracket",
        "[",Token::code_token,
        LexMatcherConfig {
        subdivider: None,
        trim_post_subdivide: None,
        trim_start: None,
        trim_chars: None,
        quoted_value: None,
        escape_replacements: None,
        casefold: CaseFold::None,
        kwarg_type: None,
    },
    ),

    LexMatcher::string_lexer(
        "end_square_bracket",
        "]",Token::code_token,
        LexMatcherConfig {
        subdivider: None,
        trim_post_subdivide: None,
        trim_start: None,
        trim_chars: None,
        quoted_value: None,
        escape_replacements: None,
        casefold: CaseFold::None,
        kwarg_type: None,
    },
    ),

    LexMatcher::string_lexer(
        "start_curly_bracket",
        "{",Token::code_token,
        LexMatcherConfig {
        subdivider: None,
        trim_post_subdivide: None,
        trim_start: None,
        trim_chars: None,
        quoted_value: None,
        escape_replacements: None,
        casefold: CaseFold::None,
        kwarg_type: None,
    },
    ),

    LexMatcher::string_lexer(
        "end_curly_bracket",
        "}",Token::code_token,
        LexMatcherConfig {
        subdivider: None,
        trim_post_subdivide: None,
        trim_start: None,
        trim_chars: None,
        quoted_value: None,
        escape_replacements: None,
        casefold: CaseFold::None,
        kwarg_type: None,
    },
    ),

    LexMatcher::string_lexer(
        "colon",
        ":",Token::code_token,
        LexMatcherConfig {
        subdivider: None,
        trim_post_subdivide: None,
        trim_start: None,
        trim_chars: None,
        quoted_value: None,
        escape_replacements: None,
        casefold: CaseFold::None,
        kwarg_type: None,
    },
    ),

    LexMatcher::string_lexer(
        "semicolon",
        ";",Token::code_token,
        LexMatcherConfig {
        subdivider: None,
        trim_post_subdivide: None,
        trim_start: None,
        trim_chars: None,
        quoted_value: None,
        escape_replacements: None,
        casefold: CaseFold::None,
        kwarg_type: None,
    },
    ),

    LexMatcher::regex_lexer(
        "word",
        r#"[0-9a-zA-Z_]+"#,Token::word_token,
        None,
        |_| true,
        LexMatcherConfig {
        subdivider: None,
        trim_post_subdivide: None,
        trim_start: None,
        trim_chars: None,
        quoted_value: None,
        escape_replacements: None,
        casefold: CaseFold::None,
        kwarg_type: None,
    },
    ),
]});

pub static SOQL_BRACKET_PAIRS: Lazy<BracketPairSet> = Lazy::new(|| { BracketPairSet(vec![
    BracketPairEntry { open: "{", close: "}", start_type: "start_curly_bracket", end_type: "end_curly_bracket", persists: false },
    BracketPairEntry { open: "(", close: ")", start_type: "start_bracket", end_type: "end_bracket", persists: true },
    BracketPairEntry { open: "[", close: "]", start_type: "start_square_bracket", end_type: "end_square_bracket", persists: false },
]) });


// Wrapper function that passes the dialect name to the shared implementation
fn extract_nested_block_comment(input: &str) -> Option<&str> {
    crate::extract_nested_block_comment(input, "soql")
}
