 ;; Author: Karl Landstrom <karl.landstrom@brgeight.se>
 ;; Author: Daniel Colascione <dan.colascione@gmail.com>
 ;; Maintainer: Daniel Colascione <dan.colascione@gmail.com>
-;; Version: 4
-;; Date: 2009-01-06
+;; Version: 5
+;; Date: 2009-04-30
 ;; Keywords: languages, oop, javascript
 
 ;; This file is free software; you can redistribute it and/or modify

                       pos
                     (setq pos (point)))))))))

;;; Font Lock

(defun espresso--inside-param-list-p ()
  "Return non-nil iff point is inside a function parameter list."
  (condition-case err
      (save-excursion
	(up-list -1)
	(and (looking-at "(")
	     (progn (forward-symbol -1)
		    (or (looking-at "function")
			(progn (forward-symbol -1) (looking-at "function"))))))
    (error nil)))

(defconst espresso--function-heading-1-re
  (concat
   "^\\s-*function\\s-+\\(" espresso--name-re "\\)")
  "Regular expression matching the start of a function header. Match group 1
is the name of the function.")

(defconst espresso--function-heading-2-re
  (concat
   "^\\s-*\\(" espresso--name-re "\\)\\s-*:\\s-*function\\_>")
  "Regular expression matching the start of a function entry in
  an associative array. Match group 1 is the name of the function.")

(defconst espresso--macro-decl-re
  (concat "^\\s-*#\\s-*define\\s-+\\(" espresso--cpp-name-re "\\)\\s-*(")
  "Regular expression matching a CPP macro definition up to the opening
parenthesis. Match group 1 is the name of the function.")

(defconst espresso--keyword-re
  (espresso--regexp-opt-symbol
   '("abstract" "break" "case" "catch" "class" "const"
     "continue" "debugger" "default" "delete" "do" "else"
     "enum" "export" "extends" "final" "finally" "for"
     "function" "goto" "if" "implements" "import" "in"
     "instanceof" "interface" "native" "new" "package"
     "private" "protected" "public" "return" "static"
     "super" "switch" "synchronized" "throw"
     "throws" "transient" "try" "typeof" "var" "void"
     "volatile" "while" "with"))
  "Regular expression matching any JavaScript keyword.")

(defconst espresso--basic-type-re
  (espresso--regexp-opt-symbol
   '("boolean" "byte" "char" "double" "float" "int" "long"
     "short" "void"))
  "Regular expression matching any predefined type in JavaScript.")

(defconst espresso--constant-re
  (espresso--regexp-opt-symbol '("false" "null" "undefined"
                                 "true" "arguments" "this"))
  "Regular expression matching any future reserved words in JavaScript.")


(defconst espresso--font-lock-keywords-1
  (list
   "\\_<import\\_>"
   (list espresso--function-heading-1-re 1 font-lock-function-name-face)
   (list espresso--function-heading-2-re 1 font-lock-function-name-face))
  "Level one font lock.")

(defconst espresso--font-lock-keywords-2
  (append espresso--font-lock-keywords-1
          (list (list espresso--keyword-re 1 font-lock-keyword-face)
                (cons espresso--basic-type-re font-lock-type-face)
                (cons espresso--constant-re font-lock-constant-face)))
  "Level two font lock.")


;; Limitations with variable declarations: There seems to be no
;; sensible way to highlight variables occuring after an initialized

                  (espresso--beginning-of-macro))
             (c-end-of-macro))
            (t
             (setq count (1- count))))))
  (point))


