Skip to main content

oak_dhall/
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.
8pub mod ast;
9/// Builder module.
10pub mod builder;
11
12/// Kind definition module.
13/// Language configuration module.
14pub mod language;
15/// Lexer module.
16pub mod lexer;
17/// LSP module.
18#[cfg(any(feature = "lsp", feature = "oak-highlight", feature = "oak-pretty-print"))]
19pub mod lsp;
20
21/// Parser module.
22pub mod parser;
23
24pub use crate::{ast::DHallRoot, builder::DHallBuilder, language::DHallLanguage, lexer::DHallLexer, parser::DHallParser};
25
26/// Parses a Dhall string.
27pub fn parse(dhall: &str) -> Result<crate::ast::DHallRoot, String> {
28    use oak_core::{Builder, parser::session::ParseSession, source::SourceText};
29    let language = DHallLanguage::default();
30    let builder = DHallBuilder::new(&language);
31    let source = SourceText::new(dhall.to_string());
32    let mut cache = ParseSession::default();
33    let result = builder.build(&source, &[], &mut cache);
34    result.result.map_err(|e| format!("{:?}", e))
35}
36
37/// Highlighter implementation.
38#[cfg(feature = "oak-highlight")]
39pub use crate::lsp::highlighter::DHallHighlighter;
40
41#[cfg(feature = "lsp")]
42pub use crate::lsp::DHallLanguageService;
43/// LSP implementation.
44#[cfg(feature = "lsp")]
45pub use crate::lsp::formatter::DHallFormatter;
46
47pub use lexer::token_type::DHallTokenType;
48pub use parser::element_type::DHallElementType;