javascript.el 3.7 KB

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