Skip to main content

oak_sql/
lib.rs

1#![doc = include_str!("readme.md")]
2#![feature(new_range_api)]
3#![warn(missing_docs)]
4#![doc(html_logo_url = "https://raw.githubusercontent.com/ygg-lang/oaks/refs/heads/dev/documents/logo.svg")]
5#![doc(html_favicon_url = "https://raw.githubusercontent.com/ygg-lang/oaks/refs/heads/dev/documents/logo.svg")]
6//! SQL support for the Oak language framework.
7
8/// AST module for SQL.
9pub mod ast;
10/// Builder module for SQL.
11pub mod builder;
12
13/// Language configuration module for SQL.
14pub mod language;
15/// Lexer module for SQL.
16pub mod lexer;
17/// LSP module for SQL.
18#[cfg(any(feature = "lsp", feature = "oak-highlight", feature = "oak-pretty-print"))]
19pub mod lsp;
20/// MCP module for SQL.
21#[cfg(feature = "mcp")]
22pub mod mcp;
23
24/// Parser module for SQL.
25pub mod parser;
26
27pub use crate::{
28    ast::SqlRoot,
29    builder::SqlBuilder,
30    language::SqlLanguage,
31    lexer::{
32        SqlLexer,
33        token_type::{SqlTokenType, SqlTokenType as SqlSyntaxKind},
34    },
35    parser::{SqlParser, element_type::SqlElementType},
36};
37
38/// Parses a SQL string.
39pub fn parse(sql: &str) -> Result<crate::ast::SqlRoot, String> {
40    use oak_core::{Builder, parser::session::ParseSession, source::SourceText};
41    let language = SqlLanguage::default();
42    let builder = SqlBuilder::new(&language);
43    let source = SourceText::new(sql.to_string());
44    let mut cache = ParseSession::default();
45    let result = builder.build(&source, &[], &mut cache);
46    result.result.map_err(|e| format!("{:?}", e))
47}
48
49/// Re-export SqlSyntaxKind in a kind module for backward compatibility
50pub mod kind {
51    /// Re-export SqlTokenType as SqlSyntaxKind.
52    pub use crate::lexer::token_type::SqlTokenType as SqlSyntaxKind;
53}
54
55/// Highlighter implementation.
56#[cfg(feature = "oak-highlight")]
57pub use crate::lsp::highlighter::SqlHighlighter;
58
59#[cfg(feature = "lsp")]
60pub use crate::lsp::{SqlLanguageService, formatter::SqlFormatter};