Mercurial > emacs
annotate lisp/cedet/semantic/wisent/python.el @ 112438:11f1b4757236
* image.c (x_create_bitmap_from_xpm_data): Add cast to fix type clash
when calling XpmCreatePixmapFromData.
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Sat, 22 Jan 2011 20:33:12 -0800 |
parents | 376148b31b5e |
children |
rev | line source |
---|---|
106783
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1 ;;; wisent-python.el --- Semantic support for Python |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2 |
112218
376148b31b5e
Add 2011 to FSF/AIST copyright years.
Glenn Morris <rgm@gnu.org>
parents:
106800
diff
changeset
|
3 ;; Copyright (C) 2002, 2004, 2006, 2007, 2008, 2009, 2010, 2011 |
106783
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
4 ;; Free Software Foundation, Inc. |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
5 |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
6 ;; Author: Richard Kim <emacs18@gmail.com> |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
7 ;; Maintainer: Richard Kim <emacs18@gmail.com> |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
8 ;; Created: June 2002 |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
9 ;; Keywords: syntax |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
10 |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
11 ;; This file is part of GNU Emacs. |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
12 |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
13 ;; GNU Emacs is free software: you can redistribute it and/or modify |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
14 ;; it under the terms of the GNU General Public License as published by |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
15 ;; the Free Software Foundation, either version 3 of the License, or |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
16 ;; (at your option) any later version. |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
17 |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
18 ;; GNU Emacs is distributed in the hope that it will be useful, |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
21 ;; GNU General Public License for more details. |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
22 |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
23 ;; You should have received a copy of the GNU General Public License |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
25 |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
26 ;;; Commentary: |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
27 ;; |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
28 ;; Parser support for Python. |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
29 |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
30 ;;; Code: |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
31 |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
32 (require 'semantic/wisent) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
33 (require 'semantic/wisent/python-wy) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
34 (require 'semantic/dep) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
35 (require 'semantic/ctxt) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
36 |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
37 |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
38 ;;; Lexical analysis |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
39 ;; |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
40 |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
41 ;; Python strings are delimited by either single quotes or double |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
42 ;; quotes, e.g., "I'm a string" and 'I too am s string'. |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
43 ;; In addition a string can have either a 'r' and/or 'u' prefix. |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
44 ;; The 'r' prefix means raw, i.e., normal backslash substitutions are |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
45 ;; to be suppressed. For example, r"01\n34" is a string with six |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
46 ;; characters 0, 1, \, n, 3 and 4. The 'u' prefix means the following |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
47 ;; string is a unicode. |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
48 (defconst wisent-python-string-re |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
49 (concat (regexp-opt '("r" "u" "ur" "R" "U" "UR" "Ur" "uR") t) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
50 "?['\"]") |
106800
58365d44aeda
Fix typos in CEDET docstrings.
Juanma Barranquero <lekktu@gmail.com>
parents:
106783
diff
changeset
|
51 "Regexp matching beginning of a Python string.") |
106783
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
52 |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
53 (defvar wisent-python-EXPANDING-block nil |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
54 "Non-nil when expanding a paren block for Python lexical analyzer.") |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
55 |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
56 (defun wisent-python-implicit-line-joining-p () |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
57 "Return non-nil if implicit line joining is active. |
106800
58365d44aeda
Fix typos in CEDET docstrings.
Juanma Barranquero <lekktu@gmail.com>
parents:
106783
diff
changeset
|
58 That is, if inside an expression in parentheses, square brackets or |
106783
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
59 curly braces." |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
60 wisent-python-EXPANDING-block) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
61 |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
62 (defsubst wisent-python-forward-string () |
106800
58365d44aeda
Fix typos in CEDET docstrings.
Juanma Barranquero <lekktu@gmail.com>
parents:
106783
diff
changeset
|
63 "Move point at the end of the Python string at point." |
106783
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
64 (when (looking-at wisent-python-string-re) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
65 ;; skip the prefix |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
66 (and (match-end 1) (goto-char (match-end 1))) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
67 ;; skip the quoted part |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
68 (cond |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
69 ((looking-at "\"\"\"[^\"]") |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
70 (search-forward "\"\"\"" nil nil 2)) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
71 ((looking-at "'''[^']") |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
72 (search-forward "'''" nil nil 2)) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
73 ((forward-sexp 1))))) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
74 |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
75 (defun wisent-python-forward-line () |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
76 "Move point to the beginning of the next logical line. |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
77 Usually this is simply the next physical line unless strings, |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
78 implicit/explicit line continuation, blank lines, or comment lines are |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
79 encountered. This function skips over such items so that the point is |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
80 at the beginning of the next logical line. If the current logical |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
81 line ends at the end of the buffer, leave the point there." |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
82 (while (not (eolp)) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
83 (when (= (point) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
84 (progn |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
85 (cond |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
86 ;; Skip over python strings. |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
87 ((looking-at wisent-python-string-re) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
88 (wisent-python-forward-string)) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
89 ;; At a comment start just goto end of line. |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
90 ((looking-at "\\s<") |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
91 (end-of-line)) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
92 ;; Skip over generic lists and strings. |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
93 ((looking-at "\\(\\s(\\|\\s\"\\)") |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
94 (forward-sexp 1)) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
95 ;; At the explicit line continuation character |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
96 ;; (backslash) move to next line. |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
97 ((looking-at "\\s\\") |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
98 (forward-line 1)) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
99 ;; Skip over white space, word, symbol, punctuation, |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
100 ;; and paired delimiter (backquote) characters. |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
101 ((skip-syntax-forward "-w_.$)"))) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
102 (point))) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
103 (error "python-forward-line endless loop detected"))) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
104 ;; The point is at eol, skip blank and comment lines. |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
105 (forward-comment (point-max)) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
106 ;; Goto the beginning of the next line. |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
107 (or (eobp) (beginning-of-line))) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
108 |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
109 (defun wisent-python-forward-line-skip-indented () |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
110 "Move point to the next logical line, skipping indented lines. |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
111 That is the next line whose indentation is less than or equal to the |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
112 identation of the current line." |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
113 (let ((indent (current-indentation))) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
114 (while (progn (wisent-python-forward-line) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
115 (and (not (eobp)) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
116 (> (current-indentation) indent)))))) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
117 |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
118 (defun wisent-python-end-of-block () |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
119 "Move point to the end of the current block." |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
120 (let ((indent (current-indentation))) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
121 (while (and (not (eobp)) (>= (current-indentation) indent)) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
122 (wisent-python-forward-line-skip-indented)) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
123 ;; Don't include final comments in current block bounds |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
124 (forward-comment (- (point-max))) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
125 (or (bolp) (forward-line 1)) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
126 )) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
127 |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
128 ;; Indentation stack, what the Python (2.3) language spec. says: |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
129 ;; |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
130 ;; The indentation levels of consecutive lines are used to generate |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
131 ;; INDENT and DEDENT tokens, using a stack, as follows. |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
132 ;; |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
133 ;; Before the first line of the file is read, a single zero is pushed |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
134 ;; on the stack; this will never be popped off again. The numbers |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
135 ;; pushed on the stack will always be strictly increasing from bottom |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
136 ;; to top. At the beginning of each logical line, the line's |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
137 ;; indentation level is compared to the top of the stack. If it is |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
138 ;; equal, nothing happens. If it is larger, it is pushed on the stack, |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
139 ;; and one INDENT token is generated. If it is smaller, it must be one |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
140 ;; of the numbers occurring on the stack; all numbers on the stack |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
141 ;; that are larger are popped off, and for each number popped off a |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
142 ;; DEDENT token is generated. At the end of the file, a DEDENT token |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
143 ;; is generated for each number remaining on the stack that is larger |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
144 ;; than zero. |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
145 (defvar wisent-python-indent-stack) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
146 |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
147 (define-lex-analyzer wisent-python-lex-beginning-of-line |
106800
58365d44aeda
Fix typos in CEDET docstrings.
Juanma Barranquero <lekktu@gmail.com>
parents:
106783
diff
changeset
|
148 "Detect and create Python indentation tokens at beginning of line." |
106783
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
149 (and |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
150 (bolp) (not (wisent-python-implicit-line-joining-p)) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
151 (let ((last-indent (car wisent-python-indent-stack)) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
152 (last-pos (point)) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
153 (curr-indent (current-indentation))) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
154 (skip-syntax-forward "-") |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
155 (cond |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
156 ;; Skip comments and blank lines. No change in indentation. |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
157 ((or (eolp) (looking-at semantic-lex-comment-regex)) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
158 (forward-comment (point-max)) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
159 (or (eobp) (beginning-of-line)) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
160 (setq semantic-lex-end-point (point)) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
161 ;; Loop lexer to handle the next line. |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
162 t) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
163 ;; No change in indentation. |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
164 ((= curr-indent last-indent) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
165 (setq semantic-lex-end-point (point)) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
166 ;; Try next analyzers. |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
167 nil) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
168 ;; Indentation increased |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
169 ((> curr-indent last-indent) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
170 (if (or (not semantic-lex-maximum-depth) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
171 (< semantic-lex-current-depth semantic-lex-maximum-depth)) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
172 (progn |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
173 ;; Return an INDENT lexical token |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
174 (setq semantic-lex-current-depth (1+ semantic-lex-current-depth)) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
175 (push curr-indent wisent-python-indent-stack) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
176 (semantic-lex-push-token |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
177 (semantic-lex-token 'INDENT last-pos (point)))) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
178 ;; Add an INDENT_BLOCK token |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
179 (semantic-lex-push-token |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
180 (semantic-lex-token |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
181 'INDENT_BLOCK |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
182 (progn (beginning-of-line) (point)) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
183 (semantic-lex-unterminated-syntax-protection 'INDENT_BLOCK |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
184 (wisent-python-end-of-block) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
185 (point))))) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
186 ;; Loop lexer to handle tokens in current line. |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
187 t) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
188 ;; Indentation decreased |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
189 (t |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
190 ;; Pop items from indentation stack |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
191 (while (< curr-indent last-indent) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
192 (pop wisent-python-indent-stack) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
193 (setq semantic-lex-current-depth (1- semantic-lex-current-depth) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
194 last-indent (car wisent-python-indent-stack)) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
195 (semantic-lex-push-token |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
196 (semantic-lex-token 'DEDENT last-pos (point)))) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
197 ;; If pos did not change, then we must return nil so that |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
198 ;; other lexical analyzers can be run. |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
199 (/= last-pos (point)))))) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
200 ;; All the work was done in the above analyzer matching condition. |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
201 ) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
202 |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
203 (define-lex-regex-analyzer wisent-python-lex-end-of-line |
106800
58365d44aeda
Fix typos in CEDET docstrings.
Juanma Barranquero <lekktu@gmail.com>
parents:
106783
diff
changeset
|
204 "Detect and create Python newline tokens. |
106783
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
205 Just skip the newline character if the following line is an implicit |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
206 continuation of current line." |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
207 "\\(\n\\|\\s>\\)" |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
208 (if (wisent-python-implicit-line-joining-p) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
209 (setq semantic-lex-end-point (match-end 0)) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
210 (semantic-lex-push-token |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
211 (semantic-lex-token 'NEWLINE (point) (match-end 0))))) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
212 |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
213 (define-lex-regex-analyzer wisent-python-lex-string |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
214 "Detect and create python string tokens." |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
215 wisent-python-string-re |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
216 (semantic-lex-push-token |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
217 (semantic-lex-token |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
218 'STRING_LITERAL |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
219 (point) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
220 (semantic-lex-unterminated-syntax-protection 'STRING_LITERAL |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
221 (wisent-python-forward-string) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
222 (point))))) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
223 |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
224 (define-lex-regex-analyzer wisent-python-lex-ignore-backslash |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
225 "Detect and skip over backslash (explicit line joining) tokens. |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
226 A backslash must be the last token of a physical line, it is illegal |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
227 elsewhere on a line outside a string literal." |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
228 "\\s\\\\s-*$" |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
229 ;; Skip over the detected backslash and go to the first |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
230 ;; non-whitespace character in the next physical line. |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
231 (forward-line) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
232 (skip-syntax-forward "-") |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
233 (setq semantic-lex-end-point (point))) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
234 |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
235 (define-lex wisent-python-lexer |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
236 "Lexical Analyzer for Python code." |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
237 ;; Must analyze beginning of line first to handle indentation. |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
238 wisent-python-lex-beginning-of-line |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
239 wisent-python-lex-end-of-line |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
240 ;; Must analyze string before symbol to handle string prefix. |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
241 wisent-python-lex-string |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
242 ;; Analyzers auto-generated from grammar. |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
243 wisent-python-wy--<number>-regexp-analyzer |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
244 wisent-python-wy--<keyword>-keyword-analyzer |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
245 wisent-python-wy--<symbol>-regexp-analyzer |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
246 wisent-python-wy--<block>-block-analyzer |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
247 wisent-python-wy--<punctuation>-string-analyzer |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
248 ;; Ignored things. |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
249 wisent-python-lex-ignore-backslash |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
250 semantic-lex-ignore-whitespace |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
251 semantic-lex-ignore-comments |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
252 ;; Signal error on unhandled syntax. |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
253 semantic-lex-default-action) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
254 |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
255 ;;; Overridden Semantic API. |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
256 ;; |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
257 (define-mode-local-override semantic-lex python-mode |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
258 (start end &optional depth length) |
106800
58365d44aeda
Fix typos in CEDET docstrings.
Juanma Barranquero <lekktu@gmail.com>
parents:
106783
diff
changeset
|
259 "Lexically analyze Python code in current buffer. |
106783
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
260 See the function `semantic-lex' for the meaning of the START, END, |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
261 DEPTH and LENGTH arguments. |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
262 This function calls `wisent-python-lexer' to actually perform the |
106800
58365d44aeda
Fix typos in CEDET docstrings.
Juanma Barranquero <lekktu@gmail.com>
parents:
106783
diff
changeset
|
263 lexical analysis, then emits the necessary Python DEDENT tokens from |
106783
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
264 what remains in the `wisent-python-indent-stack'." |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
265 (let* ((wisent-python-indent-stack (list 0)) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
266 (stream (wisent-python-lexer start end depth length)) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
267 (semantic-lex-token-stream nil)) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
268 ;; Emit DEDENT tokens if something remains in the INDENT stack. |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
269 (while (> (pop wisent-python-indent-stack) 0) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
270 (semantic-lex-push-token (semantic-lex-token 'DEDENT end end))) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
271 (nconc stream (nreverse semantic-lex-token-stream)))) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
272 |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
273 (define-mode-local-override semantic-get-local-variables python-mode () |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
274 "Get the local variables based on point's context. |
106800
58365d44aeda
Fix typos in CEDET docstrings.
Juanma Barranquero <lekktu@gmail.com>
parents:
106783
diff
changeset
|
275 To be implemented for Python! For now just return nil." |
106783
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
276 nil) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
277 |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
278 (defcustom-mode-local-semantic-dependency-system-include-path |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
279 python-mode semantic-python-dependency-system-include-path |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
280 nil |
106800
58365d44aeda
Fix typos in CEDET docstrings.
Juanma Barranquero <lekktu@gmail.com>
parents:
106783
diff
changeset
|
281 "The system include path used by Python language.") |
106783
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
282 |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
283 ;;; Enable Semantic in `python-mode'. |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
284 ;; |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
285 |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
286 ;;;###autoload |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
287 (defun wisent-python-default-setup () |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
288 "Setup buffer for parse." |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
289 (wisent-python-wy--install-parser) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
290 (set (make-local-variable 'parse-sexp-ignore-comments) t) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
291 (setq |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
292 ;; Character used to separation a parent/child relationship |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
293 semantic-type-relation-separator-character '(".") |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
294 semantic-command-separation-character ";" |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
295 ;; The following is no more necessary as semantic-lex is overriden |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
296 ;; in python-mode. |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
297 ;; semantic-lex-analyzer 'wisent-python-lexer |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
298 |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
299 ;; Semantic to take over from the one provided by python. |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
300 ;; The python one, if it uses the senator advice, will hang |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
301 ;; Emacs unrecoverably. |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
302 imenu-create-index-function 'semantic-create-imenu-index |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
303 |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
304 ;; I need a python guru to update this list: |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
305 semantic-symbol->name-assoc-list-for-type-parts '((variable . "Variables") |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
306 (function . "Methods")) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
307 semantic-symbol->name-assoc-list '((type . "Classes") |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
308 (variable . "Variables") |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
309 (function . "Functions") |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
310 (include . "Imports") |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
311 (package . "Package") |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
312 (code . "Code"))) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
313 ) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
314 |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
315 ;;;###autoload |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
316 (add-hook 'python-mode-hook 'wisent-python-default-setup) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
317 |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
318 ;; Make sure the newer python modes pull in the same python |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
319 ;; mode overrides. |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
320 (define-child-mode python-2-mode python-mode "Python 2 mode") |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
321 (define-child-mode python-3-mode python-mode "Python 3 mode") |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
322 |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
323 |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
324 ;;; Test |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
325 ;; |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
326 (defun wisent-python-lex-buffer () |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
327 "Run `wisent-python-lexer' on current buffer." |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
328 (interactive) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
329 (semantic-lex-init) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
330 (let ((token-stream (semantic-lex (point-min) (point-max) 0))) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
331 (with-current-buffer (get-buffer-create "*wisent-python-lexer*") |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
332 (erase-buffer) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
333 (pp token-stream (current-buffer)) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
334 (goto-char (point-min)) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
335 (pop-to-buffer (current-buffer))))) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
336 |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
337 (provide 'semantic/wisent/python) |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
338 |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
339 ;; Local variables: |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
340 ;; generated-autoload-file: "../loaddefs.el" |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
341 ;; generated-autoload-load-name: "semantic/wisent/python" |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
342 ;; End: |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
343 |
fc2b73c71e0f
Add Semantic parsers for Python.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
344 ;;; semantic/wisent/python.el ends here |