8000 gh-119786: Move parser doc from devguide to InternalDocs by iritkatriel · Pull Request #125119 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-119786: Move parser doc from devguide to InternalDocs #125119

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Apply Carrol's suggestions from code review
Co-authored-by: Carol Willing <carolcode@willingconsulting.com>
  • Loading branch information
iritkatriel and willingc authored Oct 8, 2024
commit 6ef9c1180e9a2c8cda5f68790ebd69faa1102f7c
2 changes: 1 addition & 1 deletion InternalDocs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ it is not, please report that through the
[issue tracker](https://github.com/python/cpython/issues).


[Python's Parser](parser.md)
[Guide to the parser](parser.md)

[Compiler Design](compiler.md)

Expand Down
26 changes: 13 additions & 13 deletions InternalDocs/parser.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Therefore, changes to the Python language are made by modifying the
[grammar file](https://github.com/python/cpython/blob/main/Grammar/python.gram).
Developers rarely need to modify the generator itself.

See [Changing CPython’s grammar](https://devguide.python.org/developer-workflow/grammar/#grammar)
See the devguide's [Changing CPython’s grammar](https://devguide.python.org/developer-workflow/grammar/#grammar)
for a detailed description of the grammar and the process for changing it.

How PEG parsers work
Expand All @@ -39,7 +39,7 @@ generate constructions that, given an input string, *deduce* which alternative
check each alternative, in the order in which they are specified, and select
that first one that succeeds.

This means that in a PEG grammer, the choice operator is not commutative.
This means that in a PEG grammar, the choice operator is not commutative.
Furthermore, unlike context-free grammars, the derivation according to a
PEG grammar cannot be ambiguous: if a string parses, it has exactly one
valid parse tree.
Expand Down Expand Up @@ -172,19 +172,19 @@ If the return type is omitted, then a ``void *`` is returned in C and an
Grammar expressions
-------------------

**``# comment``**
### ``# comment``

Python-style comments.

**``e1 e2``**
### ``e1 e2``

Match ``e1``, then match ``e2``.

```
rule_name: first_rule second_rule
```

**``e1 | e2``**
### ``e1 | e2``

Match ``e1`` or ``e2``.

Expand All @@ -198,7 +198,7 @@ first alternative, like so:
| second_alt
```

**``( e )`` (grouping operator)**
### ``( e )`` (grouping operator)

Match ``e``.

Expand All @@ -213,7 +213,7 @@ operator together with the repeat operator:
rule_name: (e1 e2)*
```

**``[ e ] or e?``**
### ``[ e ] or e?``

Optionally match ``e``.

Expand All @@ -228,23 +228,23 @@ optional:
rule_name: e (',' e)* [',']
```

**``e*``**
### ``e*``

Match zero or more occurrences of ``e``.

```
rule_name: (e1 e2)*
```

**``e+``**
### ``e+``

Match one or more occurrences of ``e``.

```
rule_name: (e1 e2)+
```

**``s.e+``**
### ``s.e+``

Match one or more occurrences of ``e``, separated by ``s``. The generated
parse tree does not include the separator. This is otherwise identical to
Expand All @@ -254,11 +254,11 @@ parse tree does not include the separator. This is otherwise identical to
rule_name: ','.e+
```

**``&e`` (positive lookahead)**
### ``&e`` (positive lookahead)

Succeed if ``e`` can be parsed, without consuming any input.

**``!e`` (negative lookahead)**
### ``!e`` (negative lookahead)

Fail if ``e`` can be parsed, without consuming any input.

Expand All @@ -270,7 +270,7 @@ consists of an atom, which is not followed by a ``.`` or a ``(`` or a
primary: atom !'.' !'(' !'['
```

**``~``**
### ``~``

Commit to the current alternative, even if it fails to parse (this is called
the "cut").
Expand Down
0