Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit bf67833

Browse files
committedSep 18, 2024
docs: mozilla#377 update mdbook nodes info
- updated nodes information - specified the usage of the cli and the flags related to AST
1 parent f43652b commit bf67833

File tree

1 file changed

+26
-33
lines changed
  • rust-code-analysis-book/src/commands

1 file changed

+26
-33
lines changed
 
+26-33
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,45 @@
11
# Nodes
22

3-
**rust-code-analysis-cli** allows to extract some information from the nodes
4-
which compose the *Abstract Syntax Tree (AST)* of a source code.
3+
The rust-code-analysis-cli provides commands to analyze and extract information from the nodes in the **AST** of a source file.
54

6-
## Find Errors
5+
## Error Detection
76

8-
To know if there are some syntactic errors in your code, run:
7+
To detect syntactic errors in your code, run:
98

10-
```console
11-
rust-code-analysis-cli -p /path/to/your/file/or/directory -I "*.ext" -f -error
9+
```bash
10+
rust-code-analysis-cli -p /path/to/file/or/directory -I "*.ext" -f error
1211
```
1312

14-
The `-p` option represents the path to a file or a directory. If a directory is
15-
passed as input, **rust-code-analysis-cli** computes the metrics for each file
16-
contained in it.
17-
The `-I` option is a glob filter used to consider only the files written in
18-
the language defined by the extension of the file.
19-
The `-f` option instead searches all nodes of a certain type.
20-
In the case above, we are looking for all the erroneous nodes present in the
21-
code.
13+
- `-p`: Path to a file or directory (analyzes all files in the directory).
14+
- `-I`: Glob filter for selecting files by extension (e.g., `*.js`, `*.rs`).
15+
- `-f`: Flag to search for nodes of a specific type (e.g., errors).
2216

23-
## Count Errors
17+
This command will find and list all syntax errors in the specified code.
2418

25-
It is also possible to count the number of nodes of a certain type using the
26-
`--count` option:
19+
## Counting Nodes
2720

28-
```console
29-
rust-code-analysis-cli -p /path/to/your/file/or/directory -I "*.ext" --count -error
21+
You can count the number of specific node types in your code by using the `--count` flag:
22+
23+
```bash
24+
rust-code-analysis-cli -p /path/to/file/or/directory -I "*.ext" --count <NODE_TYPE>
3025
```
26+
This counts how many nodes of the specified type exist in the analyzed files.
3127

32-
## Print AST
28+
## Printing the AST
3329

34-
If you want to print the AST of a source code, run the following command:
30+
To visualize the AST of a source file, use the `--dump` flag:
3531

36-
```console
37-
rust-code-analysis-cli -p /path/to/your/file/or/directory -d
32+
```bash
33+
rust-code-analysis-cli -p /path/to/file/or/directory -I "*.ext" --dump
3834
```
35+
The `-d` flag prints the entire AST, allowing you to inspect the code's syntactic structure.
3936

40-
The `-d` option prints the entire AST on the shell.
41-
42-
## Code Splitting
37+
## Analyzing Code Portions
4338

44-
Commands can be run on a single portion of the code using the `--ls`
45-
and `--le` options. The former represents the starting line of the code to be
46-
considered, while the latter its ending line.
47-
For example, if we want to print the AST of a single function which starts at
48-
line 5 and ends at line 10, we need to launch this command:
39+
To analyze only a specific part of the code, use the `--ls` (line start) and `--le` (line end) options:
4940

50-
```console
51-
rust-code-analysis-cli -p /path/to/your/file/or/directory -d --ls 5 --le 10
41+
```bash
42+
rust-code-analysis-cli -p /path/to/file/or/directory -d --ls 5 --le 10
5243
```
44+
45+
This prints the AST of the code between lines 5 and 10, useful for analyzing specific functions or blocks.

0 commit comments

Comments
 (0)
Please sign in to comment.