 ;;;; (:require-patch "")
 ;;;; HISTORY :
 ;;;; $Log$
+;;;; Revision 3.9  2015/12/22 12:31:09  troche
+;;;; * build local cache before syntax highlighting
+;;;;
 ;;;; Revision 3.8  2015/12/18 15:08:46  troche
 ;;;; * use real-search
 ;;;;

;; contains the master regexp for syntax highlighting
(defvar *pjs-buffers-class-members-cache-regexp* nil)


(defconst *pjs-class-declaration-regexp*
  "^\\s-*class\\s-+\\(\\w+\\)\\s-*{")

(defun pjs-class-members ()
  (or *pjs-buffers-class-members-cache*
      (progn (generate-pjs-class-members-cache)
	     *pjs-buffers-class-members-cache*)))

(defun pjs-class-members-regexp ()
  (or *pjs-buffers-class-members-cache-regexp*
      (progn (generate-pjs-class-members-cache)
	     *pjs-buffers-class-members-cache-regexp*)))

(defun generate-pjs-class-members-cache ()
  (save-excursion
    (goto-char (point-min))
    (unless (hash-table-p *pjs-buffers-class-members-cache*)
      (setq *pjs-buffers-class-members-cache* (make-hash-table :test 'equal)))
    (unless (hash-table-p *pjs-buffers-class-members-cache-regexp*)
      (setq *pjs-buffers-class-members-cache-regexp* (make-hash-table :test 'equal)))
    
    (while (re-real-search-forward *pjs-class-declaration-regexp* nil t)
      ;; we are at the beginning of a class
      (let* ((class-name (match-string-no-properties 1))
	     (namespace  (pjs-current-namespace))
	     (members    (when (fi::lep-open-connection-p) (fi:eval-in-lisp (format "(when (fboundp 'jvs::get-pjs-class-members) (jvs::get-pjs-class-members \"%s\" \"%s\"))" class-name namespace))))
	     )
	(when members
	  (puthash (format "%s.%s" namespace class-name) members *pjs-buffers-class-members-cache*)
	  (puthash (format "%s.%s" namespace class-name) (format "\\(?:this\\.\\|[^.]\\)%s" (js--regexp-opt-symbol (loop for item in members
														       collect item)))
		   *pjs-buffers-class-members-cache-regexp*)
	  )))))
	 
	 
;;;;; buffer dependant cache for script-level var definitions and global vars
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;; global cache for function and methods definitions
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defconst *js-variable-name*
  "[_a-zA-Z][_a-zA-Z0-9]*")

(defconst *js-function-name*
  *js-variable-name*)

(defconst *js-class-name*
  *js-variable-name*)

(defconst *js-namespace-name*
  *js-variable-name*)

(defconst *js-type*
  (format "\\(?:%s\\.\\)?%s" *js-namespace-name* *js-variable-name*))

(defconst *js-function-name-with-namespace*
  (format "%s\\.%s" *js-namespace-name* *js-function-name*))

(defconst *ojs-function-method-definition-regexp* 
  (format "^\\s-*\\(?:function\\|method\\)\\s-+\\(\\%s\\).*$" *js-function-name*))

;; contains list of cons (name . documentation)
;; used for autocomplete 
