Created
June 7, 2020 12:29
-
-
Save jugmac00/d2acada18753d5aea1bca6a39e0abd3f to your computer and use it in GitHub Desktop.
add almost equal operator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/Grammar/Grammar b/Grammar/Grammar | |
index 170518af74..25067147bf 100644 | |
--- a/Grammar/Grammar | |
+++ b/Grammar/Grammar | |
@@ -138,7 +138,7 @@ not_test: 'not' not_test | comparison | |
comparison: expr (comp_op expr)* | |
# <> isn't actually a valid comparison operator in Python. It's here for the | |
# sake of a __future__ import described in PEP 401 (which really works :-) | |
-comp_op: '<'|'>'|'=='|'>='|'<='|'<>'|'!='|'in'|'not' 'in'|'is'|'is' 'not' | |
+comp_op: '<'|'>'|'=='|'>='|'<='|'<>'|'!='|'~='|'in'|'not' 'in'|'is'|'is' 'not' | |
star_expr: '*' expr | |
expr: xor_expr ('|' xor_expr)* | |
xor_expr: and_expr ('^' and_expr)* | |
diff --git a/Grammar/Tokens b/Grammar/Tokens | |
index 9de2da5d15..c2451f3964 100644 | |
--- a/Grammar/Tokens | |
+++ b/Grammar/Tokens | |
@@ -53,6 +53,7 @@ ATEQUAL '@=' | |
RARROW '->' | |
ELLIPSIS '...' | |
COLONEQUAL ':=' | |
+ALMOSTEQUAL '~=' |
On page 117 there seems to be another problem - it is written...
Now recompile CPython and open up a REPL to test the command:
>>> a = 1
>>> b = 1.0
>>> a ~= b
True
But further down you can read, that "At this stage, the tokenizer and the AST can parse this code, but the
compiler won’t know how to handle the operator. "
So, I guess, the above snippet should be deleted here - and you just have to compile Python, but do not try the almost equal operator on the REPL - or do.. a funny XKCD message is shown.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So, I think there are three problems with the current version cpython-internals-2020-06-03.pdf and the adding of the almost equal operator
ALMOSTEQUAL '~='
to Grammar/Tokensmake regen-all
(which produces this pyconfig.h problem) instead ofmake regen-grammar
./python -X oldparser