Skip to content
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

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

Merged
merged 12 commits into from
Oct 9, 2024

Conversation

iritkatriel
Copy link
Member

@iritkatriel iritkatriel commented Oct 8, 2024

  • Copied parser doc from dev guide to the code repo.
  • Converted it from .rst to .md.
  • Minor edits.

Co-Authored-By: Adam Turner [email protected]
Co-Authored-By: Carl Friedrich Bolz-Tereick [email protected]
Co-Authored-By: Carol Willing [email protected]
Co-Authored-By: Erlend E. Aasland [email protected]
Co-Authored-By: Ezio Melotti [email protected]
Co-Authored-By: Hugo van Kemenade [email protected]
Co-Authored-By: Itamar Ostricher [email protected]
Co-Authored-By: Julien Palard [email protected]
Co-Authored-By: Mana [email protected]
Co-Authored-By: Muhammad Mahad [email protected]
Co-Authored-By: Ned Batchelder [email protected]
Co-Authored-By: Pablo Galindo Salgado [email protected]
Co-Authored-By: slateny [email protected]
Co-Authored-By: wookie184 [email protected]

@pablogsal
Copy link
Member

pablogsal commented Oct 8, 2024

Are we also removing this from the devguide? I would be sad to lose the rendered version with admonitions and other graphical features.

@pablogsal
Copy link
Member

Also, this guide and the GC guide have helped plenty of contributors learn how the parser works and I am concerned that moving this to an .md file in the CPython repo will reduce a lot its visibility.

@iritkatriel
Copy link
Member Author

We're moving all the internals documentation to the cpython repository so that (1) it's versioned (2) it gets updated in the same PR as the code.

For now I am replacing the devguide doc by a link to the new place. Eventually the cpython doc will be the single source of truth re internals and people will be directed here from the devguide.

@iritkatriel
Copy link
Member Author

This is the devguide PR for now: python/devguide#1431

At some point the devguide can just point to https://github.com/python/cpython/blob/main/InternalDocs/README.md

@iritkatriel
Copy link
Member Author

I would be sad to lose the rendered version with admonitions and other graphical features.

I tried to preserve the rendering style, with admonitions as block quotes, etc. Is there anything in particular you see that is missing?

@pablogsal
Copy link
Member

I would be sad to lose the rendered version with admonitions and other graphical features.

I tried to preserve the rendering style, with admonitions as block quotes, etc. Is there anything in particular you see that is missing?

No, I think you made a good job translating the document to markdown format, is just that I am a bit worried that this will reduce visibility and readability (raw markdown file vs a rendered webpage). Also, for other docs there were images and reading those in markdown files will a much worse experience.

I don't want to push back strongly on this or hold on this so if you want to land go ahead. I think that moving this to the CPython repo makes sense but I am worried that we are going to sacrifice aspects of the current docs that I still think they are important.

@pablogsal
Copy link
Member

pablogsal commented Oct 8, 2024

For reference, in https://devguide.python.org/internals/garbage-collector/ there are several images that if we move to a markdown file cannot be viewed properly and will have to be opened separately.

I feel that these aspects have not been discussed (or at least I haven't seen the discussion anywhere) and I feel that I didn't had the opportunity to voice my opinion before this work started

@iritkatriel
Copy link
Member Author

When you open a markdown file in GitHub it renders it, you're not reading raw markdown. It will look like this: https://github.com/python/cpython/blob/6b9e52b91ff5ce2327e9372d41e69f253cdb309b/InternalDocs/parser.md

@pablogsal
Copy link
Member

When you open a markdown file in GitHub it renders it, you're not reading raw markdown. It will look like this: https://github.com/python/cpython/blob/6b9e52b91ff5ce2327e9372d41e69f253cdb309b/InternalDocs/parser.md

Ah ok, this looks better than what I was thinking. Will images be rendered inline as well?

@iritkatriel
Copy link
Member Author

Image

@pablogsal
Copy link
Member

Oh, thanks for confirming! My biggest concerns don't apply anymore then. I have reviewed the markdown version with the link and I am happy with it so feel free to land.

Thanks a lot for the patience :)

@iritkatriel
Copy link
Member Author

Thanks!

I'll hold off merging in case I manage to get someone with better markdown foo to review and perhaps make some formatting improvements.

InternalDocs/parser.md Outdated Show resolved Hide resolved
InternalDocs/parser.md Outdated Show resolved Hide resolved
InternalDocs/parser.md Outdated Show resolved Hide resolved
InternalDocs/parser.md Outdated Show resolved Hide resolved
InternalDocs/parser.md Outdated Show resolved Hide resolved
InternalDocs/parser.md Outdated Show resolved Hide resolved
InternalDocs/parser.md Outdated Show resolved Hide resolved
InternalDocs/parser.md Outdated Show resolved Hide resolved
InternalDocs/parser.md Outdated Show resolved Hide resolved
InternalDocs/parser.md Outdated Show resolved Hide resolved
InternalDocs/parser.md Outdated Show resolved Hide resolved
InternalDocs/parser.md Outdated Show resolved Hide resolved
@JacobCoffee
Copy link
Member

Sorry for the noise 😬 thought maybe adding suggestions to batch would make it easier if you chose to accept them

@iritkatriel
Copy link
Member Author

Sorry for the noise 😬 thought maybe adding suggestions to batch would make it easier if you chose to accept them

Yes it normally is! We actually crossed wires in this case, I was make these changes in parallel because @pablogsal just sent me a link about this.

