slang_solidity/
lib.rs

1#![deny(missing_docs)]
2//! Slang is intended to be a modular Solidity compiler, specifically targeting code analysis and developer tooling.
3//! This means servicing tools with domain-specific APIs and, in general, facilitating working with and analyzing the
4//! Solidity source code. If you're in the editor writing Solidity or performing linting or additional validation,
5//! there's a chance that you are, or could be, running Slang!
6//!
7//! # Parsing Solidity Source Code
8//!
9//! ```
10//! use slang_solidity::parser::Parser;
11//! use slang_solidity::utils::LanguageFacts;
12//!
13//! let source = "contract Foo {}";
14//! let parser = Parser::create(LanguageFacts::LATEST_VERSION).unwrap();
15//! let parse_output = parser.parse_file_contents(&source);
16//! ```
17//! # Using the Cursor: Listing Contract Names
18//!
19//! [`Cursors`][`crate::cst::Cursor`] are the simplest way to navigate a CST. The below example shows how you might
20//! use cursors to list all of the contract names in a source file.
21//! ```
22//! // Step 1 (not shown): get a parse tree, for instance with the code above.
23//! # use slang_solidity::cst::NonterminalKind;
24//! # use slang_solidity::parser::Parser;
25//! # use slang_solidity::utils::LanguageFacts;
26//! #
27//! # let source = "contract Foo {}";
28//! # let parser = Parser::create(LanguageFacts::LATEST_VERSION).unwrap();
29//! # let parse_output = parser.parse_file_contents(&source);
30//! // Step 2: Get a cursor
31//! let mut cursor = parse_output.create_tree_cursor();
32//!
33//! // Step 3: Use the cursor to navigate to all `ContractDefinition`'s and print out their names
34//! while cursor.go_to_next_nonterminal_with_kind(NonterminalKind::ContractDefinition) {
35//!     println!("Contract: {}", cursor.node().unparse());
36//! }
37//! ```
38
39pub mod bindings;
40pub mod compilation;
41pub mod cst;
42#[cfg(feature = "__private_ariadne_errors")]
43#[doc(hidden)]
44pub mod diagnostic;
45pub mod parser;
46pub mod utils;
47
48#[cfg(feature = "__private_backend_api")]
49#[doc(hidden)]
50pub mod backend;