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