X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/678fb7066698ebfe3aecba722294025ed26da01b..59c414b1d0a01acff2bdc5e8ee6b76b0ee5aac3d:/admin/grammars/python.wy diff --git a/admin/grammars/python.wy b/admin/grammars/python.wy index f7808fd20b..9b37a8deae 100644 --- a/admin/grammars/python.wy +++ b/admin/grammars/python.wy @@ -1,6 +1,6 @@ ;;; python.wy -- LALR grammar for Python -;; Copyright (C) 2002-2012 Free Software Foundation, Inc. +;; Copyright (C) 2002-2015 Free Software Foundation, Inc. ;; Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, ;; 2009, 2010 Python Software Foundation; All Rights Reserved @@ -88,6 +88,16 @@ ;; -------- %package wisent-python-wy +%provide semantic/wisent/python-wy + +%{ +(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)) +} %languagemode python-mode @@ -173,6 +183,7 @@ %token COMMA "," %token ASSIGN "=" %token BACKQUOTE "`" +%token AT "@" ;; ----------------- @@ -307,6 +318,10 @@ %put WHILE summary "Start a 'while' loop" +%keyword WITH "with" +%put WITH summary +"Start statement with an associated context object" + %keyword YIELD "yield" %put YIELD summary "Create a generator function" @@ -545,8 +560,10 @@ import_stmt ;; dotted_as_name (',' dotted_as_name)* dotted_as_name_list - : dotted_as_name - | dotted_as_name_list COMMA dotted_as_name + : dotted_as_name_list COMMA dotted_as_name + (cons $3 $1) + | dotted_as_name + (list $1) ; ;; ('*' | import_as_name (',' import_as_name)*) @@ -649,6 +666,7 @@ compound_stmt | while_stmt | for_stmt | try_stmt + | with_stmt | funcdef | class_declaration ; @@ -755,14 +773,47 @@ zero_one_or_two_test () ; +;;;============================================================================ +;;@@ with_stmt +;;;============================================================================ + +;; with_stmt: 'with' test [ with_var ] ':' suite +with_stmt + : WITH test COLON suite + (CODE-TAG $1 nil) + | WITH test with_var COLON suite + (CODE-TAG $1 nil) ;; TODO capture variable + ; + +with_var + : AS expr + () ;; TODO capture + ; + ;;;============================================================================ ;;;@@ funcdef ;;;============================================================================ -;; funcdef: 'def' NAME parameters ':' suite +decorator + : AT dotted_name varargslist_opt NEWLINE + (FUNCTION-TAG $2 "decorator" $3) + ; + +decorators + : decorator + (list $1) + | decorator decorators + (cons $1 $2) + ; + +;; funcdef: [decorators] 'def' NAME parameters ':' suite funcdef : DEF NAME function_parameter_list COLON suite - (FUNCTION-TAG $2 nil $3) + (wisent-python-reconstitute-function-tag + (FUNCTION-TAG $2 nil $3) $5) + | decorators DEF NAME function_parameter_list COLON suite + (wisent-python-reconstitute-function-tag + (FUNCTION-TAG $3 nil $4 :decorators $1) $6) ; function_parameter_list @@ -798,10 +849,11 @@ function_parameter ;; classdef: 'class' NAME ['(' testlist ')'] ':' suite class_declaration : CLASS NAME paren_class_list_opt COLON suite - (TYPE-TAG $2 $1 ;; Name "class" - $5 ;; Members - (cons $3 nil) ;; (SUPERCLASSES . INTERFACES) - ) + (wisent-python-reconstitute-class-tag + (TYPE-TAG $2 $1 ;; Name "class" + $5 ;; Members + (cons $3 nil) ;; (SUPERCLASSES . INTERFACES) + )) ; ;; ['(' testlist ')']