summaryrefslogtreecommitdiff
path: root/admin/grammars/python.wy
diff options
context:
space:
mode:
Diffstat (limited to 'admin/grammars/python.wy')
-rw-r--r--admin/grammars/python.wy33
1 files changed, 25 insertions, 8 deletions
diff --git a/admin/grammars/python.wy b/admin/grammars/python.wy
index aaa25ced202..2539d1bec8c 100644
--- a/admin/grammars/python.wy
+++ b/admin/grammars/python.wy
@@ -88,15 +88,17 @@
%package wisent-python-wy
%provide semantic/wisent/python-wy
-%expectedconflicts 4
+%expectedconflicts 5
%{
+(require 'semantic/tag)
(declare-function wisent-python-reconstitute-function-tag
"semantic/wisent/python" (tag suite))
(declare-function wisent-python-reconstitute-class-tag "semantic/wisent/python"
(tag))
(declare-function semantic-parse-region "semantic"
(start end &optional nonterminal depth returnonerror))
+(defvar wisent-python-EXPANDING-block)
}
%languagemode python-mode
@@ -184,6 +186,7 @@
%token <punctuation> ASSIGN "="
%token <punctuation> BACKQUOTE "`"
%token <punctuation> AT "@"
+%token <punctuation> FOLLOWS "->"
;; -----------------
@@ -808,12 +811,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
@@ -865,7 +873,7 @@ paren_class_list_opt
paren_class_list
: PAREN_BLOCK
(let ((wisent-python-EXPANDING-block t))
- (mapcar 'semantic-tag-name (EXPANDFULL $1 paren_classes)))
+ (mapcar #'semantic-tag-name (EXPANDFULL $1 paren_classes)))
;
;; parameters: '(' [varargslist] ')'
@@ -887,7 +895,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 +1148,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 +1168,15 @@ fpdef
;; | fpdef_list COMMA fpdef
;; ;
+type_hint
+ : ;;EMPTY
+ | COLON type
+ ;
+
+type
+ : test
+ ;
+
;; ['=' test]
eq_test_opt
: ;;EMPTY