[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 277a254 2/2: Enable Python type hints and non-trivial base classe
From: |
Lars Ingebrigtsen |
Subject: |
master 277a254 2/2: Enable Python type hints and non-trivial base classes in wisent |
Date: |
Sun, 28 Feb 2021 12:20:16 -0500 (EST) |
branch: master
commit 277a254a42ad4ccf2223eaa788de37279e5e3958
Author: Kapuze Martin <m.s.p@posteo.de>
Commit: Lars Ingebrigtsen <larsi@gnus.org>
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
---
admin/grammars/python.wy | 29 ++++++++++++++++++++++-------
1 file changed, 22 insertions(+), 7 deletions(-)
diff --git a/admin/grammars/python.wy b/admin/grammars/python.wy
index aaa25ce..9c8f4ac 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