From: Kapuze Martin Date: Sun, 28 Feb 2021 14:21:53 +0000 (+0100) Subject: Enable Python type hints and non-trivial base classes in wisent X-Git-Tag: emacs-28.0.90~3498 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=277a254a42ad4ccf2223eaa788de37279e5e3958;p=emacs.git Enable Python type hints and non-trivial base classes in wisent * admin/grammars/python.wy: Enable understanding Python type hints and non-trivial base classes (bug#46817). Copyright-paperwork-exempt: yes --- diff --git a/admin/grammars/python.wy b/admin/grammars/python.wy index aaa25ced202..9c8f4ac6a9c 100644 --- a/admin/grammars/python.wy +++ b/admin/grammars/python.wy @@ -88,7 +88,7 @@ %package wisent-python-wy %provide semantic/wisent/python-wy -%expectedconflicts 4 +%expectedconflicts 5 %{ (declare-function wisent-python-reconstitute-function-tag @@ -184,6 +184,7 @@ %token ASSIGN "=" %token BACKQUOTE "`" %token AT "@" +%token FOLLOWS "->" ;; ----------------- @@ -808,12 +809,17 @@ decorators ;; funcdef: [decorators] 'def' NAME parameters ':' suite funcdef - : DEF NAME function_parameter_list COLON suite + : DEF NAME function_parameter_list return_type_hint COLON suite (wisent-python-reconstitute-function-tag - (FUNCTION-TAG $2 nil $3) $5) - | decorators DEF NAME function_parameter_list COLON suite + (FUNCTION-TAG $2 nil $3) $6) + | decorators DEF NAME function_parameter_list return_type_hint COLON suite (wisent-python-reconstitute-function-tag - (FUNCTION-TAG $3 nil $4 :decorators $1) $6) + (FUNCTION-TAG $3 nil $4 :decorators $1) $7) + ; + +return_type_hint + : ;;EMPTY + | FOLLOWS type ; function_parameter_list @@ -887,7 +893,7 @@ paren_classes ;; parser can parse general expressions, I don't see much benefit in ;; generating a string of expression as base class "name". paren_class - : dotted_name + : type ; ;;;**************************************************************************** @@ -1140,7 +1146,7 @@ fpdef_opt_test ;; fpdef: NAME | '(' fplist ')' fpdef - : NAME + : NAME type_hint (VARIABLE-TAG $1 nil nil) ;; Below breaks the parser. Don't know why, but my guess is that ;; LPAREN/RPAREN clashes with the ones in function_parameters. @@ -1160,6 +1166,15 @@ fpdef ;; | fpdef_list COMMA fpdef ;; ; +type_hint + : ;;EMPTY + | COLON type + ; + +type + : test + ; + ;; ['=' test] eq_test_opt : ;;EMPTY