forked from NomicFoundation/slang
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
doc: Add an introduction and a design overview to the user guide
And provide stubs for the How-Tos on parsing/navigating the syntax tree.
- Loading branch information
Showing
11 changed files
with
54 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
- [User Guide](./index.md) | ||
- [Cargo Crate](./cargo-crate/index.md) | ||
- [NPM Package](./npm-package/index.md) | ||
- [Introduction](./introduction.md) | ||
- [Overview](./overview.md) | ||
- [Rust Crate](./rust-crate/) | ||
- [NPM Package](./npm-package/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,14 @@ | ||
# User Guide | ||
|
||
- [Cargo Crate](./cargo-crate/index.md) | ||
Welcome to the Slang user guide! This aims to be an introduction to Slang itself, its concepts and also contains a collection of guides how you can achieve basic tasks with it. | ||
|
||
To get a good grasp on the concepts used in Slang, see the [Overview](./overview.md) section. | ||
|
||
## Distributions | ||
|
||
Slang itself is written in Rust and we maintain a public Rust package on [crates.io](https://crates.io/crates/slang_solidity). At the moment, we also distribute it as an [npm package](https://www.npmjs.com/package/@nomicfoundation/slang) with TypeScript interface. In the future, we plan on expanding the language bindings with Python and possibly more. | ||
|
||
For the guides related to specific distributions, see below: | ||
|
||
- [Rust Crate](./rust-crate/index.md) | ||
- [NPM Package](./npm-package/index.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
## What is Slang? | ||
|
||
Slang is intended to be a modular Solidity compiler, specifically targeting code analysis and developer tooling. This means servicing tools with domain-specific APIs and, in general, facilitating working with and analyzing the Solidity source code. If you're in the editor writing Solidity or performing linting or additional validation, there's a chance that you are, or could be, running Slang! | ||
|
||
## What Slang is not? | ||
|
||
First and foremost, it is not a replacement to `solc`, the standard Solidity compiler. We do not plan at the moment to support emitting EVM bytecode. Secondly, it is not meant to be used for formal verification of contracts or Solidity logic in general. | ||
|
||
## Supporting multiple versions | ||
|
||
Over the years, the Solidity programming language has evolved quite a bit since its inception. Some features were introduced, some changed, while some eventually became obsolete and were removed altogether. | ||
|
||
While it's good for a programming language to evolve and better serve the needs of its users, not being able to easily upgrade or re-deploy existing contracts poses a unique challenge. Older contracts that are still being used on the blockchain, written in older versions of Solidity, must remain understandable during the development process. | ||
|
||
Because of that, Slang must be able to reason about different versions of Solidity - how the language grammar, name binding rules and semantics changed over multiple versions. One of our goals is to document differences as part of our [Solidity Specification](../solidity-specification/index.md). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
- [Index](./index.md) | ||
- [How to parse a Solidity file](./how-to-parse-a-file.md) |
1 change: 1 addition & 0 deletions
1
documentation/public/user-guide/npm-package/how-to-parse-a-file.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--8<-- "crates/solidity/inputs/language/snippets/under-construction.md" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
## Design overview | ||
|
||
At its core, Slang is a collection of APIs that is meant to analyze the source code, starting with the source code itself and ending with a rich structure that can be reasoned about. This is a departure from the classic approach of "black-box" compilers, which are handed the input and only their output can be observed. | ||
|
||
At the time of writing, Slang is capable of parsing the source code into a Concrete Syntax Tree (CST; also sometimes called "full-fidelity"), which is a tree structure of the program that also includes things like punctuation or whitespace. | ||
|
||
This is done by using the (standard) approach of lexical analysis followed by syntax analysis - the source as a sequence of characters is recognized into a sequence of tokens (lexical analysis), which then in turn is _parsed_ into the CST. | ||
|
||
The resulting CST is a regular tree data structure that you can visit. The tree nodes are represented by the [`Node`](https://docs.rs/slang_solidity/latest/slang_solidity/cst/enum.Node.html) structure. _Rule_ nodes (aka _non-terminals_) represent sub-trees, while the _token_ nodes (aka _terminals_) are leaves and represent a lexical token (i.e. an identifier, keyword, punctuation) in the source. | ||
|
||
To help navigate the tree, we define and expose a [`Cursor`](https://docs.rs/slang_solidity/latest/slang_solidity/cursor/struct.Cursor.html) API in both Rust and TypeScript. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
- [Index](./index.md) | ||
- [How to parse a Solidity file](./how-to-parse-a-file.md) |
1 change: 1 addition & 0 deletions
1
documentation/public/user-guide/rust-crate/how-to-parse-a-file.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--8<-- "crates/solidity/inputs/language/snippets/under-construction.md" |
6 changes: 5 additions & 1 deletion
6
...on/public/user-guide/cargo-crate/index.md → ...ion/public/user-guide/rust-crate/index.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters