1 ;;; semantic/wisent/python-wy.el --- Generated parser support file
3 ;; Copyright (C) 2002-2004, 2007, 2010-2011 Free Software Foundation, Inc.
4 ;; Copyright (C) 2001-2010 Python Software Foundation
6 ;; This file is part of GNU Emacs.
8 ;; GNU Emacs is free software: you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation, either version 3 of the License, or
11 ;; (at your option) any later version.
13 ;; GNU Emacs is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23 ;; This file was generated from admin/grammars/python.wy.
24 ;; It is derived in part from the Python grammar, used under the
27 ;; PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
28 ;; --------------------------------------------
29 ;; 1. This LICENSE AGREEMENT is between the Python Software Foundation
30 ;; ("PSF"), and the Individual or Organization ("Licensee") accessing
31 ;; and otherwise using this software ("Python") in source or binary
32 ;; form and its associated documentation.
34 ;; 2. Subject to the terms and conditions of this License Agreement,
35 ;; PSF hereby grants Licensee a nonexclusive, royalty-free, world-wide
36 ;; license to reproduce, analyze, test, perform and/or display
37 ;; publicly, prepare derivative works, distribute, and otherwise use
38 ;; Python alone or in any derivative version, provided, however, that
39 ;; PSF's License Agreement and PSF's notice of copyright, i.e.,
40 ;; "Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
41 ;; 2009, 2010 Python Software Foundation; All Rights Reserved" are
42 ;; retained in Python alone or in any derivative version prepared by
45 ;; 3. In the event Licensee prepares a derivative work that is based
46 ;; on or incorporates Python or any part thereof, and wants to make
47 ;; the derivative work available to others as provided herein, then
48 ;; Licensee hereby agrees to include in any such work a brief summary
49 ;; of the changes made to Python.
51 ;; 4. PSF is making Python available to Licensee on an "AS IS"
52 ;; basis. PSF MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR
53 ;; IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, PSF MAKES NO AND
54 ;; DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS
55 ;; FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF PYTHON WILL NOT
56 ;; INFRINGE ANY THIRD PARTY RIGHTS.
58 ;; 5. PSF SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON
59 ;; FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS A
60 ;; RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON, OR
61 ;; ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF.
63 ;; 6. This License Agreement will automatically terminate upon a
64 ;; material breach of its terms and conditions.
66 ;; 7. Nothing in this License Agreement shall be deemed to create any
67 ;; relationship of agency, partnership, or joint venture between PSF
68 ;; and Licensee. This License Agreement does not grant permission to
69 ;; use PSF trademarks or trade name in a trademark sense to endorse or
70 ;; promote products or services of Licensee, or any third party.
72 ;; 8. By copying, installing or otherwise using Python, Licensee
73 ;; agrees to be bound by the terms and conditions of this License
78 (require 'semantic/lex)
85 (defconst wisent-python-wy--keyword-table
86 (semantic-lex-make-keyword-table
92 ("continue" . CONTINUE)
117 '(("yield" summary "Create a generator function")
118 ("while" summary "Start a 'while' loop")
119 ("try" summary "Start of statements protected by exception handlers")
120 ("return" summary "Return from a function")
121 ("raise" summary "Raise an exception")
122 ("print" summary "Print each argument to standard output")
123 ("pass" summary "Statement that does nothing")
124 ("or" summary "Binary logical 'or' operator")
125 ("not" summary "Unary boolean negation operator")
126 ("lambda" summary "Create anonymous function")
127 ("is" summary "Binary operator that tests for object equality")
128 ("in" summary "Part of 'for' statement ")
129 ("import" summary "Load specified modules")
130 ("if" summary "Start 'if' conditional statement")
131 ("global" summary "Declare one or more symbols as global symbols")
132 ("from" summary "Modify behavior of 'import' statement")
133 ("for" summary "Start a 'for' loop")
134 ("finally" summary "Specify code to be executed after 'try' statements whether or not an exception occurred")
135 ("exec" summary "Dynamically execute Python code")
136 ("except" summary "Specify exception handlers along with 'try' keyword")
137 ("else" summary "Start the 'else' clause following an 'if' statement")
138 ("elif" summary "Shorthand for 'else if' following an 'if' statement")
139 ("del" summary "Delete specified objects, i.e., undo what assignment did")
140 ("def" summary "Define a new function")
141 ("continue" summary "Skip to the next iteration of enclosing 'for' or 'while' loop")
142 ("class" summary "Define a new class")
143 ("break" summary "Terminate 'for' or 'while' loop")
144 ("assert" summary "Raise AssertionError exception if <expr> is false")
145 ("as" summary "EXPR as NAME makes value of EXPR available as variable NAME")
146 ("and" summary "Logical AND binary operator ... ")))
147 "Table of language keywords.")
149 (defconst wisent-python-wy--token-table
150 (semantic-lex-make-type-table
205 (BRACK_BLOCK . "(LBRACK RBRACK)")
206 (BRACE_BLOCK . "(LBRACE RBRACE)")
207 (PAREN_BLOCK . "(LPAREN RPAREN)"))
209 (INDENT_BLOCK . "(INDENT DEDENT)")
210 (DEDENT . "[^:INDENT:]")
216 '(("keyword" :declared t)
217 ("symbol" :declared t)
218 ("number" :declared t)
219 ("punctuation" :declared t)
220 ("block" :declared t)))
221 "Table of lexical tokens.")
223 (defconst wisent-python-wy--parse-table
226 (require 'semantic/wisent/comp))
227 (wisent-compile-grammar
228 '((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 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 YIELD)
235 ((small_stmt_list semicolon_opt NEWLINE)))
238 ((small_stmt_list SEMICOLON small_stmt)))
250 ((PRINT print_stmt_trailer)
252 (semantic-tag-new-code $1 nil))))
256 ((GTGT test trailing_test_list_with_opt_comma_opt)
258 (trailing_test_list_with_opt_comma_opt
260 ((trailing_test_list comma_opt)
265 ((trailing_test_list COMMA test)
268 ((testlist expr_stmt_trailer)
272 (string-match "^\\(\\sw\\|\\s_\\)+$" $1))
274 (semantic-tag-new-variable $1 nil nil))
276 (semantic-tag-new-code $1 nil)))))
278 ((augassign testlist))
282 ((eq_testlist_zom ASSIGN testlist)
300 (semantic-tag-new-code $1 nil))))
302 ((expr_list comma_opt)
307 ((expr_list COMMA expr)
312 (semantic-tag-new-code $1 nil))))
322 (semantic-tag-new-code $1 nil))))
326 (semantic-tag-new-code $1 nil))))
328 ((RETURN testlist_opt)
330 (semantic-tag-new-code $1 nil))))
338 (semantic-tag-new-code $1 nil)))
341 (semantic-tag-new-code $1 nil))))
343 ((RAISE zero_one_two_or_three_tests)
345 (semantic-tag-new-code $1 nil))))
346 (zero_one_two_or_three_tests
348 ((test zero_one_or_two_tests)
350 (zero_one_or_two_tests
352 ((COMMA test zero_or_one_comma_test)
354 (zero_or_one_comma_test
359 ((IMPORT dotted_as_name_list)
361 (semantic-tag-new-include $2 nil)))
362 ((FROM dotted_name IMPORT star_or_import_as_name_list)
364 (semantic-tag-new-include $2 nil))))
367 ((dotted_as_name_list COMMA dotted_as_name)))
368 (star_or_import_as_name_list
371 ((import_as_name_list)
376 ((import_as_name_list COMMA import_as_name)
382 ((dotted_name as_name_opt)))
389 ((dotted_name PERIOD NAME)
390 (format "%s.%s" $1 $3)))
392 ((GLOBAL comma_sep_name_list)
394 (semantic-tag-new-code $1 nil))))
397 ((comma_sep_name_list COMMA NAME)))
399 ((EXEC expr exec_trailer)
401 (semantic-tag-new-code $1 nil))))
404 ((IN test comma_test_opt)
411 ((ASSERT test comma_test_opt)
413 (semantic-tag-new-code $1 nil))))
420 ((class_declaration)))
422 ((IF test COLON suite elif_suite_pair_list else_suite_pair_opt)
424 (semantic-tag-new-code $1 nil))))
425 (elif_suite_pair_list
427 ((elif_suite_pair_list ELIF test COLON suite)
436 ((NEWLINE indented_block)
440 (semantic-parse-region
443 'indented_block_body 1)))
452 ((WHILE test COLON suite else_suite_pair_opt)
454 (semantic-tag-new-code $1 nil))))
456 ((FOR exprlist IN testlist COLON suite else_suite_pair_opt)
458 (semantic-tag-new-code $1 nil))))
460 ((TRY COLON suite except_clause_suite_pair_list else_suite_pair_opt)
462 (semantic-tag-new-code $1 nil)))
463 ((TRY COLON suite FINALLY COLON suite)
465 (semantic-tag-new-code $1 nil))))
466 (except_clause_suite_pair_list
467 ((except_clause COLON suite)
469 ((except_clause_suite_pair_list except_clause COLON suite)
472 ((EXCEPT zero_one_or_two_test)
474 (zero_one_or_two_test
476 ((test zero_or_one_comma_test)
479 ((DEF NAME function_parameter_list COLON suite)
481 (semantic-tag-new-function $2 nil $3))))
482 (function_parameter_list
485 ((wisent-python-EXPANDING-block t))
486 (semantic-parse-region
489 'function_parameters 1))))
495 ((function_parameter COMMA))
496 ((function_parameter RPAREN)))
501 (semantic-tag-new-variable $2 nil nil)))
504 (semantic-tag-new-variable $2 nil nil))))
506 ((CLASS NAME paren_class_list_opt COLON suite)
508 (semantic-tag-new-type $2 $1 $5
510 (paren_class_list_opt
512 ((paren_class_list)))
516 ((wisent-python-EXPANDING-block t))
517 (mapcar 'semantic-tag-name
518 (semantic-parse-region
521 'paren_classes 1)))))
529 (semantic-tag-new-variable $1 nil nil)))
530 ((paren_class RPAREN)
532 (semantic-tag-new-variable $1 nil nil))))
540 ((test_test OR and_test)
544 ((and_test AND not_test)
552 ((comparison comp_op expr)
572 ((xor_expr HAT and_expr)
576 ((and_expr AMP shift_expr)
580 ((shift_expr shift_expr_operators arith_expr)
582 (shift_expr_operators
587 ((arith_expr plus_or_minus term)
594 ((term term_operator factor)
602 ((prefix_operators factor)
610 ((atom trailer_zom exponent_zom)
620 ((trailer_zom trailer)
624 ((exponent_zom EXPONENT factor)
640 ((BACKQUOTE testlist BACKQUOTE)
644 ((one_or_more_string)))
650 ((comma_sep_test_list comma_opt)))
653 ((comma_sep_test_list COMMA test)
654 (format "%s, %s" $1 $3)))
657 ((one_or_more_string STRING_LITERAL)
660 ((LAMBDA varargslist_opt COLON test)
667 ((fpdef_opt_test_list_comma_zom rest_args)
669 ((fpdef_opt_test_list comma_opt)))
671 ((MULT NAME multmult_name_opt)
677 ((COMMA EXPONENT NAME)
679 (semantic-tag-new-variable $3 nil nil))))
680 (fpdef_opt_test_list_comma_zom
682 ((fpdef_opt_test_list_comma_zom fpdef_opt_test COMMA)
686 ((fpdef_opt_test_list COMMA fpdef_opt_test)
689 ((fpdef eq_test_opt)))
693 (semantic-tag-new-variable $1 nil nil))))
695 ((fpdef_list comma_opt)))
698 ((fpdef_list COMMA fpdef)))
709 '(goal function_parameter paren_class indented_block function_parameters paren_classes indented_block_body)))
712 (defun wisent-python-wy--install-parser ()
713 "Setup the Semantic Parser."
714 (semantic-install-function-overrides
715 '((parse-stream . wisent-parse-stream)))
716 (setq semantic-parser-name "LALR"
717 semantic--parse-table wisent-python-wy--parse-table
718 semantic-debug-parser-source "python.wy"
719 semantic-flex-keywords-obarray wisent-python-wy--keyword-table
720 semantic-lex-types-obarray wisent-python-wy--token-table)
721 ;; Collect unmatched syntax lexical tokens
722 (semantic-make-local-hook 'wisent-discarding-token-functions)
723 (add-hook 'wisent-discarding-token-functions
724 'wisent-collect-unmatched-syntax nil t))
729 (define-lex-block-type-analyzer wisent-python-wy--<block>-block-analyzer
730 "block analyzer for <block> tokens."
732 '((("(" LPAREN PAREN_BLOCK)
733 ("{" LBRACE BRACE_BLOCK)
734 ("[" LBRACK BRACK_BLOCK))
740 (define-lex-string-type-analyzer wisent-python-wy--<punctuation>-string-analyzer
741 "string analyzer for <punctuation> tokens."
742 "\\(\\s.\\|\\s$\\|\\s'\\)+"
783 (define-lex-regex-type-analyzer wisent-python-wy--<symbol>-regexp-analyzer
784 "regexp analyzer for <symbol> tokens."
789 (define-lex-regex-type-analyzer wisent-python-wy--<number>-regexp-analyzer
790 "regexp analyzer for <number> tokens."
791 semantic-lex-number-expression
795 (define-lex-keyword-type-analyzer wisent-python-wy--<keyword>-keyword-analyzer
796 "keyword analyzer for <keyword> tokens."
797 "\\(\\sw\\|\\s_\\)+")
803 (provide 'semantic/wisent/python-wy)
805 ;;; semantic/wisent/python-wy.el ends here