Created
          July 21, 2023 14:08 
        
      - 
      
- 
        Save oguzalb/590d034cde3fae9c3bc1c278c687246c to your computer and use it in GitHub Desktop. 
    adding arrow functions to Python grammar
  
        
  
    
      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/Tokens b/Grammar/Tokens | |
| index 618ae81..29bcfeb 100644 | |
| --- a/Grammar/Tokens | |
| +++ b/Grammar/Tokens | |
| @@ -11,6 +11,7 @@ RPAR ')' | |
| LSQB '[' | |
| RSQB ']' | |
| COLON ':' | |
| +FUNC_SIGN '=>' | |
| COMMA ',' | |
| SEMI ';' | |
| PLUS '+' | |
| diff --git a/Grammar/python.gram b/Grammar/python.gram | |
| index c1863ae..337a6d0 100644 | |
| --- a/Grammar/python.gram | |
| +++ b/Grammar/python.gram | |
| @@ -674,6 +674,7 @@ expressions[expr_ty]: | |
| expression[expr_ty] (memo): | |
| | invalid_expression | |
| | invalid_legacy_expression | |
| + | lambarrowdef | |
| | a=disjunction 'if' b=disjunction 'else' c=expression { _PyAST_IfExp(b, a, c, EXTRA) } | |
| | disjunction | |
| | lambdef | |
| @@ -858,6 +859,9 @@ group[expr_ty]: | |
| lambdef[expr_ty]: | |
| | 'lambda' a=[lambda_params] ':' b=expression { | |
| _PyAST_Lambda((a) ? a : CHECK(arguments_ty, _PyPegen_empty_arguments(p)), b, EXTRA) } | |
| +lambarrowdef[expr_ty]: | |
| + | '(' a=[params] ')' '=>' b=expression { | |
| + _PyAST_Lambda((a) ? a : CHECK(arguments_ty, _PyPegen_empty_arguments(p)), b, EXTRA) } | |
| lambda_params[arguments_ty]: | |
| | invalid_lambda_parameters | 
Thank you very much! Nice work. 🔥🤝
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
@angelhdzmultimedia
Hey hi! I was just trying to show people that it's easy to change the Python grammar = ) I don't think this kind of a change will happen.
Though, you are of course free to make the change and play with the arrow functions in local projects! Cheers!