1 ;;; semantic/wisent/python-wy.el --- Generated parser support file
3 ;; Copyright (C) 2002, 2003, 2004, 2007, 2010, 2011, 2012
4 ;; Free Software Foundation, Inc.
5 ;; Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
6 ;; 2009, 2010 Python Software Foundation; All Rights Reserved
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25 ;; This file was generated from etc/grammars/python.wy.
26 ;; It is derived in part from the Python grammar, used under the
29 ;; PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
30 ;; --------------------------------------------
31 ;; 1. This LICENSE AGREEMENT is between the Python Software Foundation
32 ;; ("PSF"), and the Individual or Organization ("Licensee") accessing
33 ;; and otherwise using this software ("Python") in source or binary
34 ;; form and its associated documentation.
36 ;; 2. Subject to the terms and conditions of this License Agreement,
37 ;; PSF hereby grants Licensee a nonexclusive, royalty-free, world-wide
38 ;; license to reproduce, analyze, test, perform and/or display
39 ;; publicly, prepare derivative works, distribute, and otherwise use
40 ;; Python alone or in any derivative version, provided, however, that
41 ;; PSF's License Agreement and PSF's notice of copyright, i.e.,
42 ;; "Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
43 ;; 2009, 2010 Python Software Foundation; All Rights Reserved" are
44 ;; retained in Python alone or in any derivative version prepared by
47 ;; 3. In the event Licensee prepares a derivative work that is based
48 ;; on or incorporates Python or any part thereof, and wants to make
49 ;; the derivative work available to others as provided herein, then
50 ;; Licensee hereby agrees to include in any such work a brief summary
51 ;; of the changes made to Python.
53 ;; 4. PSF is making Python available to Licensee on an "AS IS"
54 ;; basis. PSF MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR
55 ;; IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, PSF MAKES NO AND
56 ;; DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS
57 ;; FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF PYTHON WILL NOT
58 ;; INFRINGE ANY THIRD PARTY RIGHTS.
60 ;; 5. PSF SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON
61 ;; FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS A
62 ;; RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON, OR
63 ;; ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF.
65 ;; 6. This License Agreement will automatically terminate upon a
66 ;; material breach of its terms and conditions.
68 ;; 7. Nothing in this License Agreement shall be deemed to create any
69 ;; relationship of agency, partnership, or joint venture between PSF
70 ;; and Licensee. This License Agreement does not grant permission to
71 ;; use PSF trademarks or trade name in a trademark sense to endorse or
72 ;; promote products or services of Licensee, or any third party.
74 ;; 8. By copying, installing or otherwise using Python, Licensee
75 ;; agrees to be bound by the terms and conditions of this License
80 (require 'semantic/lex)
87 (defconst wisent-python-wy--keyword-table
88 (semantic-lex-make-keyword-table
94 ("continue" . CONTINUE)
101 ("finally" . FINALLY)
119 '(("yield" summary "Create a generator function")
120 ("while" summary "Start a 'while' loop")
121 ("try" summary "Start of statements protected by exception handlers")
122 ("return" summary "Return from a function")
123 ("raise" summary "Raise an exception")
124 ("print" summary "Print each argument to standard output")
125 ("pass" summary "Statement that does nothing")
126 ("or" summary "Binary logical 'or' operator")
127 ("not" summary "Unary boolean negation operator")
128 ("lambda" summary "Create anonymous function")
129 ("is" summary "Binary operator that tests for object equality")
130 ("in" summary "Part of 'for' statement ")
131 ("import" summary "Load specified modules")
132 ("if" summary "Start 'if' conditional statement")
133 ("global" summary "Declare one or more symbols as global symbols")
134 ("from" summary "Modify behavior of 'import' statement")
135 ("for" summary "Start a 'for' loop")
136 ("finally" summary "Specify code to be executed after 'try' statements whether or not an exception occurred")
137 ("exec" summary "Dynamically execute Python code")
138 ("except" summary "Specify exception handlers along with 'try' keyword")
139 ("else" summary "Start the 'else' clause following an 'if' statement")
140 ("elif" summary "Shorthand for 'else if' following an 'if' statement")
141 ("del" summary "Delete specified objects, i.e., undo what assignment did")
142 ("def" summary "Define a new function")
143 ("continue" summary "Skip to the next iteration of enclosing 'for' or 'while' loop")
144 ("class" summary "Define a new class")
145 ("break" summary "Terminate 'for' or 'while' loop")
146 ("assert" summary "Raise AssertionError exception if <expr> is false")
147 ("as" summary "EXPR as NAME makes value of EXPR available as variable NAME")
148 ("and" summary "Logical AND binary operator ... ")))
149 "Table of language keywords.")
151 (defconst wisent-python-wy--token-table
152 (semantic-lex-make-type-table
207 (BRACK_BLOCK . "(LBRACK RBRACK)")
208 (BRACE_BLOCK . "(LBRACE RBRACE)")
209 (PAREN_BLOCK . "(LPAREN RPAREN)"))
211 (INDENT_BLOCK . "(INDENT DEDENT)")
212 (DEDENT . "[^:INDENT:]")
218 '(("keyword" :declared t)
219 ("symbol" :declared t)
220 ("number" :declared t)
221 ("punctuation" :declared t)
222 ("block" :declared t)))
223 "Table of lexical tokens.")
225 (defconst wisent-python-wy--parse-table
228 (require 'semantic/wisent/comp))
229 (wisent-compile-grammar
230 '((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)
237 ((small_stmt_list semicolon_opt NEWLINE)))
240 ((small_stmt_list SEMICOLON small_stmt)))
252 ((PRINT print_stmt_trailer)
254 (semantic-tag-new-code $1 nil))))
258 ((GTGT test trailing_test_list_with_opt_comma_opt)
260 (trailing_test_list_with_opt_comma_opt
262 ((trailing_test_list comma_opt)
267 ((trailing_test_list COMMA test)
270 ((testlist expr_stmt_trailer)
274 (string-match "^\\(\\sw\\|\\s_\\)+$" $1))
276 (semantic-tag-new-variable $1 nil nil))
278 (semantic-tag-new-code $1 nil)))))
280 ((augassign testlist))
284 ((eq_testlist_zom ASSIGN testlist)
302 (semantic-tag-new-code $1 nil))))
304 ((expr_list comma_opt)
309 ((expr_list COMMA expr)
314 (semantic-tag-new-code $1 nil))))
324 (semantic-tag-new-code $1 nil))))
328 (semantic-tag-new-code $1 nil))))
330 ((RETURN testlist_opt)
332 (semantic-tag-new-code $1 nil))))
340 (semantic-tag-new-code $1 nil)))
343 (semantic-tag-new-code $1 nil))))
345 ((RAISE zero_one_two_or_three_tests)
347 (semantic-tag-new-code $1 nil))))
348 (zero_one_two_or_three_tests
350 ((test zero_one_or_two_tests)
352 (zero_one_or_two_tests
354 ((COMMA test zero_or_one_comma_test)
356 (zero_or_one_comma_test
361 ((IMPORT dotted_as_name_list)
363 (semantic-tag-new-include $2 nil)))
364 ((FROM dotted_name IMPORT star_or_import_as_name_list)
366 (semantic-tag-new-include $2 nil))))
369 ((dotted_as_name_list COMMA dotted_as_name)))
370 (star_or_import_as_name_list
373 ((import_as_name_list)
378 ((import_as_name_list COMMA import_as_name)
384 ((dotted_name as_name_opt)))
391 ((dotted_name PERIOD NAME)
392 (format "%s.%s" $1 $3)))
394 ((GLOBAL comma_sep_name_list)
396 (semantic-tag-new-code $1 nil))))
399 ((comma_sep_name_list COMMA NAME)))
401 ((EXEC expr exec_trailer)
403 (semantic-tag-new-code $1 nil))))
406 ((IN test comma_test_opt)
413 ((ASSERT test comma_test_opt)
415 (semantic-tag-new-code $1 nil))))
422 ((class_declaration)))
424 ((IF test COLON suite elif_suite_pair_list else_suite_pair_opt)
426 (semantic-tag-new-code $1 nil))))
427 (elif_suite_pair_list
429 ((elif_suite_pair_list ELIF test COLON suite)
438 ((NEWLINE indented_block)
442 (semantic-parse-region
445 'indented_block_body 1)))
454 ((WHILE test COLON suite else_suite_pair_opt)
456 (semantic-tag-new-code $1 nil))))
458 ((FOR exprlist IN testlist COLON suite else_suite_pair_opt)
460 (semantic-tag-new-code $1 nil))))
462 ((TRY COLON suite except_clause_suite_pair_list else_suite_pair_opt)
464 (semantic-tag-new-code $1 nil)))
465 ((TRY COLON suite FINALLY COLON suite)
467 (semantic-tag-new-code $1 nil))))
468 (except_clause_suite_pair_list
469 ((except_clause COLON suite)
471 ((except_clause_suite_pair_list except_clause COLON suite)
474 ((EXCEPT zero_one_or_two_test)
476 (zero_one_or_two_test
478 ((test zero_or_one_comma_test)
481 ((DEF NAME function_parameter_list COLON suite)
483 (semantic-tag-new-function $2 nil $3))))
484 (function_parameter_list
487 ((wisent-python-EXPANDING-block t))
488 (semantic-parse-region
491 'function_parameters 1))))
497 ((function_parameter COMMA))
498 ((function_parameter RPAREN)))
503 (semantic-tag-new-variable $2 nil nil)))
506 (semantic-tag-new-variable $2 nil nil))))
508 ((CLASS NAME paren_class_list_opt COLON suite)
510 (semantic-tag-new-type $2 $1 $5
512 (paren_class_list_opt
514 ((paren_class_list)))
518 ((wisent-python-EXPANDING-block t))
519 (mapcar 'semantic-tag-name
520 (semantic-parse-region
523 'paren_classes 1)))))
531 (semantic-tag-new-variable $1 nil nil)))
532 ((paren_class RPAREN)
534 (semantic-tag-new-variable $1 nil nil))))
542 ((test_test OR and_test)
546 ((and_test AND not_test)
554 ((comparison comp_op expr)
574 ((xor_expr HAT and_expr)
578 ((and_expr AMP shift_expr)
582 ((shift_expr shift_expr_operators arith_expr)
584 (shift_expr_operators
589 ((arith_expr plus_or_minus term)
596 ((term term_operator factor)
604 ((prefix_operators factor)
612 ((atom trailer_zom exponent_zom)
622 ((trailer_zom trailer)
626 ((exponent_zom EXPONENT factor)
642 ((BACKQUOTE testlist BACKQUOTE)
646 ((one_or_more_string)))
652 ((comma_sep_test_list comma_opt)))
655 ((comma_sep_test_list COMMA test)
656 (format "%s, %s" $1 $3)))
659 ((one_or_more_string STRING_LITERAL)
662 ((LAMBDA varargslist_opt COLON test)
669 ((fpdef_opt_test_list_comma_zom rest_args)
671 ((fpdef_opt_test_list comma_opt)))
673 ((MULT NAME multmult_name_opt)
679 ((COMMA EXPONENT NAME)
681 (semantic-tag-new-variable $3 nil nil))))
682 (fpdef_opt_test_list_comma_zom
684 ((fpdef_opt_test_list_comma_zom fpdef_opt_test COMMA)
688 ((fpdef_opt_test_list COMMA fpdef_opt_test)
691 ((fpdef eq_test_opt)))
695 (semantic-tag-new-variable $1 nil nil))))
697 ((fpdef_list comma_opt)))
700 ((fpdef_list COMMA fpdef)))
711 '(goal function_parameter paren_class indented_block function_parameters paren_classes indented_block_body)))
714 (defun wisent-python-wy--install-parser ()
715 "Setup the Semantic Parser."
716 (semantic-install-function-overrides
717 '((parse-stream . wisent-parse-stream)))
718 (setq semantic-parser-name "LALR"
719 semantic--parse-table wisent-python-wy--parse-table
720 semantic-debug-parser-source "python.wy"
721 semantic-flex-keywords-obarray wisent-python-wy--keyword-table
722 semantic-lex-types-obarray wisent-python-wy--token-table)
723 ;; Collect unmatched syntax lexical tokens
724 (semantic-make-local-hook 'wisent-discarding-token-functions)
725 (add-hook 'wisent-discarding-token-functions
726 'wisent-collect-unmatched-syntax nil t))
731 (define-lex-keyword-type-analyzer wisent-python-wy--<keyword>-keyword-analyzer
732 "keyword analyzer for <keyword> tokens."
733 "\\(\\sw\\|\\s_\\)+")
735 (define-lex-block-type-analyzer wisent-python-wy--<block>-block-analyzer
736 "block analyzer for <block> tokens."
738 '((("(" LPAREN PAREN_BLOCK)
739 ("{" LBRACE BRACE_BLOCK)
740 ("[" LBRACK BRACK_BLOCK))
746 (define-lex-regex-type-analyzer wisent-python-wy--<symbol>-regexp-analyzer
747 "regexp analyzer for <symbol> tokens."
752 (define-lex-regex-type-analyzer wisent-python-wy--<number>-regexp-analyzer
753 "regexp analyzer for <number> tokens."
754 semantic-lex-number-expression
758 (define-lex-string-type-analyzer wisent-python-wy--<punctuation>-string-analyzer
759 "string analyzer for <punctuation> tokens."
760 "\\(\\s.\\|\\s$\\|\\s'\\)+"
805 (provide 'semantic/wisent/python-wy)
807 ;;; semantic/wisent/python-wy.el ends here