From 2cf396c368a188e9142843e566ce6d8e6eb08999 Mon Sep 17 00:00:00 2001 From: Yan Yanchii Date: Sat, 28 Dec 2024 16:05:00 +0100 Subject: [PATCH 1/9] gh-119786: Fix typos in `InternalDocs/parser.md` (#128314) --- InternalDocs/parser.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/InternalDocs/parser.md b/InternalDocs/parser.md index 445b866fc0cb96..be47efe24356d4 100644 --- a/InternalDocs/parser.md +++ b/InternalDocs/parser.md @@ -56,7 +56,7 @@ an input string as its argument, and yields one of the following results: Note that "failure" results do not imply that the program is incorrect, nor do they necessarily mean that the parsing has failed. Since the choice operator is -ordered, a failure very often merely indicates "try the following option". A +ordered, a failure very often merely indicates "try the following option". A direct implementation of a PEG parser as a recursive descent parser will present exponential time performance in the worst case, because PEG parsers have infinite lookahead (this means that they can consider an arbitrary number of @@ -253,7 +253,7 @@ inside curly-braces, which specifies the return value of the alternative: If the action is omitted, a default action is generated: - If there is a single name in the rule, it gets returned. -- If there multiple names in the rule, a collection with all parsed +- If there are multiple names in the rule, a collection with all parsed expressions gets returned (the type of the collection will be different in C and Python). @@ -447,7 +447,7 @@ parser (the one used by the interpreter) just execute: $ make regen-pegen ``` -using the `Makefile` in the main directory. If you are on Windows you can +using the `Makefile` in the main directory. If you are on Windows you can use the Visual Studio project files to regenerate the parser or to execute: ```dos @@ -539,7 +539,7 @@ memoization is used. The C parser used by Python is highly optimized and memoization can be expensive both in memory and time. Although the memory cost is obvious (the parser needs memory for storing previous results in the cache) the execution time cost comes -for continuously checking if the given rule has a cache hit or not. In many +from continuously checking if the given rule has a cache hit or not. In many situations, just parsing it again can be faster. Pegen **disables memoization by default** except for rules with the special marker `memo` after the rule name (and type, if present): @@ -605,7 +605,7 @@ File "", line 1 SyntaxError: invalid syntax ``` -While soft keywords don't have this limitation if used in a context other the +While soft keywords don't have this limitation if used in a context other than one where they are defined as keywords: ```pycon From 5cbf2171aa401b8576c300d62aaded7108443a2b Mon Sep 17 00:00:00 2001 From: HarryLHW <123lhw321@gmail.com> Date: Sat, 28 Dec 2024 23:19:15 +0800 Subject: [PATCH 2/9] Align the grammar of the `Decimal` string constructor with `float`'s --- Doc/library/decimal.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/decimal.rst b/Doc/library/decimal.rst index c9a3e448cad063..bc35f90bbdec9b 100644 --- a/Doc/library/decimal.rst +++ b/Doc/library/decimal.rst @@ -350,12 +350,12 @@ Decimal objects *value* can be an integer, string, tuple, :class:`float`, or another :class:`Decimal` object. If no *value* is given, returns ``Decimal('0')``. If *value* is a string, it should conform to the decimal numeric string syntax after leading - and trailing whitespace characters, as well as underscores throughout, are removed:: + and trailing whitespace characters are removed:: sign ::= '+' | '-' digit ::= '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' indicator ::= 'e' | 'E' - digits ::= digit [digit]... + digits ::= (digit | '_')* digit (digit | '_')* decimal-part ::= digits '.' [digits] | ['.'] digits exponent-part ::= indicator [sign] digits infinity ::= 'Infinity' | 'Inf' From f5468ad80acffdf2094272dc9bfd362c7632fe02 Mon Sep 17 00:00:00 2001 From: HarryLHW <123lhw321@gmail.com> Date: Sat, 28 Dec 2024 23:20:35 +0800 Subject: [PATCH 3/9] Use a production list --- Doc/library/decimal.rst | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/Doc/library/decimal.rst b/Doc/library/decimal.rst index bc35f90bbdec9b..87389943788512 100644 --- a/Doc/library/decimal.rst +++ b/Doc/library/decimal.rst @@ -350,18 +350,19 @@ Decimal objects *value* can be an integer, string, tuple, :class:`float`, or another :class:`Decimal` object. If no *value* is given, returns ``Decimal('0')``. If *value* is a string, it should conform to the decimal numeric string syntax after leading - and trailing whitespace characters are removed:: - - sign ::= '+' | '-' - digit ::= '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' - indicator ::= 'e' | 'E' - digits ::= (digit | '_')* digit (digit | '_')* - decimal-part ::= digits '.' [digits] | ['.'] digits - exponent-part ::= indicator [sign] digits - infinity ::= 'Infinity' | 'Inf' - nan ::= 'NaN' [digits] | 'sNaN' [digits] - numeric-value ::= decimal-part [exponent-part] | infinity - numeric-string ::= [sign] numeric-value | [sign] nan + and trailing whitespace characters are removed: + + .. productionlist:: decimal + sign: "+" | "-" + digit: "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" + indicator: "e" | "E" + digits: (`digit` | "_")* `digit` (`digit` | "_")* + decimalpart: `digits` "." [`digits`] | ["."] `digits` + exponentpart: indicator [sign] digits + infinity: "Infinity" | "Inf" + nan: "NaN" [`digits`] | "sNaN" [`digits`] + numericvalue: `decimalpart` [`exponentpart`] | `infinity` + numericstring: [`sign`] `numericvalue` | [`sign`] `nan` Other Unicode decimal digits are also permitted where ``digit`` appears above. These include decimal digits from various other From b80f68f6a084e493e6f1663b34254ae5737617ab Mon Sep 17 00:00:00 2001 From: HarryLHW <123lhw321@gmail.com> Date: Sun, 29 Dec 2024 00:37:07 +0800 Subject: [PATCH 4/9] Update Doc/library/decimal.rst MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> --- Doc/library/decimal.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/decimal.rst b/Doc/library/decimal.rst index 87389943788512..cac6ac3df950b7 100644 --- a/Doc/library/decimal.rst +++ b/Doc/library/decimal.rst @@ -358,7 +358,7 @@ Decimal objects indicator: "e" | "E" digits: (`digit` | "_")* `digit` (`digit` | "_")* decimalpart: `digits` "." [`digits`] | ["."] `digits` - exponentpart: indicator [sign] digits + exponentpart: `indicator` [`sign`] `digits` infinity: "Infinity" | "Inf" nan: "NaN" [`digits`] | "sNaN" [`digits`] numericvalue: `decimalpart` [`exponentpart`] | `infinity` From 9646cd5a207ad9a09fc5073e5ae3044d09b23194 Mon Sep 17 00:00:00 2001 From: HarryLHW <123lhw321@gmail.com> Date: Sun, 29 Dec 2024 00:41:11 +0800 Subject: [PATCH 5/9] Use `_` to separate words --- Doc/library/decimal.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Doc/library/decimal.rst b/Doc/library/decimal.rst index cac6ac3df950b7..4f4192169fb50c 100644 --- a/Doc/library/decimal.rst +++ b/Doc/library/decimal.rst @@ -357,12 +357,12 @@ Decimal objects digit: "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" indicator: "e" | "E" digits: (`digit` | "_")* `digit` (`digit` | "_")* - decimalpart: `digits` "." [`digits`] | ["."] `digits` - exponentpart: `indicator` [`sign`] `digits` + decimal_part: `digits` "." [`digits`] | ["."] `digits` + exponent_part: `indicator` [`sign`] `digits` infinity: "Infinity" | "Inf" nan: "NaN" [`digits`] | "sNaN" [`digits`] - numericvalue: `decimalpart` [`exponentpart`] | `infinity` - numericstring: [`sign`] `numericvalue` | [`sign`] `nan` + numeric_value: `decimal_part` [`exponent_part`] | `infinity` + numeric_string: [`sign`] `numeric_value` | [`sign`] `nan` Other Unicode decimal digits are also permitted where ``digit`` appears above. These include decimal digits from various other From f263f6d7cf1fefa799b079dfeb51167cd9ff0230 Mon Sep 17 00:00:00 2001 From: HarryLHW <123lhw321@gmail.com> Date: Sun, 29 Dec 2024 01:22:26 +0800 Subject: [PATCH 6/9] revert 'as well as underscores throughout' --- Doc/library/decimal.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/decimal.rst b/Doc/library/decimal.rst index 4f4192169fb50c..4a4044222b2344 100644 --- a/Doc/library/decimal.rst +++ b/Doc/library/decimal.rst @@ -350,7 +350,7 @@ Decimal objects *value* can be an integer, string, tuple, :class:`float`, or another :class:`Decimal` object. If no *value* is given, returns ``Decimal('0')``. If *value* is a string, it should conform to the decimal numeric string syntax after leading - and trailing whitespace characters are removed: + and trailing whitespace characters, as well as underscores throughout, are removed: .. productionlist:: decimal sign: "+" | "-" From 1e13f7c2d19cc2b06b23620f75199b567280e05e Mon Sep 17 00:00:00 2001 From: HarryLHW <123lhw321@gmail.com> Date: Tue, 31 Dec 2024 07:13:21 +0800 Subject: [PATCH 7/9] Revert the grammar change. --- Doc/library/decimal.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/decimal.rst b/Doc/library/decimal.rst index 4a4044222b2344..f47d814641caaa 100644 --- a/Doc/library/decimal.rst +++ b/Doc/library/decimal.rst @@ -356,7 +356,7 @@ Decimal objects sign: "+" | "-" digit: "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" indicator: "e" | "E" - digits: (`digit` | "_")* `digit` (`digit` | "_")* + digits: `digit` [`digit`]... decimal_part: `digits` "." [`digits`] | ["."] `digits` exponent_part: `indicator` [`sign`] `digits` infinity: "Infinity" | "Inf" From 2cd8e6b9e000a820ca390a0db70e729dfff60074 Mon Sep 17 00:00:00 2001 From: HarryLHW <123lhw321@gmail.com> Date: Tue, 31 Dec 2024 22:35:43 +0800 Subject: [PATCH 8/9] Update Doc/library/decimal.rst Co-authored-by: Sergey B Kirpichev --- Doc/library/decimal.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/decimal.rst b/Doc/library/decimal.rst index f47d814641caaa..906b80d856209a 100644 --- a/Doc/library/decimal.rst +++ b/Doc/library/decimal.rst @@ -354,7 +354,7 @@ Decimal objects .. productionlist:: decimal sign: "+" | "-" - digit: "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" + digit: "0"..."9" indicator: "e" | "E" digits: `digit` [`digit`]... decimal_part: `digits` "." [`digits`] | ["."] `digits` From 015abbe0b4489daefd3a170b817c4f5945a4298e Mon Sep 17 00:00:00 2001 From: HarryLHW <123lhw321@gmail.com> Date: Tue, 31 Dec 2024 22:36:07 +0800 Subject: [PATCH 9/9] Update Doc/library/decimal.rst Co-authored-by: Sergey B Kirpichev --- Doc/library/decimal.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/decimal.rst b/Doc/library/decimal.rst index 906b80d856209a..96a4fa9402f412 100644 --- a/Doc/library/decimal.rst +++ b/Doc/library/decimal.rst @@ -356,7 +356,7 @@ Decimal objects sign: "+" | "-" digit: "0"..."9" indicator: "e" | "E" - digits: `digit` [`digit`]... + digits: (`digit`)+ decimal_part: `digits` "." [`digits`] | ["."] `digits` exponent_part: `indicator` [`sign`] `digits` infinity: "Infinity" | "Inf"