summaryrefslogtreecommitdiff
path: root/admin/grammars/python.wy
diff options
context:
space:
mode:
authorKapuze Martin <m.s.p@posteo.de>2021-02-28 15:21:53 +0100
committerLars Ingebrigtsen <larsi@gnus.org>2021-02-28 18:09:15 +0100
commit277a254a42ad4ccf2223eaa788de37279e5e3958 (patch)
treece1851e5b74450d718b0967c139f0f07695fd3a0 /admin/grammars/python.wy
parent05100407543deef4191ba0453ec4b89ef40dde90 (diff)
downloademacs-277a254a42ad4ccf2223eaa788de37279e5e3958.tar.gz
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
Diffstat (limited to 'admin/grammars/python.wy')
-rw-r--r--admin/grammars/python.wy29
1 files changed, 22 insertions, 7 deletions
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 <punctuation> ASSIGN "="
%token <punctuation> BACKQUOTE "`"
%token <punctuation> AT "@"
+%token <punctuation> 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