lady_deirdre/lib.rs
1////////////////////////////////////////////////////////////////////////////////
2// This file is part of "Lady Deirdre", a compiler front-end foundation //
3// technology. //
4// //
5// This work is proprietary software with source-available code. //
6// //
7// To copy, use, distribute, or contribute to this work, you must agree to //
8// the terms of the General License Agreement: //
9// //
10// https://github.com/Eliah-Lakhin/lady-deirdre/blob/master/EULA.md //
11// //
12// The agreement grants a Basic Commercial License, allowing you to use //
13// this work in non-commercial and limited commercial products with a total //
14// gross revenue cap. To remove this commercial limit for one of your //
15// products, you must acquire a Full Commercial License. //
16// //
17// If you contribute to the source code, documentation, or related materials, //
18// you must grant me an exclusive license to these contributions. //
19// Contributions are governed by the "Contributions" section of the General //
20// License Agreement. //
21// //
22// Copying the work in parts is strictly forbidden, except as permitted //
23// under the General License Agreement. //
24// //
25// If you do not or cannot agree to the terms of this Agreement, //
26// do not use this work. //
27// //
28// This work is provided "as is", without any warranties, express or implied, //
29// except where such disclaimers are legally invalid. //
30// //
31// Copyright (c) 2024 Ilya Lakhin (Илья Александрович Лахин). //
32// All rights reserved. //
33////////////////////////////////////////////////////////////////////////////////
34
35//TODO check warnings regularly
36#![allow(warnings)]
37#![allow(unused_unsafe)]
38#![deny(missing_docs)]
39
40//! # Lady Deirdre API Documentation
41//!
42//! Lady Deirdre is a framework for incremental programming language compilers,
43//! interpreters, and source code analyzers.
44//!
45//! This documentation provides formal API descriptions. For a general
46//! exploration of Lady Deirdre's usage, please refer to the [User Guide](https://lady-deirdre.lakhin.com/).
47//!
48//! ## Getting Started
49//!
50//! To start using Lady Deirdre, add this crate to the dependencies in your
51//! project's Cargo.toml file:
52//!
53//! ```toml
54//! [dependencies.lady-deirdre]
55//! version = "2.0"
56//! ```
57//!
58//! This crate does not have any configuration features or third-party
59//! dependencies, except for the Rust standard library and the accompanying
60//! macro derive crate. Therefore, no additional preparations are needed.
61//!
62//! ## Web Assembly Builds
63//!
64//! The crate can compile and run under WebAssembly targets (including the
65//! `wasm32-unknown-unknown` target) without any extra preparations or setups.
66//!
67//! ## Links
68//!
69//! - [Source Code](https://github.com/Eliah-Lakhin/lady-deirdre)
70//! - [Main Crate](https://crates.io/crates/lady-deirdre)
71//! - [API Documentation](https://docs.rs/lady-deirdre)
72//! - [User Guide](https://lady-deirdre.lakhin.com/)
73//! - [Examples](https://github.com/Eliah-Lakhin/lady-deirdre/tree/master/work/crates/examples)
74//! - [License Agreement](https://github.com/Eliah-Lakhin/lady-deirdre/blob/master/EULA.md)
75//!
76//! ## Copyright
77//!
78//! This work is proprietary software with source-available code.
79//!
80//! To copy, use, distribute, or contribute to this work, you must agree to the
81//! terms and conditions of the [General License Agreement](https://github.com/Eliah-Lakhin/lady-deirdre/blob/master/EULA.md).
82//!
83//! For an explanation of the licensing terms, see the
84//! [F.A.Q.](https://github.com/Eliah-Lakhin/lady-deirdre/tree/master/FAQ.md)
85//!
86//! Copyright (c) 2024 Ilya Lakhin (Илья Александрович Лахин). All rights reserved.
87
88/// Semantic analysis framework.
89///
90/// This framework enables arbitrary on-demand incremental computations over
91/// the set of documents that build up a single compilation project.
92///
93/// The API design of this module mimics Reference Attributed Grammars but uses
94/// the incremental computation algorithm similar to the one used in
95/// [Salsa](https://github.com/salsa-rs/salsa).
96///
97/// You can find the detailed specification of the framework features under the
98/// [Analyzer](analysis::Analyzer) object documentation. This object is an
99/// entry point of the framework.
100pub mod analysis;
101
102/// Memory management utilities.
103///
104/// The primary object of interest is the [Repo](arena::Repo) ("repository").
105///
106/// Repository is a storage of values in the memory allocation. Each value
107/// is associated with a unique key called [Entry](arena::Entry). Keys management
108/// is on the repository side. Insertion, deletion, and borrowing a value from
109/// the Repo by key is a fast O(1) operation.
110///
111/// Repositories are of particular interest for the compilation units, which use
112/// them to store individual syntax tree nodes and the source code tokens
113/// metadata.
114///
115/// You can use the [Repo](arena::Repo) object for various purposes depending
116/// on the needs.
117///
118/// Additionally, the arena module has an [Id](arena::Id) object, instances of
119/// which are globally unique (within the current process) and identify
120/// individual compilation units.
121pub mod arena;
122
123/// Tools for source code formatting and printing.
124///
125/// The [PrettyPrinter](format::PrettyPrinter) objects provides a set
126/// of features to implement source code formatters.
127///
128/// The [Snippet](format::Snippet) is a configurable interface for printing
129/// source code snippets with syntax highlighting and annotated fragments into
130/// the terminal. This interface is useful for printing compiler's
131/// syntax errors.
132///
133/// Finally, this module provides a set of features to stylize terminal strings
134/// within the [TerminalString](format::TerminalString) trait and related
135/// components.
136pub mod format;
137
138/// Building blocks of the lexical structure of compilation units.
139///
140/// This module provides interfaces to describe the lexical component of
141/// your programming language grammar and to access the source code tokens.
142///
143/// - The [Token](lexis::Token) trait implements a lexical scanner of
144/// a particular programming language, and describes individual lexical
145/// tokens.
146/// - The [SourceCode](lexis::SourceCode) trait provides access to individual
147/// tokens, source code text, and other metadata related to the lexical
148/// structure of the compilation unit.
149/// - The [TokenBuffer](lexis::TokenBuffer) object is the default implementation
150/// of the SourceCode. It is capable to scan an ongoing text stream using
151/// specified Token scanner and of storing the produced tokens.
152/// - The [TokenStream](lexis::TokenStream) object is a stateless lexical
153/// scanner with lookahead capabilities. It is recommended for use when the
154/// scanned token stream does not need to be retained.
155///
156/// A detailed specification of the lexical scanning process can be found
157/// under the [LexisSession](lexis::LexisSession) trait.
158pub mod lexis;
159
160/// Synchronization primitives useful for compilers.
161///
162/// These primitives enrich the set of [std::sync] objects, which you may find
163/// useful when implementing a compiler or a language analyzer intended to work
164/// in a multi-thread environment:
165///
166/// - [Shared](sync::Shared) is like an [Arc](std::sync::Arc), but without
167/// the weak counterpart.
168/// - [Lazy](sync::Lazy) is like a Lazy interface from the once_cell crate,
169/// but is built on the recently stabilized [std::sync::OnceLock].
170/// - [Table](sync::Table) is a sharded read-write lock of the hash map.
171/// This object is similar to the DashMap from the dashmap crate.
172/// - [Trigger](sync::Trigger) is an atomic bool flag that you can set only
173/// once to signalize a task to gracefully finish its job.
174pub mod sync;
175
176/// Building blocks of the syntax structure of compilation units.
177///
178/// This module provides interfaces to describe the syntax component of
179/// your programming language grammar and to traverse the syntax trees.
180///
181/// - The [Node](syntax::Node) trait describes the syntax tree's node structure
182/// and provides a parser function for individual nodes.
183/// - The [SyntaxTree](syntax::SyntaxTree) trait provides access to individual
184/// nodes and parse errors, and has functions to traverse the syntax tree.
185/// - The [ImmutableSyntaxTree](syntax::ImmutableSyntaxTree) object is
186/// the default implementation of the SyntaxTree trait. It is capable of
187/// parsing the syntax tree only once during creation and does not provide
188/// incremental reparsing features.
189///
190/// A detailed specification of the syntax parsing process can be found
191/// under the [SyntaxSession](syntax::SyntaxSession) trait.
192pub mod syntax;
193
194/// A set of objects to manage individual compilation units in memory.
195///
196/// The primary object of interest is the [Document](units::Document).
197///
198/// This object contains the content of a single file within your compilation
199/// project and offers methods to read the lexical and syntax structure of
200/// the content, as well as methods to apply user-input changes to the file.
201/// The Document automatically reparses all incoming changes and ensures that
202/// the lexical and syntax structure remains up to date with its text content.
203///
204/// Additionally, the Document provides interfaces to track changes in the
205/// content structure.
206///
207/// The remaining module interfaces serve as the building blocks of
208/// the Document, which you can utilize independently depending on your needs.
209pub mod units;
210
211mod mem;
212mod report;
213
214extern crate self as lady_deirdre;