From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Martin Puttke Newsgroups: gmane.emacs.bugs Subject: bug#46817: update python grammar Date: Sat, 27 Feb 2021 19:04:53 +0100 Message-ID: <87im6d5quy.fsf@posteo.de> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="24688"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.5.7; emacs 27.1 To: 46817@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Feb 27 19:10:18 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lG42j-0006JJ-Mc for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 27 Feb 2021 19:10:17 +0100 Original-Received: from localhost ([::1]:33430 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lG42i-0008Uk-PR for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 27 Feb 2021 13:10:16 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:36586) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lG42V-0008UP-Gy for bug-gnu-emacs@gnu.org; Sat, 27 Feb 2021 13:10:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:33770) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lG42U-0005fA-Ll for bug-gnu-emacs@gnu.org; Sat, 27 Feb 2021 13:10:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lG42U-0003CK-FR for bug-gnu-emacs@gnu.org; Sat, 27 Feb 2021 13:10:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Martin Puttke Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 27 Feb 2021 18:10:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 46817 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.161444939212266 (code B ref -1); Sat, 27 Feb 2021 18:10:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 27 Feb 2021 18:09:52 +0000 Original-Received: from localhost ([127.0.0.1]:45316 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lG42J-0003Bm-GD for submit@debbugs.gnu.org; Sat, 27 Feb 2021 13:09:51 -0500 Original-Received: from lists.gnu.org ([209.51.188.17]:34306) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lG3xo-00035X-4N for submit@debbugs.gnu.org; Sat, 27 Feb 2021 13:05:13 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:35998) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lG3xn-0007Fv-Vs for bug-gnu-emacs@gnu.org; Sat, 27 Feb 2021 13:05:12 -0500 Original-Received: from mout02.posteo.de ([185.67.36.66]:47485) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lG3xl-0003Rd-BT for bug-gnu-emacs@gnu.org; Sat, 27 Feb 2021 13:05:11 -0500 Original-Received: from submission (posteo.de [89.146.220.130]) by mout02.posteo.de (Postfix) with ESMTPS id 0349B2400FD for ; Sat, 27 Feb 2021 19:05:05 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.de; s=2017; t=1614449106; bh=RLpgj04L9GVMIWFbP0X1pkwo61BwuPFgT4uSK0peL1E=; h=From:To:Subject:Date:From; b=Dw0RKnTAKyRsvD/HSsYZiSDn0YtWcAgegfbb1ILaEPUvSz0HohY3fx+iDEtolKTJQ jZE5c8Z+hB01H2/VVgvlVnubvVj5GNpgEQv2kb0nQC+Zl9h1MWesXt0fD8c2q8ueZV l8me3BaXuifgTYnIwks9SElljLed3npyET8Afn0eapNeyY627rd/ylQWltlqxumLGZ r33p3lHKD7GGN+lPBuLYExWrp/Gq39mr/XIiUiwZjpDURGfh5I3ztvuZQJpSXgoTjb 9yJ9bp2Nciowrn9V+v1ZiacLUDFsPGKuV6sbFo3KcT5komIumZE3/+O2kp0Uv52IQ8 Fx6Ni10rFqf3A== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4DnvZ91fDtz9rxX for ; Sat, 27 Feb 2021 19:05:05 +0100 (CET) Received-SPF: pass client-ip=185.67.36.66; envelope-from=martinstefanputtke@posteo.de; helo=mout02.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Sat, 27 Feb 2021 13:09:50 -0500 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:200964 Archived-At: --=-=-= Content-Type: text/plain; format=flowed Hi out there, I made some fixes to enhance the python grammar file to enable it to understand python type hints and have non-trivial base classes. Please feel free to include my changes into emacs. please find my patches attached. All the best Martin --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-add-python-grammar-for-type-hints-in-variable-defini.patch >From b5eaf8174267ac466ad3d8be63bae4448f476d16 Mon Sep 17 00:00:00 2001 From: Kapuze Martin Date: Wed, 18 Nov 2020 17:54:22 +0100 Subject: [PATCH 1/3] add python grammar for type hints in variable definitions --- admin/grammars/python.wy | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/admin/grammars/python.wy b/admin/grammars/python.wy index aaa25ced20..b7254e2533 100644 --- a/admin/grammars/python.wy +++ b/admin/grammars/python.wy @@ -1140,7 +1140,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 +1160,15 @@ fpdef ;; | fpdef_list COMMA fpdef ;; ; +type_hint + : ;;EMPTY + | COLON type + ; + +type + : dotted_name + ; + ;; ['=' test] eq_test_opt : ;;EMPTY -- 2.25.1 --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0002-add-python-grammar-for-type-hints-for-function-retur.patch >From 3d8c711acc63bb2e61dfeccb73223ff3bf29b67e Mon Sep 17 00:00:00 2001 From: Kapuze Martin Date: Wed, 18 Nov 2020 18:11:36 +0100 Subject: [PATCH 2/3] add python grammar for type hints for function return value --- admin/grammars/python.wy | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/admin/grammars/python.wy b/admin/grammars/python.wy index b7254e2533..cc5093b0b7 100644 --- a/admin/grammars/python.wy +++ b/admin/grammars/python.wy @@ -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 -- 2.25.1 --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0003-generalize-type-definition-and-apply-it-to-parent-cl.patch >From cf4cd6d4ca1debc6f0b82aa5c9a03a78730980b1 Mon Sep 17 00:00:00 2001 From: Kapuze Martin Date: Mon, 23 Nov 2020 21:56:09 +0100 Subject: [PATCH 3/3] generalize type definition and apply it to parent classes --- admin/grammars/python.wy | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/admin/grammars/python.wy b/admin/grammars/python.wy index cc5093b0b7..bb3d96d703 100644 --- a/admin/grammars/python.wy +++ b/admin/grammars/python.wy @@ -893,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 ; ;;;**************************************************************************** @@ -1172,7 +1172,7 @@ type_hint ; type - : dotted_name + : test ; ;; ['=' test] -- 2.25.1 --=-=-= Content-Type: text/plain; format=flowed -- Composed with Spacemacs (www.spacemacs.org) --=-=-=--