python-wy.el 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807
  1. ;;; semantic/wisent/python-wy.el --- Generated parser support file
  2. ;; Copyright (C) 2002-2004, 2007, 2010-2012 Free Software Foundation, Inc.
  3. ;; Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
  4. ;; 2009, 2010 Python Software Foundation; All Rights Reserved
  5. ;; This file is part of GNU Emacs.
  6. ;; GNU Emacs is free software: you can redistribute it and/or modify
  7. ;; it under the terms of the GNU General Public License as published by
  8. ;; the Free Software Foundation, either version 3 of the License, or
  9. ;; (at your option) any later version.
  10. ;; GNU Emacs is distributed in the hope that it will be useful,
  11. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ;; GNU General Public License for more details.
  14. ;; You should have received a copy of the GNU General Public License
  15. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  16. ;;; Commentary:
  17. ;;
  18. ;; This file was generated from admin/grammars/python.wy.
  19. ;; It is derived in part from the Python grammar, used under the
  20. ;; following license:
  21. ;;
  22. ;; PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
  23. ;; --------------------------------------------
  24. ;; 1. This LICENSE AGREEMENT is between the Python Software Foundation
  25. ;; ("PSF"), and the Individual or Organization ("Licensee") accessing
  26. ;; and otherwise using this software ("Python") in source or binary
  27. ;; form and its associated documentation.
  28. ;;
  29. ;; 2. Subject to the terms and conditions of this License Agreement,
  30. ;; PSF hereby grants Licensee a nonexclusive, royalty-free, world-wide
  31. ;; license to reproduce, analyze, test, perform and/or display
  32. ;; publicly, prepare derivative works, distribute, and otherwise use
  33. ;; Python alone or in any derivative version, provided, however, that
  34. ;; PSF's License Agreement and PSF's notice of copyright, i.e.,
  35. ;; "Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
  36. ;; 2009, 2010 Python Software Foundation; All Rights Reserved" are
  37. ;; retained in Python alone or in any derivative version prepared by
  38. ;; Licensee.
  39. ;;
  40. ;; 3. In the event Licensee prepares a derivative work that is based
  41. ;; on or incorporates Python or any part thereof, and wants to make
  42. ;; the derivative work available to others as provided herein, then
  43. ;; Licensee hereby agrees to include in any such work a brief summary
  44. ;; of the changes made to Python.
  45. ;;
  46. ;; 4. PSF is making Python available to Licensee on an "AS IS"
  47. ;; basis. PSF MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR
  48. ;; IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, PSF MAKES NO AND
  49. ;; DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS
  50. ;; FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF PYTHON WILL NOT
  51. ;; INFRINGE ANY THIRD PARTY RIGHTS.
  52. ;;
  53. ;; 5. PSF SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON
  54. ;; FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS A
  55. ;; RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON, OR
  56. ;; ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF.
  57. ;;
  58. ;; 6. This License Agreement will automatically terminate upon a
  59. ;; material breach of its terms and conditions.
  60. ;;
  61. ;; 7. Nothing in this License Agreement shall be deemed to create any
  62. ;; relationship of agency, partnership, or joint venture between PSF
  63. ;; and Licensee. This License Agreement does not grant permission to
  64. ;; use PSF trademarks or trade name in a trademark sense to endorse or
  65. ;; promote products or services of Licensee, or any third party.
  66. ;;
  67. ;; 8. By copying, installing or otherwise using Python, Licensee
  68. ;; agrees to be bound by the terms and conditions of this License
  69. ;; Agreement.
  70. ;;; Code:
  71. (require 'semantic/lex)
  72. ;;; Prologue
  73. ;;
  74. ;;; Declarations
  75. ;;
  76. (defconst wisent-python-wy--keyword-table
  77. (semantic-lex-make-keyword-table
  78. '(("and" . AND)
  79. ("as" . AS)
  80. ("assert" . ASSERT)
  81. ("break" . BREAK)
  82. ("class" . CLASS)
  83. ("continue" . CONTINUE)
  84. ("def" . DEF)
  85. ("del" . DEL)
  86. ("elif" . ELIF)
  87. ("else" . ELSE)
  88. ("except" . EXCEPT)
  89. ("exec" . EXEC)
  90. ("finally" . FINALLY)
  91. ("for" . FOR)
  92. ("from" . FROM)
  93. ("global" . GLOBAL)
  94. ("if" . IF)
  95. ("import" . IMPORT)
  96. ("in" . IN)
  97. ("is" . IS)
  98. ("lambda" . LAMBDA)
  99. ("not" . NOT)
  100. ("or" . OR)
  101. ("pass" . PASS)
  102. ("print" . PRINT)
  103. ("raise" . RAISE)
  104. ("return" . RETURN)
  105. ("try" . TRY)
  106. ("while" . WHILE)
  107. ("yield" . YIELD))
  108. '(("yield" summary "Create a generator function")
  109. ("while" summary "Start a 'while' loop")
  110. ("try" summary "Start of statements protected by exception handlers")
  111. ("return" summary "Return from a function")
  112. ("raise" summary "Raise an exception")
  113. ("print" summary "Print each argument to standard output")
  114. ("pass" summary "Statement that does nothing")
  115. ("or" summary "Binary logical 'or' operator")
  116. ("not" summary "Unary boolean negation operator")
  117. ("lambda" summary "Create anonymous function")
  118. ("is" summary "Binary operator that tests for object equality")
  119. ("in" summary "Part of 'for' statement ")
  120. ("import" summary "Load specified modules")
  121. ("if" summary "Start 'if' conditional statement")
  122. ("global" summary "Declare one or more symbols as global symbols")
  123. ("from" summary "Modify behavior of 'import' statement")
  124. ("for" summary "Start a 'for' loop")
  125. ("finally" summary "Specify code to be executed after 'try' statements whether or not an exception occurred")
  126. ("exec" summary "Dynamically execute Python code")
  127. ("except" summary "Specify exception handlers along with 'try' keyword")
  128. ("else" summary "Start the 'else' clause following an 'if' statement")
  129. ("elif" summary "Shorthand for 'else if' following an 'if' statement")
  130. ("del" summary "Delete specified objects, i.e., undo what assignment did")
  131. ("def" summary "Define a new function")
  132. ("continue" summary "Skip to the next iteration of enclosing 'for' or 'while' loop")
  133. ("class" summary "Define a new class")
  134. ("break" summary "Terminate 'for' or 'while' loop")
  135. ("assert" summary "Raise AssertionError exception if <expr> is false")
  136. ("as" summary "EXPR as NAME makes value of EXPR available as variable NAME")
  137. ("and" summary "Logical AND binary operator ... ")))
  138. "Table of language keywords.")
  139. (defconst wisent-python-wy--token-table
  140. (semantic-lex-make-type-table
  141. '(("symbol"
  142. (NAME))
  143. ("number"
  144. (NUMBER_LITERAL))
  145. ("string"
  146. (STRING_LITERAL))
  147. ("punctuation"
  148. (BACKQUOTE . "`")
  149. (ASSIGN . "=")
  150. (COMMA . ",")
  151. (SEMICOLON . ";")
  152. (COLON . ":")
  153. (BAR . "|")
  154. (TILDE . "~")
  155. (PERIOD . ".")
  156. (MINUS . "-")
  157. (PLUS . "+")
  158. (MOD . "%")
  159. (DIV . "/")
  160. (MULT . "*")
  161. (AMP . "&")
  162. (GT . ">")
  163. (LT . "<")
  164. (HAT . "^")
  165. (NE . "!=")
  166. (LTGT . "<>")
  167. (HATEQ . "^=")
  168. (OREQ . "|=")
  169. (AMPEQ . "&=")
  170. (MODEQ . "%=")
  171. (DIVEQ . "/=")
  172. (MULTEQ . "*=")
  173. (MINUSEQ . "-=")
  174. (PLUSEQ . "+=")
  175. (LE . "<=")
  176. (GE . ">=")
  177. (EQ . "==")
  178. (EXPONENT . "**")
  179. (GTGT . ">>")
  180. (LTLT . "<<")
  181. (DIVDIV . "//")
  182. (DIVDIVEQ . "//=")
  183. (EXPEQ . "**=")
  184. (GTGTEQ . ">>=")
  185. (LTLTEQ . "<<="))
  186. ("close-paren"
  187. (RBRACK . "]")
  188. (RBRACE . "}")
  189. (RPAREN . ")"))
  190. ("open-paren"
  191. (LBRACK . "[")
  192. (LBRACE . "{")
  193. (LPAREN . "("))
  194. ("block"
  195. (BRACK_BLOCK . "(LBRACK RBRACK)")
  196. (BRACE_BLOCK . "(LBRACE RBRACE)")
  197. (PAREN_BLOCK . "(LPAREN RPAREN)"))
  198. ("indentation"
  199. (INDENT_BLOCK . "(INDENT DEDENT)")
  200. (DEDENT . "[^:INDENT:]")
  201. (INDENT . "^\\s-+"))
  202. ("newline"
  203. (NEWLINE . "\n"))
  204. ("charquote"
  205. (BACKSLASH . "\\")))
  206. '(("keyword" :declared t)
  207. ("symbol" :declared t)
  208. ("number" :declared t)
  209. ("punctuation" :declared t)
  210. ("block" :declared t)))
  211. "Table of lexical tokens.")
  212. (defconst wisent-python-wy--parse-table
  213. (progn
  214. (eval-when-compile
  215. (require 'semantic/wisent/comp))
  216. (wisent-compile-grammar
  217. '((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)
  218. nil
  219. (goal
  220. ((NEWLINE))
  221. ((simple_stmt))
  222. ((compound_stmt)))
  223. (simple_stmt
  224. ((small_stmt_list semicolon_opt NEWLINE)))
  225. (small_stmt_list
  226. ((small_stmt))
  227. ((small_stmt_list SEMICOLON small_stmt)))
  228. (small_stmt
  229. ((expr_stmt))
  230. ((print_stmt))
  231. ((del_stmt))
  232. ((pass_stmt))
  233. ((flow_stmt))
  234. ((import_stmt))
  235. ((global_stmt))
  236. ((exec_stmt))
  237. ((assert_stmt)))
  238. (print_stmt
  239. ((PRINT print_stmt_trailer)
  240. (wisent-raw-tag
  241. (semantic-tag-new-code $1 nil))))
  242. (print_stmt_trailer
  243. ((test_list_opt)
  244. nil)
  245. ((GTGT test trailing_test_list_with_opt_comma_opt)
  246. nil))
  247. (trailing_test_list_with_opt_comma_opt
  248. (nil)
  249. ((trailing_test_list comma_opt)
  250. nil))
  251. (trailing_test_list
  252. ((COMMA test)
  253. nil)
  254. ((trailing_test_list COMMA test)
  255. nil))
  256. (expr_stmt
  257. ((testlist expr_stmt_trailer)
  258. (if
  259. (and $2
  260. (stringp $1)
  261. (string-match "^\\(\\sw\\|\\s_\\)+$" $1))
  262. (wisent-raw-tag
  263. (semantic-tag-new-variable $1 nil nil))
  264. (wisent-raw-tag
  265. (semantic-tag-new-code $1 nil)))))
  266. (expr_stmt_trailer
  267. ((augassign testlist))
  268. ((eq_testlist_zom)))
  269. (eq_testlist_zom
  270. (nil)
  271. ((eq_testlist_zom ASSIGN testlist)
  272. (identity $3)))
  273. (augassign
  274. ((PLUSEQ))
  275. ((MINUSEQ))
  276. ((MULTEQ))
  277. ((DIVEQ))
  278. ((MODEQ))
  279. ((AMPEQ))
  280. ((OREQ))
  281. ((HATEQ))
  282. ((LTLTEQ))
  283. ((GTGTEQ))
  284. ((EXPEQ))
  285. ((DIVDIVEQ)))
  286. (del_stmt
  287. ((DEL exprlist)
  288. (wisent-raw-tag
  289. (semantic-tag-new-code $1 nil))))
  290. (exprlist
  291. ((expr_list comma_opt)
  292. nil))
  293. (expr_list
  294. ((expr)
  295. nil)
  296. ((expr_list COMMA expr)
  297. nil))
  298. (pass_stmt
  299. ((PASS)
  300. (wisent-raw-tag
  301. (semantic-tag-new-code $1 nil))))
  302. (flow_stmt
  303. ((break_stmt))
  304. ((continue_stmt))
  305. ((return_stmt))
  306. ((raise_stmt))
  307. ((yield_stmt)))
  308. (break_stmt
  309. ((BREAK)
  310. (wisent-raw-tag
  311. (semantic-tag-new-code $1 nil))))
  312. (continue_stmt
  313. ((CONTINUE)
  314. (wisent-raw-tag
  315. (semantic-tag-new-code $1 nil))))
  316. (return_stmt
  317. ((RETURN testlist_opt)
  318. (wisent-raw-tag
  319. (semantic-tag-new-code $1 nil))))
  320. (testlist_opt
  321. (nil)
  322. ((testlist)
  323. nil))
  324. (yield_stmt
  325. ((YIELD)
  326. (wisent-raw-tag
  327. (semantic-tag-new-code $1 nil)))
  328. ((YIELD testlist)
  329. (wisent-raw-tag
  330. (semantic-tag-new-code $1 nil))))
  331. (raise_stmt
  332. ((RAISE zero_one_two_or_three_tests)
  333. (wisent-raw-tag
  334. (semantic-tag-new-code $1 nil))))
  335. (zero_one_two_or_three_tests
  336. (nil)
  337. ((test zero_one_or_two_tests)
  338. nil))
  339. (zero_one_or_two_tests
  340. (nil)
  341. ((COMMA test zero_or_one_comma_test)
  342. nil))
  343. (zero_or_one_comma_test
  344. (nil)
  345. ((COMMA test)
  346. nil))
  347. (import_stmt
  348. ((IMPORT dotted_as_name_list)
  349. (wisent-raw-tag
  350. (semantic-tag-new-include $2 nil)))
  351. ((FROM dotted_name IMPORT star_or_import_as_name_list)
  352. (wisent-raw-tag
  353. (semantic-tag-new-include $2 nil))))
  354. (dotted_as_name_list
  355. ((dotted_as_name))
  356. ((dotted_as_name_list COMMA dotted_as_name)))
  357. (star_or_import_as_name_list
  358. ((MULT)
  359. nil)
  360. ((import_as_name_list)
  361. nil))
  362. (import_as_name_list
  363. ((import_as_name)
  364. nil)
  365. ((import_as_name_list COMMA import_as_name)
  366. nil))
  367. (import_as_name
  368. ((NAME as_name_opt)
  369. nil))
  370. (dotted_as_name
  371. ((dotted_name as_name_opt)))
  372. (as_name_opt
  373. (nil)
  374. ((AS NAME)
  375. (identity $2)))
  376. (dotted_name
  377. ((NAME))
  378. ((dotted_name PERIOD NAME)
  379. (format "%s.%s" $1 $3)))
  380. (global_stmt
  381. ((GLOBAL comma_sep_name_list)
  382. (wisent-raw-tag
  383. (semantic-tag-new-code $1 nil))))
  384. (comma_sep_name_list
  385. ((NAME))
  386. ((comma_sep_name_list COMMA NAME)))
  387. (exec_stmt
  388. ((EXEC expr exec_trailer)
  389. (wisent-raw-tag
  390. (semantic-tag-new-code $1 nil))))
  391. (exec_trailer
  392. (nil)
  393. ((IN test comma_test_opt)
  394. nil))
  395. (comma_test_opt
  396. (nil)
  397. ((COMMA test)
  398. nil))
  399. (assert_stmt
  400. ((ASSERT test comma_test_opt)
  401. (wisent-raw-tag
  402. (semantic-tag-new-code $1 nil))))
  403. (compound_stmt
  404. ((if_stmt))
  405. ((while_stmt))
  406. ((for_stmt))
  407. ((try_stmt))
  408. ((funcdef))
  409. ((class_declaration)))
  410. (if_stmt
  411. ((IF test COLON suite elif_suite_pair_list else_suite_pair_opt)
  412. (wisent-raw-tag
  413. (semantic-tag-new-code $1 nil))))
  414. (elif_suite_pair_list
  415. (nil)
  416. ((elif_suite_pair_list ELIF test COLON suite)
  417. nil))
  418. (else_suite_pair_opt
  419. (nil)
  420. ((ELSE COLON suite)
  421. nil))
  422. (suite
  423. ((simple_stmt)
  424. (list $1))
  425. ((NEWLINE indented_block)
  426. (progn $2)))
  427. (indented_block
  428. ((INDENT_BLOCK)
  429. (semantic-parse-region
  430. (car $region1)
  431. (cdr $region1)
  432. 'indented_block_body 1)))
  433. (indented_block_body
  434. ((INDENT)
  435. nil)
  436. ((DEDENT)
  437. nil)
  438. ((simple_stmt))
  439. ((compound_stmt)))
  440. (while_stmt
  441. ((WHILE test COLON suite else_suite_pair_opt)
  442. (wisent-raw-tag
  443. (semantic-tag-new-code $1 nil))))
  444. (for_stmt
  445. ((FOR exprlist IN testlist COLON suite else_suite_pair_opt)
  446. (wisent-raw-tag
  447. (semantic-tag-new-code $1 nil))))
  448. (try_stmt
  449. ((TRY COLON suite except_clause_suite_pair_list else_suite_pair_opt)
  450. (wisent-raw-tag
  451. (semantic-tag-new-code $1 nil)))
  452. ((TRY COLON suite FINALLY COLON suite)
  453. (wisent-raw-tag
  454. (semantic-tag-new-code $1 nil))))
  455. (except_clause_suite_pair_list
  456. ((except_clause COLON suite)
  457. nil)
  458. ((except_clause_suite_pair_list except_clause COLON suite)
  459. nil))
  460. (except_clause
  461. ((EXCEPT zero_one_or_two_test)
  462. nil))
  463. (zero_one_or_two_test
  464. (nil)
  465. ((test zero_or_one_comma_test)
  466. nil))
  467. (funcdef
  468. ((DEF NAME function_parameter_list COLON suite)
  469. (wisent-raw-tag
  470. (semantic-tag-new-function $2 nil $3))))
  471. (function_parameter_list
  472. ((PAREN_BLOCK)
  473. (let
  474. ((wisent-python-EXPANDING-block t))
  475. (semantic-parse-region
  476. (car $region1)
  477. (cdr $region1)
  478. 'function_parameters 1))))
  479. (function_parameters
  480. ((LPAREN)
  481. nil)
  482. ((RPAREN)
  483. nil)
  484. ((function_parameter COMMA))
  485. ((function_parameter RPAREN)))
  486. (function_parameter
  487. ((fpdef_opt_test))
  488. ((MULT NAME)
  489. (wisent-raw-tag
  490. (semantic-tag-new-variable $2 nil nil)))
  491. ((EXPONENT NAME)
  492. (wisent-raw-tag
  493. (semantic-tag-new-variable $2 nil nil))))
  494. (class_declaration
  495. ((CLASS NAME paren_class_list_opt COLON suite)
  496. (wisent-raw-tag
  497. (semantic-tag-new-type $2 $1 $5
  498. (cons $3 nil)))))
  499. (paren_class_list_opt
  500. (nil)
  501. ((paren_class_list)))
  502. (paren_class_list
  503. ((PAREN_BLOCK)
  504. (let
  505. ((wisent-python-EXPANDING-block t))
  506. (mapcar 'semantic-tag-name
  507. (semantic-parse-region
  508. (car $region1)
  509. (cdr $region1)
  510. 'paren_classes 1)))))
  511. (paren_classes
  512. ((LPAREN)
  513. nil)
  514. ((RPAREN)
  515. nil)
  516. ((paren_class COMMA)
  517. (wisent-raw-tag
  518. (semantic-tag-new-variable $1 nil nil)))
  519. ((paren_class RPAREN)
  520. (wisent-raw-tag
  521. (semantic-tag-new-variable $1 nil nil))))
  522. (paren_class
  523. ((dotted_name)))
  524. (test
  525. ((test_test))
  526. ((lambdef)))
  527. (test_test
  528. ((and_test))
  529. ((test_test OR and_test)
  530. nil))
  531. (and_test
  532. ((not_test))
  533. ((and_test AND not_test)
  534. nil))
  535. (not_test
  536. ((NOT not_test)
  537. nil)
  538. ((comparison)))
  539. (comparison
  540. ((expr))
  541. ((comparison comp_op expr)
  542. nil))
  543. (comp_op
  544. ((LT))
  545. ((GT))
  546. ((EQ))
  547. ((GE))
  548. ((LE))
  549. ((LTGT))
  550. ((NE))
  551. ((IN))
  552. ((NOT IN))
  553. ((IS))
  554. ((IS NOT)))
  555. (expr
  556. ((xor_expr))
  557. ((expr BAR xor_expr)
  558. nil))
  559. (xor_expr
  560. ((and_expr))
  561. ((xor_expr HAT and_expr)
  562. nil))
  563. (and_expr
  564. ((shift_expr))
  565. ((and_expr AMP shift_expr)
  566. nil))
  567. (shift_expr
  568. ((arith_expr))
  569. ((shift_expr shift_expr_operators arith_expr)
  570. nil))
  571. (shift_expr_operators
  572. ((LTLT))
  573. ((GTGT)))
  574. (arith_expr
  575. ((term))
  576. ((arith_expr plus_or_minus term)
  577. nil))
  578. (plus_or_minus
  579. ((PLUS))
  580. ((MINUS)))
  581. (term
  582. ((factor))
  583. ((term term_operator factor)
  584. nil))
  585. (term_operator
  586. ((MULT))
  587. ((DIV))
  588. ((MOD))
  589. ((DIVDIV)))
  590. (factor
  591. ((prefix_operators factor)
  592. nil)
  593. ((power)))
  594. (prefix_operators
  595. ((PLUS))
  596. ((MINUS))
  597. ((TILDE)))
  598. (power
  599. ((atom trailer_zom exponent_zom)
  600. (concat $1
  601. (if $2
  602. (concat " " $2 " ")
  603. "")
  604. (if $3
  605. (concat " " $3)
  606. ""))))
  607. (trailer_zom
  608. (nil)
  609. ((trailer_zom trailer)
  610. nil))
  611. (exponent_zom
  612. (nil)
  613. ((exponent_zom EXPONENT factor)
  614. nil))
  615. (trailer
  616. ((PAREN_BLOCK)
  617. nil)
  618. ((BRACK_BLOCK)
  619. nil)
  620. ((PERIOD NAME)
  621. nil))
  622. (atom
  623. ((PAREN_BLOCK)
  624. nil)
  625. ((BRACK_BLOCK)
  626. nil)
  627. ((BRACE_BLOCK)
  628. nil)
  629. ((BACKQUOTE testlist BACKQUOTE)
  630. nil)
  631. ((NAME))
  632. ((NUMBER_LITERAL))
  633. ((one_or_more_string)))
  634. (test_list_opt
  635. (nil)
  636. ((testlist)
  637. nil))
  638. (testlist
  639. ((comma_sep_test_list comma_opt)))
  640. (comma_sep_test_list
  641. ((test))
  642. ((comma_sep_test_list COMMA test)
  643. (format "%s, %s" $1 $3)))
  644. (one_or_more_string
  645. ((STRING_LITERAL))
  646. ((one_or_more_string STRING_LITERAL)
  647. (concat $1 $2)))
  648. (lambdef
  649. ((LAMBDA varargslist_opt COLON test)
  650. (format "%s %s" $1
  651. (or $2 ""))))
  652. (varargslist_opt
  653. (nil)
  654. ((varargslist)))
  655. (varargslist
  656. ((fpdef_opt_test_list_comma_zom rest_args)
  657. (nconc $2 $1))
  658. ((fpdef_opt_test_list comma_opt)))
  659. (rest_args
  660. ((MULT NAME multmult_name_opt)
  661. nil)
  662. ((EXPONENT NAME)
  663. nil))
  664. (multmult_name_opt
  665. (nil)
  666. ((COMMA EXPONENT NAME)
  667. (wisent-raw-tag
  668. (semantic-tag-new-variable $3 nil nil))))
  669. (fpdef_opt_test_list_comma_zom
  670. (nil)
  671. ((fpdef_opt_test_list_comma_zom fpdef_opt_test COMMA)
  672. (nconc $2 $1)))
  673. (fpdef_opt_test_list
  674. ((fpdef_opt_test))
  675. ((fpdef_opt_test_list COMMA fpdef_opt_test)
  676. (nconc $3 $1)))
  677. (fpdef_opt_test
  678. ((fpdef eq_test_opt)))
  679. (fpdef
  680. ((NAME)
  681. (wisent-raw-tag
  682. (semantic-tag-new-variable $1 nil nil))))
  683. (fplist
  684. ((fpdef_list comma_opt)))
  685. (fpdef_list
  686. ((fpdef))
  687. ((fpdef_list COMMA fpdef)))
  688. (eq_test_opt
  689. (nil)
  690. ((ASSIGN test)
  691. nil))
  692. (comma_opt
  693. (nil)
  694. ((COMMA)))
  695. (semicolon_opt
  696. (nil)
  697. ((SEMICOLON))))
  698. '(goal function_parameter paren_class indented_block function_parameters paren_classes indented_block_body)))
  699. "Parser table.")
  700. (defun wisent-python-wy--install-parser ()
  701. "Setup the Semantic Parser."
  702. (semantic-install-function-overrides
  703. '((parse-stream . wisent-parse-stream)))
  704. (setq semantic-parser-name "LALR"
  705. semantic--parse-table wisent-python-wy--parse-table
  706. semantic-debug-parser-source "python.wy"
  707. semantic-flex-keywords-obarray wisent-python-wy--keyword-table
  708. semantic-lex-types-obarray wisent-python-wy--token-table)
  709. ;; Collect unmatched syntax lexical tokens
  710. (semantic-make-local-hook 'wisent-discarding-token-functions)
  711. (add-hook 'wisent-discarding-token-functions
  712. 'wisent-collect-unmatched-syntax nil t))
  713. ;;; Analyzers
  714. (define-lex-block-type-analyzer wisent-python-wy--<block>-block-analyzer
  715. "block analyzer for <block> tokens."
  716. "\\s(\\|\\s)"
  717. '((("(" LPAREN PAREN_BLOCK)
  718. ("{" LBRACE BRACE_BLOCK)
  719. ("[" LBRACK BRACK_BLOCK))
  720. (")" RPAREN)
  721. ("}" RBRACE)
  722. ("]" RBRACK))
  723. )
  724. (define-lex-string-type-analyzer wisent-python-wy--<punctuation>-string-analyzer
  725. "string analyzer for <punctuation> tokens."
  726. "\\(\\s.\\|\\s$\\|\\s'\\)+"
  727. '((BACKQUOTE . "`")
  728. (ASSIGN . "=")
  729. (COMMA . ",")
  730. (SEMICOLON . ";")
  731. (COLON . ":")
  732. (BAR . "|")
  733. (TILDE . "~")
  734. (PERIOD . ".")
  735. (MINUS . "-")
  736. (PLUS . "+")
  737. (MOD . "%")
  738. (DIV . "/")
  739. (MULT . "*")
  740. (AMP . "&")
  741. (GT . ">")
  742. (LT . "<")
  743. (HAT . "^")
  744. (NE . "!=")
  745. (LTGT . "<>")
  746. (HATEQ . "^=")
  747. (OREQ . "|=")
  748. (AMPEQ . "&=")
  749. (MODEQ . "%=")
  750. (DIVEQ . "/=")
  751. (MULTEQ . "*=")
  752. (MINUSEQ . "-=")
  753. (PLUSEQ . "+=")
  754. (LE . "<=")
  755. (GE . ">=")
  756. (EQ . "==")
  757. (EXPONENT . "**")
  758. (GTGT . ">>")
  759. (LTLT . "<<")
  760. (DIVDIV . "//")
  761. (DIVDIVEQ . "//=")
  762. (EXPEQ . "**=")
  763. (GTGTEQ . ">>=")
  764. (LTLTEQ . "<<="))
  765. 'punctuation)
  766. (define-lex-regex-type-analyzer wisent-python-wy--<symbol>-regexp-analyzer
  767. "regexp analyzer for <symbol> tokens."
  768. "\\(\\sw\\|\\s_\\)+"
  769. nil
  770. 'NAME)
  771. (define-lex-regex-type-analyzer wisent-python-wy--<number>-regexp-analyzer
  772. "regexp analyzer for <number> tokens."
  773. semantic-lex-number-expression
  774. nil
  775. 'NUMBER_LITERAL)
  776. (define-lex-keyword-type-analyzer wisent-python-wy--<keyword>-keyword-analyzer
  777. "keyword analyzer for <keyword> tokens."
  778. "\\(\\sw\\|\\s_\\)+")
  779. ;;; Epilogue
  780. ;;
  781. (provide 'semantic/wisent/python-wy)
  782. ;;; semantic/wisent/python-wy.el ends here