1 ;;; semantic/wisent/python-wy.el --- Generated parser support file
3 ;; Copyright (C) 2002-2013 Free Software Foundation, Inc.
4 ;; Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
5 ;; 2009, 2010 Python Software Foundation; All Rights Reserved
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software: you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation, either version 3 of the License, or
12 ;; (at your option) any later version.
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24 ;; This file was generated from admin/grammars/python.wy.
25 ;; It is derived in part from the Python grammar, used under the
28 ;; PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
29 ;; --------------------------------------------
30 ;; 1. This LICENSE AGREEMENT is between the Python Software Foundation
31 ;; ("PSF"), and the Individual or Organization ("Licensee") accessing
32 ;; and otherwise using this software ("Python") in source or binary
33 ;; form and its associated documentation.
35 ;; 2. Subject to the terms and conditions of this License Agreement,
36 ;; PSF hereby grants Licensee a nonexclusive, royalty-free, world-wide
37 ;; license to reproduce, analyze, test, perform and/or display
38 ;; publicly, prepare derivative works, distribute, and otherwise use
39 ;; Python alone or in any derivative version, provided, however, that
40 ;; PSF's License Agreement and PSF's notice of copyright, i.e.,
41 ;; "Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
42 ;; 2009, 2010 Python Software Foundation; All Rights Reserved" are
43 ;; retained in Python alone or in any derivative version prepared by
46 ;; 3. In the event Licensee prepares a derivative work that is based
47 ;; on or incorporates Python or any part thereof, and wants to make
48 ;; the derivative work available to others as provided herein, then
49 ;; Licensee hereby agrees to include in any such work a brief summary
50 ;; of the changes made to Python.
52 ;; 4. PSF is making Python available to Licensee on an "AS IS"
53 ;; basis. PSF MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR
54 ;; IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, PSF MAKES NO AND
55 ;; DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS
56 ;; FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF PYTHON WILL NOT
57 ;; INFRINGE ANY THIRD PARTY RIGHTS.
59 ;; 5. PSF SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON
60 ;; FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS A
61 ;; RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON, OR
62 ;; ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF.
64 ;; 6. This License Agreement will automatically terminate upon a
65 ;; material breach of its terms and conditions.
67 ;; 7. Nothing in this License Agreement shall be deemed to create any
68 ;; relationship of agency, partnership, or joint venture between PSF
69 ;; and Licensee. This License Agreement does not grant permission to
70 ;; use PSF trademarks or trade name in a trademark sense to endorse or
71 ;; promote products or services of Licensee, or any third party.
73 ;; 8. By copying, installing or otherwise using Python, Licensee
74 ;; agrees to be bound by the terms and conditions of this License
79 (require 'semantic/lex)
80 (eval-when-compile (require 'semantic/bovine))
84 (declare-function wisent-python-reconstitute-function-tag "semantic/wisent/python")
85 (declare-function wisent-python-reconstitute-class-tag "semantic/wisent/python")
89 (defconst wisent-python-wy--keyword-table
90 (semantic-lex-make-keyword-table
96 ("continue" . CONTINUE)
103 ("finally" . FINALLY)
122 '(("yield" summary "Create a generator function")
123 ("with" summary "Start statement with an associated context object")
124 ("while" summary "Start a 'while' loop")
125 ("try" summary "Start of statements protected by exception handlers")
126 ("return" summary "Return from a function")
127 ("raise" summary "Raise an exception")
128 ("print" summary "Print each argument to standard output")
129 ("pass" summary "Statement that does nothing")
130 ("or" summary "Binary logical 'or' operator")
131 ("not" summary "Unary boolean negation operator")
132 ("lambda" summary "Create anonymous function")
133 ("is" summary "Binary operator that tests for object equality")
134 ("in" summary "Part of 'for' statement ")
135 ("import" summary "Load specified modules")
136 ("if" summary "Start 'if' conditional statement")
137 ("global" summary "Declare one or more symbols as global symbols")
138 ("from" summary "Modify behavior of 'import' statement")
139 ("for" summary "Start a 'for' loop")
140 ("finally" summary "Specify code to be executed after 'try' statements whether or not an exception occurred")
141 ("exec" summary "Dynamically execute Python code")
142 ("except" summary "Specify exception handlers along with 'try' keyword")
143 ("else" summary "Start the 'else' clause following an 'if' statement")
144 ("elif" summary "Shorthand for 'else if' following an 'if' statement")
145 ("del" summary "Delete specified objects, i.e., undo what assignment did")
146 ("def" summary "Define a new function")
147 ("continue" summary "Skip to the next iteration of enclosing 'for' or 'while' loop")
148 ("class" summary "Define a new class")
149 ("break" summary "Terminate 'for' or 'while' loop")
150 ("assert" summary "Raise AssertionError exception if <expr> is false")
151 ("as" summary "EXPR as NAME makes value of EXPR available as variable NAME")
152 ("and" summary "Logical AND binary operator ... ")))
153 "Table of language keywords.")
155 (defconst wisent-python-wy--token-table
156 (semantic-lex-make-type-table
212 (BRACK_BLOCK . "(LBRACK RBRACK)")
213 (BRACE_BLOCK . "(LBRACE RBRACE)")
214 (PAREN_BLOCK . "(LPAREN RPAREN)"))
216 (INDENT_BLOCK . "(INDENT DEDENT)")
217 (DEDENT . "[^:INDENT:]")
223 '(("keyword" :declared t)
224 ("symbol" :declared t)
225 ("number" :declared t)
226 ("punctuation" :declared t)
227 ("block" :declared t)))
228 "Table of lexical tokens.")
230 (defconst wisent-python-wy--parse-table
233 (require 'semantic/wisent/comp))
234 (wisent-compile-grammar
235 '((BACKSLASH NEWLINE INDENT DEDENT INDENT_BLOCK PAREN_BLOCK BRACE_BLOCK BRACK_BLOCK LPAREN RPAREN LBRACE RBRACE LBRACK RBRACK LTLTEQ GTGTEQ EXPEQ DIVDIVEQ DIVDIV LTLT GTGT EXPONENT EQ GE LE PLUSEQ MINUSEQ MULTEQ DIVEQ MODEQ AMPEQ OREQ HATEQ LTGT NE HAT LT GT AMP MULT DIV MOD PLUS MINUS PERIOD TILDE BAR COLON SEMICOLON COMMA ASSIGN BACKQUOTE AT STRING_LITERAL NUMBER_LITERAL NAME AND AS ASSERT BREAK CLASS CONTINUE DEF DEL ELIF ELSE EXCEPT EXEC FINALLY FOR FROM GLOBAL IF IMPORT IN IS LAMBDA NOT OR PASS PRINT RAISE RETURN TRY WHILE WITH YIELD)
242 ((small_stmt_list semicolon_opt NEWLINE)))
245 ((small_stmt_list SEMICOLON small_stmt)))
257 ((PRINT print_stmt_trailer)
259 (semantic-tag-new-code $1 nil))))
263 ((GTGT test trailing_test_list_with_opt_comma_opt)
265 (trailing_test_list_with_opt_comma_opt
267 ((trailing_test_list comma_opt)
272 ((trailing_test_list COMMA test)
275 ((testlist expr_stmt_trailer)
279 (string-match "^\\(\\sw\\|\\s_\\)+$" $1))
281 (semantic-tag-new-variable $1 nil nil))
283 (semantic-tag-new-code $1 nil)))))
285 ((augassign testlist))
289 ((eq_testlist_zom ASSIGN testlist)
307 (semantic-tag-new-code $1 nil))))
309 ((expr_list comma_opt)
314 ((expr_list COMMA expr)
319 (semantic-tag-new-code $1 nil))))
329 (semantic-tag-new-code $1 nil))))
333 (semantic-tag-new-code $1 nil))))
335 ((RETURN testlist_opt)
337 (semantic-tag-new-code $1 nil))))
345 (semantic-tag-new-code $1 nil)))
348 (semantic-tag-new-code $1 nil))))
350 ((RAISE zero_one_two_or_three_tests)
352 (semantic-tag-new-code $1 nil))))
353 (zero_one_two_or_three_tests
355 ((test zero_one_or_two_tests)
357 (zero_one_or_two_tests
359 ((COMMA test zero_or_one_comma_test)
361 (zero_or_one_comma_test
366 ((IMPORT dotted_as_name_list)
368 (semantic-tag-new-include $2 nil)))
369 ((FROM dotted_name IMPORT star_or_import_as_name_list)
371 (semantic-tag-new-include $2 nil))))
373 ((dotted_as_name_list COMMA dotted_as_name)
377 (star_or_import_as_name_list
380 ((import_as_name_list)
385 ((import_as_name_list COMMA import_as_name)
391 ((dotted_name as_name_opt)))
398 ((dotted_name PERIOD NAME)
399 (format "%s.%s" $1 $3)))
401 ((GLOBAL comma_sep_name_list)
403 (semantic-tag-new-code $1 nil))))
406 ((comma_sep_name_list COMMA NAME)))
408 ((EXEC expr exec_trailer)
410 (semantic-tag-new-code $1 nil))))
413 ((IN test comma_test_opt)
420 ((ASSERT test comma_test_opt)
422 (semantic-tag-new-code $1 nil))))
430 ((class_declaration)))
432 ((IF test COLON suite elif_suite_pair_list else_suite_pair_opt)
434 (semantic-tag-new-code $1 nil))))
435 (elif_suite_pair_list
437 ((elif_suite_pair_list ELIF test COLON suite)
446 ((NEWLINE indented_block)
450 (semantic-parse-region
453 'indented_block_body 1)))
462 ((WHILE test COLON suite else_suite_pair_opt)
464 (semantic-tag-new-code $1 nil))))
466 ((FOR exprlist IN testlist COLON suite else_suite_pair_opt)
468 (semantic-tag-new-code $1 nil))))
470 ((TRY COLON suite except_clause_suite_pair_list else_suite_pair_opt)
472 (semantic-tag-new-code $1 nil)))
473 ((TRY COLON suite FINALLY COLON suite)
475 (semantic-tag-new-code $1 nil))))
476 (except_clause_suite_pair_list
477 ((except_clause COLON suite)
479 ((except_clause_suite_pair_list except_clause COLON suite)
482 ((EXCEPT zero_one_or_two_test)
484 (zero_one_or_two_test
486 ((test zero_or_one_comma_test)
489 ((WITH test COLON suite)
491 (semantic-tag-new-code $1 nil)))
492 ((WITH test with_var COLON suite)
494 (semantic-tag-new-code $1 nil))))
499 ((AT dotted_name varargslist_opt NEWLINE)
501 (semantic-tag-new-function $2 "decorator" $3))))
505 ((decorator decorators)
508 ((DEF NAME function_parameter_list COLON suite)
509 (wisent-python-reconstitute-function-tag
511 (semantic-tag-new-function $2 nil $3))
513 ((decorators DEF NAME function_parameter_list COLON suite)
514 (wisent-python-reconstitute-function-tag
516 (semantic-tag-new-function $3 nil $4 :decorators $1))
518 (function_parameter_list
521 ((wisent-python-EXPANDING-block t))
522 (semantic-parse-region
525 'function_parameters 1))))
531 ((function_parameter COMMA))
532 ((function_parameter RPAREN)))
537 (semantic-tag-new-variable $2 nil nil)))
540 (semantic-tag-new-variable $2 nil nil))))
542 ((CLASS NAME paren_class_list_opt COLON suite)
543 (wisent-python-reconstitute-class-tag
545 (semantic-tag-new-type $2 $1 $5
547 (paren_class_list_opt
549 ((paren_class_list)))
553 ((wisent-python-EXPANDING-block t))
554 (mapcar 'semantic-tag-name
555 (semantic-parse-region
558 'paren_classes 1)))))
566 (semantic-tag-new-variable $1 nil nil)))
567 ((paren_class RPAREN)
569 (semantic-tag-new-variable $1 nil nil))))
577 ((test_test OR and_test)
581 ((and_test AND not_test)
589 ((comparison comp_op expr)
609 ((xor_expr HAT and_expr)
613 ((and_expr AMP shift_expr)
617 ((shift_expr shift_expr_operators arith_expr)
619 (shift_expr_operators
624 ((arith_expr plus_or_minus term)
631 ((term term_operator factor)
639 ((prefix_operators factor)
647 ((atom trailer_zom exponent_zom)
657 ((trailer_zom trailer)
661 ((exponent_zom EXPONENT factor)
677 ((BACKQUOTE testlist BACKQUOTE)
681 ((one_or_more_string)))
687 ((comma_sep_test_list comma_opt)))
690 ((comma_sep_test_list COMMA test)
691 (format "%s, %s" $1 $3)))
694 ((one_or_more_string STRING_LITERAL)
697 ((LAMBDA varargslist_opt COLON test)
704 ((fpdef_opt_test_list_comma_zom rest_args)
706 ((fpdef_opt_test_list comma_opt)))
708 ((MULT NAME multmult_name_opt)
714 ((COMMA EXPONENT NAME)
716 (semantic-tag-new-variable $3 nil nil))))
717 (fpdef_opt_test_list_comma_zom
719 ((fpdef_opt_test_list_comma_zom fpdef_opt_test COMMA)
723 ((fpdef_opt_test_list COMMA fpdef_opt_test)
726 ((fpdef eq_test_opt)))
730 (semantic-tag-new-variable $1 nil nil))))
732 ((fpdef_list comma_opt)))
735 ((fpdef_list COMMA fpdef)))
746 '(goal function_parameter paren_class indented_block function_parameters paren_classes indented_block_body)))
749 (defun wisent-python-wy--install-parser ()
750 "Setup the Semantic Parser."
751 (semantic-install-function-overrides
752 '((parse-stream . wisent-parse-stream)))
753 (setq semantic-parser-name "LALR"
754 semantic--parse-table wisent-python-wy--parse-table
755 semantic-debug-parser-source "python.wy"
756 semantic-flex-keywords-obarray wisent-python-wy--keyword-table
757 semantic-lex-types-obarray wisent-python-wy--token-table)
758 ;; Collect unmatched syntax lexical tokens
759 (semantic-make-local-hook 'wisent-discarding-token-functions)
760 (add-hook 'wisent-discarding-token-functions
761 'wisent-collect-unmatched-syntax nil t))
766 (define-lex-block-type-analyzer wisent-python-wy--<block>-block-analyzer
767 "block analyzer for <block> tokens."
769 '((("(" LPAREN PAREN_BLOCK)
770 ("{" LBRACE BRACE_BLOCK)
771 ("[" LBRACK BRACK_BLOCK))
777 (define-lex-regex-type-analyzer wisent-python-wy--<symbol>-regexp-analyzer
778 "regexp analyzer for <symbol> tokens."
783 (define-lex-regex-type-analyzer wisent-python-wy--<number>-regexp-analyzer
784 "regexp analyzer for <number> tokens."
785 semantic-lex-number-expression
789 (define-lex-string-type-analyzer wisent-python-wy--<punctuation>-string-analyzer
790 "string analyzer for <punctuation> tokens."
791 "\\(\\s.\\|\\s$\\|\\s'\\)+"
833 (define-lex-keyword-type-analyzer wisent-python-wy--<keyword>-keyword-analyzer
834 "keyword analyzer for <keyword> tokens."
835 "\\(\\sw\\|\\s_\\)+")
841 (provide 'semantic/wisent/python-wy)
843 ;;; semantic/wisent/python-wy.el ends here