Commit | Line | Data |
---|---|---|
bb051423 CY |
1 | ;;; semantic/wisent/javascript.el --- javascript parser support |
2 | ||
8beeeabb | 3 | ;; Copyright (C) 2005, 2009 Free Software Foundation, Inc. |
bb051423 CY |
4 | |
5 | ;; Author: Eric Ludlam <zappo@gnu.org> | |
6 | ;; Keywords: syntax | |
7 | ||
8 | ;; This file is part of GNU Emacs. | |
9 | ||
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. | |
14 | ||
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. | |
19 | ||
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/>. | |
22 | ||
23 | ;;; Commentary: | |
24 | ;; | |
25 | ;; Parser support for javascript language. | |
26 | ||
27 | ||
28 | ;;; Code: | |
29 | (require 'semantic/java) | |
30 | (require 'semantic/wisent) | |
31 | (require 'semantic/wisent/js-wy) | |
32 | ||
33 | (defun wisent-javascript-jv-expand-tag (tag) | |
34 | "Expand TAG into a list of equivalent tags, or nil. | |
35 | Expand multiple variable declarations in the same statement, that is | |
36 | tags of class `variable' whose name is equal to a list of elements of | |
37 | the form (NAME VALUE START . END). NAME is a variable name. VALUE is | |
38 | an initializer START and END are the bounds in the declaration, related | |
39 | to this variable NAME." | |
40 | (let (elts elt value clone start end xpand) | |
41 | (when (and (eq 'variable (semantic-tag-class tag)) | |
42 | (consp (setq elts (semantic-tag-name tag)))) | |
43 | ;; There are multiple names in the same variable declaration. | |
44 | (while elts | |
45 | ;; For each name element, clone the initial tag and give it | |
46 | ;; the name of the element. | |
47 | (setq elt (car elts) | |
48 | elts (cdr elts) | |
49 | clone (semantic-tag-clone tag (car elt)) | |
50 | value (car (cdr elt)) | |
51 | start (if elts (caddr elt) (semantic-tag-start tag)) | |
52 | end (if xpand (cdddr elt) (semantic-tag-end tag)) | |
53 | xpand (cons clone xpand)) | |
54 | ;; Set the definition of the cloned tag | |
55 | (semantic-tag-put-attribute clone :default-value value) | |
56 | ;; Set the bounds of the cloned tag with those of the name | |
57 | ;; element. | |
58 | (semantic-tag-set-bounds clone start end)) | |
59 | xpand))) | |
60 | ||
61 | ;;; Override Methods | |
62 | ;; | |
63 | ;; These methods override aspects of how semantic-tools can access | |
64 | ;; the tags created by the javascript parser. | |
65 | ;; Local context | |
66 | (define-mode-overload-implementation semantic-get-local-variables | |
67 | javascript-mode () | |
68 | "Get local values from a specific context. | |
69 | This function overrides `get-local-variables'." | |
70 | ;; Does javascript have identifiable local variables? | |
71 | nil) | |
72 | ||
73 | ||
74 | ;;; Setup Function | |
75 | ;; | |
76 | ;; This sets up the javascript parser | |
77 | ||
f3628edd GM |
78 | ;; In semantic-imenu.el, not part of Emacs. |
79 | (defvar semantic-imenu-summary-function) | |
80 | ||
bb051423 CY |
81 | ;;;###autoload |
82 | (defun wisent-javascript-setup-parser () | |
83 | "Setup buffer for parse." | |
84 | (wisent-javascript-jv-wy--install-parser) | |
85 | (setq | |
86 | ;; Lexical Analysis | |
87 | semantic-lex-analyzer 'javascript-lexer-jv | |
88 | semantic-lex-number-expression semantic-java-number-regexp | |
89 | ;; semantic-lex-depth nil ;; Full lexical analysis | |
90 | ;; Parsing | |
91 | semantic-tag-expand-function 'wisent-javascript-jv-expand-tag | |
92 | ;; Environment | |
93 | semantic-imenu-summary-function 'semantic-format-tag-name | |
94 | imenu-create-index-function 'semantic-create-imenu-index | |
95 | semantic-command-separation-character ";" | |
96 | )) | |
97 | ||
bb051423 CY |
98 | (provide 'semantic/wisent/javascript-jv) |
99 | ||
100 | ;; Local variables: | |
101 | ;; generated-autoload-file: "../loaddefs.el" | |
102 | ;; generated-autoload-feature: semantic/loaddefs | |
103 | ;; generated-autoload-load-name: "semantic/wisent/javascript" | |
104 | ;; End: | |
105 | ||
3999968a | 106 | ;; arch-tag: 15416a3a-84ca-4b3b-a13c-e7a1891ec3ea |
bb051423 | 107 | ;;; semantic/wisent/javascript-jv.el ends here |