FUEL: Improved highlighting of stack effect declarations for alien functions. Types are highlighted bold using the new face factor-font-lock-type-in-stack-effect.

db4
Björn Lindqvist 2013-09-20 16:35:49 +02:00 committed by John Benediktsson
parent ccda289400
commit 86712433cd
1 changed files with 45 additions and 14 deletions

View File

@ -167,6 +167,12 @@ source/docs/tests file. When set to false, you'll be asked only once."
:group 'factor-faces
:group 'faces)
(defface factor-font-lock-type-in-stack-effect '((t :inherit font-lock-comment-face
:bold t))
"Face for Factor types in stack effect declarations."
:group 'factor-faces
:group 'faces)
;;; Thing-at-point:
@ -201,7 +207,7 @@ source/docs/tests file. When set to false, you'll be asked only once."
"CONSULT:" "call-next-method"
"DEFER:" "DESTRUCTOR:"
"EBNF:" ";EBNF" "ENUM:" "ERROR:" "EXCLUDE:"
"FORGET:" "FROM:" "FUNCTION:" "FUNCTION-ALIAS:"
"FORGET:" "FROM:" "FUNCTION-ALIAS:"
"GAME:" "GENERIC#" "GENERIC:"
"GLSL-SHADER:" "GLSL-PROGRAM:"
"HELP:" "HINTS:" "HOOK:"
@ -310,7 +316,7 @@ source/docs/tests file. When set to false, you'll be asked only once."
(factor-second-word-regex '("&:" "SYMBOL:" "VAR:" "CONSTANT:")))
(defconst factor-stack-effect-regex
"\\( ( [^\n]* )\\)\\|\\( (( [^\n]* ))\\)")
"\\( ( [^)]* )\\)\\|\\( (( [^)]* ))\\)")
(defconst factor-use-line-regex "^USE: +\\(.*\\)$")
@ -318,9 +324,6 @@ source/docs/tests file. When set to false, you'll be asked only once."
(defconst factor-sub-vocab-regex "^<\\([^ \n]+\\) *$")
(defconst factor-alien-function-regex
(format "\\_<FUNCTION: +%s[\n ]+%s" symbol symbol))
(defconst factor-alien-function-alias-regex
"\\_<FUNCTION-ALIAS: +\\(\\w+\\)[\n ]+\\(\\w+\\)[\n ]+\\(\\w+\\)")
@ -418,10 +421,7 @@ source/docs/tests file. When set to false, you'll be asked only once."
;;; Font lock:
(defconst factor-font-lock-keywords
`((,factor-stack-effect-regex . 'factor-font-lock-stack-effect)
(,factor-brace-words-regex 1 'factor-font-lock-parsing-word)
(,factor-alien-function-regex (1 'factor-font-lock-type-name)
(2 'factor-font-lock-word))
`((,factor-brace-words-regex 1 'factor-font-lock-parsing-word)
(,factor-alien-function-alias-regex (1 'factor-font-lock-word)
(2 'factor-font-lock-type-name)
(3 'factor-font-lock-word))
@ -471,7 +471,6 @@ source/docs/tests file. When set to false, you'll be asked only once."
;; definition that is terminated with ";" is searched for words
;; that are slot names which are highlighted with the face
;; factor-font-lock-symbol.
(,(format
"\\(%s\\):[ \n]+%s\\(?:[ \n]+<[ \n]+%s\\)?"
(regexp-opt '("STRUCT" "TUPLE" "UNION-STRUCT"))
@ -483,14 +482,41 @@ source/docs/tests file. When set to false, you'll be asked only once."
;; A slot is either a single symbol or a sequence along the
;; lines: { foo initial: "bar }
("\\(\\(?:\\sw\\|\\s_\\)+\\)\\|\\(?:{[ \n]+\\(\\(?:\\sw\\|\\s_\\)+\\)[^}]+\\)"
((lambda (&rest foo)
(save-excursion
(re-search-forward " ;" nil t)
(1- (point)))))
(factor-find-end-of-def)
nil
(1 'factor-font-lock-symbol nil t)
(2 'factor-font-lock-symbol nil t)))
;; Highlights alien function definitions. Types in stack effect
;; declarations are given a bold face.
(,(format "\\(\\(?:GL-\\)?FUNCTION\\):[ \n]+%s[ \n]+%s[ \n]+" symbol symbol)
(1 'factor-font-lock-parsing-word)
(2 'factor-font-lock-type-name)
(3 'factor-font-lock-word)
;; Regexp from hell that puts every type name in the first group,
;; names and brackets in the second and third.
("\\(?:\\(\\(?:\\sw\\|\\s_\\)+\\)[ \n]+\\(\\(?:\\sw\\|\\s_\\)+,?\\(?:[ \n]+)\\)?\\)\\|\\([()]\\)\\)"
(factor-find-end-of-def)
nil
(1 'factor-font-lock-type-in-stack-effect nil t)
(2 'factor-font-lock-stack-effect nil t)
(3 'factor-font-lock-stack-effect nil t)))
;; Almost identical to the previous one, but for function aliases.
(,(format "\\(FUNCTION-ALIAS\\):[ \n]+%s[ \n]+%s[ \n]+%s[ \n]+"
symbol symbol symbol)
(1 'factor-font-lock-parsing-word)
(2 'factor-font-lock-word)
(3 'factor-font-lock-type-name)
(4 'factor-font-lock-word)
("\\(?:\\(\\(?:\\sw\\|\\s_\\)+\\)[ \n]+\\(\\(?:\\sw\\|\\s_\\)+,?\\(?:[ \n]+)\\)?\\)\\|\\([()]\\)\\)"
(factor-find-end-of-def)
nil
(1 'factor-font-lock-type-in-stack-effect nil t)
(2 'factor-font-lock-stack-effect nil t)
(3 'factor-font-lock-stack-effect nil t)))
(,factor-stack-effect-regex . 'factor-font-lock-stack-effect)
(,factor-constructor-regex . 'factor-font-lock-constructor)
(,factor-setter-regex . 'factor-font-lock-setter-word)
(,factor-getter-regex . 'factor-font-lock-getter-word)
@ -619,6 +645,11 @@ source/docs/tests file. When set to false, you'll be asked only once."
(defsubst factor-beginning-of-sexp-pos ()
(save-excursion (factor-beginning-of-sexp) (point)))
(defun factor-find-end-of-def (&rest foo)
(save-excursion
(re-search-forward " ;" nil t)
(1- (point))))
;;; USING/IN: