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