aboutsummaryrefslogtreecommitdiffstats
path: root/admin/grammars/python.wy
diff options
context:
space:
mode:
Diffstat (limited to 'admin/grammars/python.wy')
-rw-r--r--admin/grammars/python.wy64
1 files changed, 56 insertions, 8 deletions
diff --git a/admin/grammars/python.wy b/admin/grammars/python.wy
index f7808fd20b8..f17f41c9b1b 100644
--- a/admin/grammars/python.wy
+++ b/admin/grammars/python.wy
@@ -88,6 +88,12 @@
88;; -------- 88;; --------
89 89
90%package wisent-python-wy 90%package wisent-python-wy
91%provide semantic/wisent/python-wy
92
93%{
94(declare-function wisent-python-reconstitute-function-tag "semantic/wisent/python")
95(declare-function wisent-python-reconstitute-class-tag "semantic/wisent/python")
96}
91 97
92%languagemode python-mode 98%languagemode python-mode
93 99
@@ -173,6 +179,7 @@
173%token <punctuation> COMMA "," 179%token <punctuation> COMMA ","
174%token <punctuation> ASSIGN "=" 180%token <punctuation> ASSIGN "="
175%token <punctuation> BACKQUOTE "`" 181%token <punctuation> BACKQUOTE "`"
182%token <punctuation> AT "@"
176 183
177 184
178;; ----------------- 185;; -----------------
@@ -307,6 +314,10 @@
307%put WHILE summary 314%put WHILE summary
308"Start a 'while' loop" 315"Start a 'while' loop"
309 316
317%keyword WITH "with"
318%put WITH summary
319"Start statement with an associated context object"
320
310%keyword YIELD "yield" 321%keyword YIELD "yield"
311%put YIELD summary 322%put YIELD summary
312"Create a generator function" 323"Create a generator function"
@@ -545,8 +556,10 @@ import_stmt
545 556
546;; dotted_as_name (',' dotted_as_name)* 557;; dotted_as_name (',' dotted_as_name)*
547dotted_as_name_list 558dotted_as_name_list
548 : dotted_as_name 559 : dotted_as_name_list COMMA dotted_as_name
549 | dotted_as_name_list COMMA dotted_as_name 560 (cons $3 $1)
561 | dotted_as_name
562 (list $1)
550 ; 563 ;
551 564
552;; ('*' | import_as_name (',' import_as_name)*) 565;; ('*' | import_as_name (',' import_as_name)*)
@@ -649,6 +662,7 @@ compound_stmt
649 | while_stmt 662 | while_stmt
650 | for_stmt 663 | for_stmt
651 | try_stmt 664 | try_stmt
665 | with_stmt
652 | funcdef 666 | funcdef
653 | class_declaration 667 | class_declaration
654 ; 668 ;
@@ -756,13 +770,46 @@ zero_one_or_two_test
756 ; 770 ;
757 771
758;;;============================================================================ 772;;;============================================================================
773;;@@ with_stmt
774;;;============================================================================
775
776;; with_stmt: 'with' test [ with_var ] ':' suite
777with_stmt
778 : WITH test COLON suite
779 (CODE-TAG $1 nil)
780 | WITH test with_var COLON suite
781 (CODE-TAG $1 nil) ;; TODO capture variable
782 ;
783
784with_var
785 : AS expr
786 () ;; TODO capture
787 ;
788
789;;;============================================================================
759;;;@@ funcdef 790;;;@@ funcdef
760;;;============================================================================ 791;;;============================================================================
761 792
762;; funcdef: 'def' NAME parameters ':' suite 793decorator
794 : AT dotted_name varargslist_opt NEWLINE
795 (FUNCTION-TAG $2 "decorator" $3)
796 ;
797
798decorators
799 : decorator
800 (list $1)
801 | decorator decorators
802 (cons $1 $2)
803 ;
804
805;; funcdef: [decorators] 'def' NAME parameters ':' suite
763funcdef 806funcdef
764 : DEF NAME function_parameter_list COLON suite 807 : DEF NAME function_parameter_list COLON suite
765 (FUNCTION-TAG $2 nil $3) 808 (wisent-python-reconstitute-function-tag
809 (FUNCTION-TAG $2 nil $3) $5)
810 | decorators DEF NAME function_parameter_list COLON suite
811 (wisent-python-reconstitute-function-tag
812 (FUNCTION-TAG $3 nil $4 :decorators $1) $6)
766 ; 813 ;
767 814
768function_parameter_list 815function_parameter_list
@@ -798,10 +845,11 @@ function_parameter
798;; classdef: 'class' NAME ['(' testlist ')'] ':' suite 845;; classdef: 'class' NAME ['(' testlist ')'] ':' suite
799class_declaration 846class_declaration
800 : CLASS NAME paren_class_list_opt COLON suite 847 : CLASS NAME paren_class_list_opt COLON suite
801 (TYPE-TAG $2 $1 ;; Name "class" 848 (wisent-python-reconstitute-class-tag
802 $5 ;; Members 849 (TYPE-TAG $2 $1 ;; Name "class"
803 (cons $3 nil) ;; (SUPERCLASSES . INTERFACES) 850 $5 ;; Members
804 ) 851 (cons $3 nil) ;; (SUPERCLASSES . INTERFACES)
852 ))
805 ; 853 ;
806 854
807;; ['(' testlist ')'] 855;; ['(' testlist ')']