Skip to content

Commit 4b506c2

Browse files
Adding readme under parser and parser/src
Adding readme files under parser and parser/src to make it faster to figure out the files and what each does.
1 parent 7faab46 commit 4b506c2

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

parser/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# RustPython/parser
2+
3+
This directory has the code for python lexing, parsing and generating Abstract Syntax Trees (AST).
4+
5+
The steps are:
6+
- Lexical analysis: splits the source code into tokens.
7+
- Parsing and generating the AST: transforms those tokens into an AST. Uses `LALRPOP`, a Rust parser generator framework.
8+
9+
This crate is published on [https://docs.rs/rustpython-parser](https://docs.rs/rustpython-parser).
10+
11+
We wrote [a blog post](https://rustpython.github.io/featured/2020/03/11/thing-explainer-parser.html) with screenshots and an explanation to help you understand the steps by seeing them in action.
12+
13+
For more information on LALRPOP, here is a link to the [LALRPOP book](https://github.com/lalrpop/lalrpop).
14+
15+
There is a readme in the `src` folder with the details of each file.
16+
17+
## How to use
18+
19+
For example, one could do this:
20+
```
21+
use rustpython_parser::{parser, ast};
22+
let python_source = "print('Hello world')";
23+
let python_ast = parser::parse_expression(python_source).unwrap();
24+
```

parser/src/README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# RustPython/parser/src
2+
3+
**lib.rs**
4+
This is the crate's root.
5+
6+
**lexer.rs**
7+
This module takes care of lexing python source text. This means source code is translated into separate tokens.
8+
9+
**parser.rs**
10+
A python parsing module. Use this module to parse python code into an AST. There are three ways to parse python code. You could parse a whole program, a single statement, or a single expression.
11+
12+
**ast.rs**
13+
Implements abstract syntax tree (AST) nodes for the python language. Roughly equivalent to [the python AST](https://docs.python.org/3/library/ast.html).
14+
15+
**python.lalrpop**
16+
Python grammar.
17+
18+
**token.rs**
19+
Different token definitions. Loosely based on token.h from CPython source.
20+
21+
**errors.rs**
22+
Define internal parse error types. The goal is to provide a matching and a safe error API, masking errors from LALR.
23+
24+
**fstring.rs**
25+
Format strings.
26+
27+
**function.rs**
28+
Collection of functions for parsing parameters, arguments.
29+
30+
**location.rs**
31+
Datatypes to support source location information.
32+
33+
**mode.rs**
34+
Execution mode check. Allowed modes are `exec`, `eval` or `single`.

0 commit comments

Comments
 (0)