Skip to main content

oak_fsharp/
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
10/// AST module.
11pub mod ast;
12/// Builder module
13pub mod builder;
14/// Language definition and configuration for F#.
15pub mod language;
16/// Lexer implementation for F#.
17pub mod lexer;
18#[cfg(any(feature = "lsp", feature = "oak-highlight", feature = "oak-pretty-print"))]
19/// LSP module
20pub mod lsp;
21/// Parser module
22pub mod parser;
23
24pub use ast::FSharpRoot;
25pub use builder::FSharpBuilder;
26pub use language::FSharpLanguage;
27pub use lexer::{FSharpLexer, token_type::FSharpTokenType};
28pub use parser::{FSharpParser, element_type::FSharpElementType};
29
30/// Parses F# source code into a [FSharpRoot] AST.
31///
32/// This is a convenience function that initializes the language, builder,
33/// and parser to process the source text.
34///
35/// # Errors
36///
37/// Returns an [oak_core::OakError] if parsing fails.
38pub fn parse(source: &str) -> Result<FSharpRoot, oak_core::OakError> {
39    let language = FSharpLanguage::new();
40    let builder = FSharpBuilder::new(&language);
41    let source_text = oak_core::source::SourceText::new(source);
42    let mut session = oak_core::parser::ParseSession::<FSharpLanguage>::default();
43    let output = builder.build(&source_text, &[], &mut session);
44    output.result
45}
46
47/// LSP implementation.
48#[cfg(feature = "lsp")]
49pub use crate::lsp::FsharpLanguageService;