|
1 | 1 | # Nodes
|
2 | 2 |
|
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. |
5 | 4 |
|
6 |
| -## Find Errors |
| 5 | +## Error Detection |
7 | 6 |
|
8 |
| -To know if there are some syntactic errors in your code, run: |
| 7 | +To detect syntactic errors in your code, run: |
9 | 8 |
|
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 |
12 | 11 | ```
|
13 | 12 |
|
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). |
22 | 16 |
|
23 |
| -## Count Errors |
| 17 | +This command will find and list all syntax errors in the specified code. |
24 | 18 |
|
25 |
| -It is also possible to count the number of nodes of a certain type using the |
26 |
| -`--count` option: |
| 19 | +## Counting Nodes |
27 | 20 |
|
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> |
30 | 25 | ```
|
| 26 | +This counts how many nodes of the specified type exist in the analyzed files. |
31 | 27 |
|
32 |
| -## Print AST |
| 28 | +## Printing the AST |
33 | 29 |
|
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: |
35 | 31 |
|
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 |
38 | 34 | ```
|
| 35 | +The `-d` flag prints the entire AST, allowing you to inspect the code's syntactic structure. |
39 | 36 |
|
40 |
| -The `-d` option prints the entire AST on the shell. |
41 |
| - |
42 |
| -## Code Splitting |
| 37 | +## Analyzing Code Portions |
43 | 38 |
|
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: |
49 | 40 |
|
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 |
52 | 43 | ```
|
| 44 | + |
| 45 | +This prints the AST of the code between lines 5 and 10, useful for analyzing specific functions or blocks. |
0 commit comments