Skip to main content

oak_csharp/
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
7use oak_core::Builder;
8
9/// AST module containing high-level C# syntax tree definitions.
10pub mod ast;
11/// Builder module for converting green trees into high-level AST nodes.
12pub mod builder;
13/// Language definition and configuration for C#.
14pub mod language;
15/// Lexer implementation for C#.
16pub mod lexer;
17/// LSP-related functionality (hover, completion, highlighting) for C#.
18#[cfg(any(feature = "lsp", feature = "oak-highlight", feature = "oak-pretty-print"))]
19pub mod lsp;
20/// Parser implementation for C#.
21pub mod parser;
22
23pub use ast::CSharpRoot;
24pub use builder::CSharpBuilder;
25pub use language::CSharpLanguage;
26pub use lexer::{CSharpLexer, token_type::CSharpTokenType};
27pub use parser::CSharpParser;
28
29/// Parses C# source code into a [CSharpRoot] AST.
30///
31/// This is a convenience function that initializes the language, builder,
32/// and parser to process the source text.
33///
34/// # Errors
35///
36/// Returns an [oak_core::OakError] if parsing fails.
37pub fn parse(source: &str) -> Result<CSharpRoot, oak_core::OakError> {
38    let language = CSharpLanguage::new();
39    let builder = CSharpBuilder::new(&language);
40    let source_text = oak_core::source::SourceText::new(source);
41    let mut session = oak_core::parser::ParseSession::<CSharpLanguage>::default();
42    let output = builder.build(&source_text, &[], &mut session);
43    output.result
44}
45
46pub use parser::element_type::CSharpElementType;
47
48/// LSP implementation.
49#[cfg(feature = "lsp")]
50pub use crate::lsp::CSharpLanguageService;