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
54 changes: 27 additions & 27 deletions InternalDocs/parser.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,23 +174,23 @@ Grammar expressions

### ``# comment``

Python-style comments.
Python-style comments.

### ``e1 e2``

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

```
rule_name: first_rule second_rule
```

### ``e1 | e2``

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

The first alternative can also appear on the line after the rule name
for formatting purposes. In that case, a \| must be used before the
first alternative, like so:
The first alternative can also appear on the line after the rule name
for formatting purposes. In that case, a \| must be used before the
first alternative, like so:

```
rule_name[return_type]:
Expand All @@ -200,88 +200,88 @@ first alternative, like so:

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

Match ``e``.
Match ``e``.

```
rule_name: (e)
```

A slightly more complex and useful example includes using the grouping
operator together with the repeat operator:
A slightly more complex and useful example includes using the grouping
operator together with the repeat operator:

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

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

Optionally match ``e``.
Optionally match ``e``.

```
rule_name: [e]
```

A more useful example includes defining that a trailing comma is
optional:
A more useful example includes defining that a trailing comma is
optional:

```
rule_name: e (',' e)* [',']
```

### ``e*``

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

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

### ``e+``

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

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

### ``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
``(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
``(e (s e)*)``.

```
rule_name: ','.e+
```

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

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

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

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

An example taken from the Python grammar specifies that a primary
consists of an atom, which is not followed by a ``.`` or a ``(`` or a
``[``:
An example taken from the Python grammar specifies that a primary
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").
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.

the "cut").

```
rule_name: '(' ~ some_rule ')' | some_alt
```

In this example, if a left parenthesis is parsed, then the other
alternative won’t be considered, even if some_rule or ``)`` fail to be
parsed.
In this example, if a left parenthesis is parsed, then the other
alternative won’t be considered, even if some_rule or ``)`` fail to be
parsed.

Left recursion
--------------
Expand Down