2008-12-05 22:34:25 -05:00
|
|
|
|
;;; fuel-font-lock.el -- font lock for factor code
|
|
|
|
|
|
2009-01-03 10:37:28 -05:00
|
|
|
|
;; Copyright (C) 2008, 2009 Jose Antonio Ortega Ruiz
|
2008-12-05 22:34:25 -05:00
|
|
|
|
;; See http://factorcode.org/license.txt for BSD license.
|
|
|
|
|
|
|
|
|
|
;; Author: Jose Antonio Ortega Ruiz <jao@gnu.org>
|
|
|
|
|
;; Keywords: languages, fuel, factor
|
|
|
|
|
;; Start date: Wed Dec 03, 2008 21:40
|
|
|
|
|
|
|
|
|
|
;;; Comentary:
|
|
|
|
|
|
|
|
|
|
;; Font lock setup for highlighting Factor code.
|
|
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
|
|
|
|
|
(require 'fuel-syntax)
|
2008-12-18 06:11:59 -05:00
|
|
|
|
(require 'fuel-base)
|
2008-12-05 22:34:25 -05:00
|
|
|
|
|
|
|
|
|
(require 'font-lock)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; Faces:
|
|
|
|
|
|
2008-12-21 10:47:16 -05:00
|
|
|
|
(defgroup fuel-faces nil
|
|
|
|
|
"Faces used by FUEL."
|
|
|
|
|
:group 'fuel
|
|
|
|
|
:group 'faces)
|
|
|
|
|
|
|
|
|
|
(defmacro fuel-font-lock--defface (face def group doc)
|
|
|
|
|
`(defface ,face (face-default-spec ,def)
|
|
|
|
|
,(format "Face for %s." doc)
|
|
|
|
|
:group ',group
|
|
|
|
|
:group 'fuel-faces
|
|
|
|
|
:group 'faces))
|
|
|
|
|
|
|
|
|
|
(put 'fuel-font-lock--defface 'lisp-indent-function 1)
|
|
|
|
|
|
2008-12-08 20:36:55 -05:00
|
|
|
|
(defmacro fuel-font-lock--make-face (prefix def-prefix group face def doc)
|
|
|
|
|
(let ((face (intern (format "%s-%s" prefix face)))
|
|
|
|
|
(def (intern (format "%s-%s-face" def-prefix def))))
|
2008-12-21 10:47:16 -05:00
|
|
|
|
`(fuel-font-lock--defface ,face ,def ,group ,doc)))
|
2008-12-05 22:34:25 -05:00
|
|
|
|
|
2008-12-08 20:36:55 -05:00
|
|
|
|
(defmacro fuel-font-lock--define-faces (prefix def-prefix group faces)
|
|
|
|
|
(let ((setup (make-symbol (format "%s--faces-setup" prefix))))
|
|
|
|
|
`(progn
|
|
|
|
|
(defmacro ,setup ()
|
|
|
|
|
(cons 'progn
|
|
|
|
|
(mapcar (lambda (f) (append '(fuel-font-lock--make-face
|
|
|
|
|
,prefix ,def-prefix ,group) f))
|
|
|
|
|
',faces)))
|
|
|
|
|
(,setup))))
|
2008-12-05 22:34:25 -05:00
|
|
|
|
|
2008-12-18 06:11:59 -05:00
|
|
|
|
(fuel-font-lock--define-faces
|
|
|
|
|
factor-font-lock font-lock factor-mode
|
|
|
|
|
((comment comment "comments")
|
|
|
|
|
(constructor type "constructors (<foo>)")
|
2009-01-09 18:55:39 -05:00
|
|
|
|
(constant constant "constants and literal values")
|
2009-01-10 00:40:01 -05:00
|
|
|
|
(number constant "integers and floats")
|
|
|
|
|
(ratio constant "ratios")
|
2008-12-18 06:11:59 -05:00
|
|
|
|
(declaration keyword "declaration words")
|
|
|
|
|
(parsing-word keyword "parsing words")
|
|
|
|
|
(setter-word function-name "setter words (>>foo)")
|
|
|
|
|
(getter-word function-name "getter words (foo>>)")
|
|
|
|
|
(stack-effect comment "stack effect specifications")
|
|
|
|
|
(string string "strings")
|
|
|
|
|
(symbol variable-name "name of symbol being defined")
|
|
|
|
|
(type-name type "type names")
|
|
|
|
|
(vocabulary-name constant "vocabulary names")
|
|
|
|
|
(word function-name "word, generic or method being defined")))
|
|
|
|
|
|
2008-12-05 22:34:25 -05:00
|
|
|
|
|
|
|
|
|
;;; Font lock:
|
|
|
|
|
|
|
|
|
|
(defconst fuel-font-lock--font-lock-keywords
|
2008-12-22 08:06:50 -05:00
|
|
|
|
`((,fuel-syntax--parsing-words-regex . 'factor-font-lock-parsing-word)
|
|
|
|
|
(,fuel-syntax--brace-words-regex 1 'factor-font-lock-parsing-word)
|
|
|
|
|
("\\(P\\|SBUF\\)\"" 1 'factor-font-lock-parsing-word)
|
2008-12-05 22:34:25 -05:00
|
|
|
|
(,fuel-syntax--stack-effect-regex . 'factor-font-lock-stack-effect)
|
2009-01-09 18:55:39 -05:00
|
|
|
|
(,fuel-syntax--vocab-ref-regexp 2 'factor-font-lock-vocabulary-name)
|
2008-12-22 00:58:20 -05:00
|
|
|
|
(,fuel-syntax--declaration-words-regex . 'factor-font-lock-declaration)
|
2008-12-05 22:34:25 -05:00
|
|
|
|
(,fuel-syntax--word-definition-regex 2 'factor-font-lock-word)
|
2009-01-09 18:55:39 -05:00
|
|
|
|
(,fuel-syntax--alias-definition-regex (1 'factor-font-lock-word)
|
|
|
|
|
(2 'factor-font-lock-word))
|
|
|
|
|
(,fuel-syntax--int-constant-def-regex 2 'factor-font-lock-constant)
|
2009-01-10 00:40:01 -05:00
|
|
|
|
(,fuel-syntax--integer-regex . 'factor-font-lock-number)
|
|
|
|
|
(,fuel-syntax--float-regex . 'factor-font-lock-number)
|
|
|
|
|
(,fuel-syntax--ratio-regex . 'factor-font-lock-ratio)
|
2008-12-05 22:34:25 -05:00
|
|
|
|
(,fuel-syntax--type-definition-regex 2 'factor-font-lock-type-name)
|
|
|
|
|
(,fuel-syntax--method-definition-regex (1 'factor-font-lock-type-name)
|
|
|
|
|
(2 'factor-font-lock-word))
|
2009-01-09 18:55:39 -05:00
|
|
|
|
(,fuel-syntax--parent-type-regex 2 'factor-font-lock-type-name)
|
2008-12-05 22:34:25 -05:00
|
|
|
|
(,fuel-syntax--constructor-regex . 'factor-font-lock-constructor)
|
2008-12-22 00:58:20 -05:00
|
|
|
|
(,fuel-syntax--setter-regex . 'factor-font-lock-setter-word)
|
|
|
|
|
(,fuel-syntax--getter-regex . 'factor-font-lock-getter-word)
|
2009-01-09 18:55:39 -05:00
|
|
|
|
(,fuel-syntax--symbol-definition-regex 2 'factor-font-lock-symbol))
|
2008-12-05 22:34:25 -05:00
|
|
|
|
"Font lock keywords definition for Factor mode.")
|
|
|
|
|
|
|
|
|
|
(defun fuel-font-lock--font-lock-setup (&optional keywords no-syntax)
|
|
|
|
|
(set (make-local-variable 'comment-start) "! ")
|
|
|
|
|
(set (make-local-variable 'parse-sexp-lookup-properties) t)
|
|
|
|
|
(set (make-local-variable 'font-lock-comment-face) 'factor-font-lock-comment)
|
|
|
|
|
(set (make-local-variable 'font-lock-string-face) 'factor-font-lock-string)
|
|
|
|
|
(set (make-local-variable 'font-lock-defaults)
|
|
|
|
|
`(,(or keywords 'fuel-font-lock--font-lock-keywords)
|
|
|
|
|
nil nil nil nil
|
|
|
|
|
,@(if no-syntax nil
|
|
|
|
|
(list (cons 'font-lock-syntactic-keywords
|
|
|
|
|
fuel-syntax--syntactic-keywords))))))
|
|
|
|
|
|
2009-01-03 10:37:28 -05:00
|
|
|
|
|
|
|
|
|
;;; Fontify strings as Factor code:
|
|
|
|
|
|
|
|
|
|
(defvar fuel-font-lock--font-lock-buffer
|
|
|
|
|
(let ((buffer (get-buffer-create " *fuel font lock*")))
|
|
|
|
|
(set-buffer buffer)
|
|
|
|
|
(set-syntax-table fuel-syntax--syntax-table)
|
|
|
|
|
(fuel-font-lock--font-lock-setup)
|
|
|
|
|
buffer))
|
|
|
|
|
|
|
|
|
|
(defun fuel-font-lock--factor-str (str)
|
|
|
|
|
(save-current-buffer
|
|
|
|
|
(set-buffer fuel-font-lock--font-lock-buffer)
|
|
|
|
|
(erase-buffer)
|
|
|
|
|
(insert str)
|
|
|
|
|
(let ((font-lock-verbose nil)) (font-lock-fontify-buffer))
|
|
|
|
|
(buffer-string)))
|
|
|
|
|
|
|
|
|
|
|
2008-12-05 22:34:25 -05:00
|
|
|
|
(provide 'fuel-font-lock)
|
|
|
|
|
;;; fuel-font-lock.el ends here
|