@JacobCoffee
Copy link
Member

JacobCoffee commented Oct 8, 2024

re: grammar expressions as a table, this is a quick and dirty copypasta into columns but wdyt?

| Expression      | Description                                                               | Example                                                                |
|-----------------|---------------------------------------------------------------------------|------------------------------------------------------------------------|
| `# comment`     | Python-style comments                                                     | N/A                                                                    |
| `e1 e2`         | Match `e1`, then match `e2`                                               | `rule_name: first_rule second_rule`                                    |
| `e1 \| e2`      | Match `e1` or `e2`                                                        | `rule_name[return_type]:`<br>`    \| first_alt`<br>`    \| second_alt` |
| `( e )`         | Grouping operator: Match `e`                                              | `rule_name: (e)`<br>`rule_name: (e1 e2)*`                              |
| `[ e ]` or `e?` | Optionally match `e`                                                      | `rule_name: [e]`<br>`rule_name: e (',' e)* [',']`                      |
| `e*`            | Match zero or more occurrences of `e`                                     | `rule_name: (e1 e2)*`                                                  |
| `e+`            | Match one or more occurrences of `e`                                      | `rule_name: (e1 e2)+`                                                  |
| `s.e+`          | Match one or more occurrences of `e`, separated by `s`                    | `rule_name: ','.e+`                                                    |
| `&e`            | Positive lookahead: Succeed if `e` can be parsed, without consuming input | N/A                                                                    |
| `!e`            | Negative lookahead: Fail if `e` can be parsed, without consuming input    | `primary: atom !'.' !'(' !'['`                                         |
| `~`             | Commit to the current alternative, even if it fails to parse (cut)        | `rule_name: '(' ~ some_rule ')' \| some_alt`                           |
Details
Expression Description Example
# comment Python-style comments N/A
e1 e2 Match e1, then match e2 rule_name: first_rule second_rule
e1 | e2 Match e1 or e2 rule_name[return_type]:
| first_alt
| second_alt
( e ) Grouping operator: Match e rule_name: (e)
rule_name: (e1 e2)*
[ e ] or e? Optionally match e rule_name: [e]
rule_name: e (',' e)* [',']
e* Match zero or more occurrences of e rule_name: (e1 e2)*
e+ Match one or more occurrences of e rule_name: (e1 e2)+
s.e+ Match one or more occurrences of e, separated by s rule_name: ','.e+
&e Positive lookahead: Succeed if e can be parsed, without consuming input N/A
!e Negative lookahead: Fail if e can be parsed, without consuming input primary: atom !'.' !'(' !'['
~ Commit to the current alternative, even if it fails to parse (cut) rule_name: '(' ~ some_rule ')' | some_alt

@iritkatriel
Copy link
Member Author

Maybe wrap the longer descriptions into multiple lines?

@pablogsal do you like this?

Copy link
Contributor

@willingc willingc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recommend using H3 level as suggested here since it will allow more granular open/collapse in editors and is easier to read when rendered.

I typically would only have 1 H1 level (the title) and H2 for subsections. Since we are using H1 for subsections here moving them to H2 level would mean all the headings would need to be one lower. I'm not sure that's worth the effort so I left as is.

InternalDocs/README.md Outdated Show resolved Hide resolved
InternalDocs/parser.md Outdated Show resolved Hide resolved
InternalDocs/parser.md Outdated Show resolved Hide resolved
InternalDocs/parser.md Outdated Show resolved Hide resolved
InternalDocs/parser.md Outdated Show resolved Hide resolved
InternalDocs/parser.md Outdated Show resolved Hide resolved
InternalDocs/parser.md Outdated Show resolved Hide resolved
InternalDocs/parser.md Outdated Show resolved Hide resolved
InternalDocs/parser.md Outdated Show resolved Hide resolved
InternalDocs/parser.md Outdated Show resolved Hide resolved
@willingc
Copy link
Contributor

willingc commented Oct 8, 2024

I like @JacobCoffee's table too but I would make it 2 columns (instead of 3) if you go the table route so that the example visually follows the description.


```
primary: atom !'.' !'(' !'['
```

### ``~``

Commit to the current alternative, even if it fails to parse (this is called
the "cut").
Commit to the current alternative, even if it fails to parse (this is called
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice @iritkatriel. It may make sense to have a brief description on line 273 so the ~ stands out a bit more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out these indents are not rendering in markdown as I hoped they would. Maybe table is better.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://gist.github.com/JacobCoffee/5e577dc91115cd401afebd54d0eb1a0b is sort've how 2 columns would look. I don't like that you lose the large chunks of descriptions like we had in ~ (In this example,...), but also didn't like the blob of text in the cell for description being so large. 😬

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's certainly better than what we currently have. I'd remove the " Example:" in each of the boxes.

InternalDocs/parser.md Outdated Show resolved Hide resolved
InternalDocs/parser.md Outdated Show resolved Hide resolved
@pablogsal
Copy link
Member

@pablogsal do you like this?

Yeah, I think it reads nicely

InternalDocs/parser.md Outdated Show resolved Hide resolved
iritkatriel and others added 2 commits October 9, 2024 17:34
@iritkatriel
Copy link
Member Author

Thank you everyone!

@iritkatriel iritkatriel merged commit d501153 into python:main Oct 9, 2024
21 checks passed
@willingc
Copy link
Contributor

willingc commented Oct 9, 2024

Thanks @iritkatriel for making this happen. I do like the 2 column table. Thanks @JacobCoffee.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir skip news
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants