FUEL: Improved font-locking. Colors for USING expressions, hexadecimal numbers and tuple slots.
parent
086bba3403
commit
830637c84d
|
@ -195,6 +195,7 @@ source/docs/tests file. When set to false, you'll be asked only once."
|
||||||
|
|
||||||
;;; Regexps galore:
|
;;; Regexps galore:
|
||||||
|
|
||||||
|
;; Excludes parsing words that are handled by other regexps
|
||||||
(defconst factor-parsing-words
|
(defconst factor-parsing-words
|
||||||
'(":" "::" ";" "&:" "<<" "<PRIVATE" ">>"
|
'(":" "::" ";" "&:" "<<" "<PRIVATE" ">>"
|
||||||
"ABOUT:" "AFTER:" "ALIAS:" "ALIEN:" "ARTICLE:"
|
"ABOUT:" "AFTER:" "ALIAS:" "ALIEN:" "ARTICLE:"
|
||||||
|
@ -216,9 +217,9 @@ source/docs/tests file. When set to false, you'll be asked only once."
|
||||||
"QUALIFIED-WITH:" "QUALIFIED:"
|
"QUALIFIED-WITH:" "QUALIFIED:"
|
||||||
"read-only" "RENAME:" "REQUIRE:" "REQUIRES:"
|
"read-only" "RENAME:" "REQUIRE:" "REQUIRES:"
|
||||||
"SINGLETON:" "SINGLETONS:" "SLOT:" "SPECIALIZED-ARRAY:"
|
"SINGLETON:" "SINGLETONS:" "SLOT:" "SPECIALIZED-ARRAY:"
|
||||||
"SPECIALIZED-ARRAYS:" "STRING:" "STRUCT:" "SYMBOL:" "SYMBOLS:" "SYNTAX:"
|
"SPECIALIZED-ARRAYS:" "STRING:" "STRUCT:" "SYMBOLS:" "SYNTAX:"
|
||||||
"TUPLE:" "TYPEDEF:" "TYPED:" "TYPED::"
|
"TYPEDEF:" "TYPED:" "TYPED::"
|
||||||
"UNIFORM-TUPLE:" "UNION:" "UNION-STRUCT:" "USE:" "USING:"
|
"UNIFORM-TUPLE:" "UNION:" "UNION-STRUCT:" "USE:"
|
||||||
"VARIANT:" "VERTEX-FORMAT:"))
|
"VARIANT:" "VERTEX-FORMAT:"))
|
||||||
|
|
||||||
(defconst factor-parsing-words-regex
|
(defconst factor-parsing-words-regex
|
||||||
|
@ -255,7 +256,7 @@ source/docs/tests file. When set to false, you'll be asked only once."
|
||||||
"^AFTER: +\\([^ ]+\\) +\\([^ ]+\\)")
|
"^AFTER: +\\([^ ]+\\) +\\([^ ]+\\)")
|
||||||
|
|
||||||
(defconst factor-integer-regex
|
(defconst factor-integer-regex
|
||||||
"\\_<-?[0-9]+\\_>")
|
"\\_<-?\\(0[xob]\\)?[0-9]+\\_>")
|
||||||
|
|
||||||
(defconst factor-raw-float-regex
|
(defconst factor-raw-float-regex
|
||||||
"[0-9]*\\.[0-9]*\\([eEpP][+-]?[0-9]+\\)?")
|
"[0-9]*\\.[0-9]*\\([eEpP][+-]?[0-9]+\\)?")
|
||||||
|
@ -273,32 +274,37 @@ source/docs/tests file. When set to false, you'll be asked only once."
|
||||||
"\\_<\"[^>]\\([^\"\n]\\|\\\\\"\\)*\n")
|
"\\_<\"[^>]\\([^\"\n]\\|\\\\\"\\)*\n")
|
||||||
|
|
||||||
(defconst factor-word-definition-regex
|
(defconst factor-word-definition-regex
|
||||||
(format "\\_<\\(%s\\)?: +\\_<\\(%s\\)\\_>"
|
(format "\\_<\\(%s\\)?: +\\(%s\\)"
|
||||||
(regexp-opt
|
(regexp-opt
|
||||||
'(":" "GENERIC" "DEFER" "HOOK" "MAIN" "MATH" "POSTPONE"
|
'(":" "GENERIC" "DEFER" "HOOK" "MAIN" "MATH" "POSTPONE"
|
||||||
"SYMBOL" "SYNTAX" "TYPED" "TYPED:" "RENAME"))
|
"SYNTAX" "TYPED" "TYPED:" "RENAME"))
|
||||||
"\\(\\sw\\|\\s_\\|\\s(\\|\\s)\\)+"))
|
"\\(\\sw\\|\\s_\\|\\s(\\|\\s)\\)+"))
|
||||||
|
|
||||||
(defconst factor-alias-definition-regex
|
(defconst factor-alias-definition-regex
|
||||||
"^ALIAS: +\\(\\_<.+?\\_>\\) +\\(\\_<.+?\\_>\\)")
|
"^ALIAS: +\\(\\_<.+?\\_>\\) +\\(\\_<.+?\\_>\\)")
|
||||||
|
|
||||||
(defconst factor-vocab-ref-regexp
|
(defconst factor-vocab-ref-regex
|
||||||
(factor-second-word-regex
|
(factor-second-word-regex
|
||||||
'("IN:" "USE:" "FROM:" "EXCLUDE:" "QUALIFIED:" "QUALIFIED-WITH:")))
|
'("IN:" "USE:" "FROM:" "EXCLUDE:" "QUALIFIED:" "QUALIFIED-WITH:")))
|
||||||
|
|
||||||
|
(defconst factor-using-lines-regex "^\\(USING\\):[ \n]+\\([^;]+\\);")
|
||||||
|
|
||||||
(defconst factor-int-constant-def-regex
|
(defconst factor-int-constant-def-regex
|
||||||
(factor-second-word-regex '("ALIEN:" "CHAR:" "NAN:")))
|
(factor-second-word-regex '("ALIEN:" "CHAR:" "NAN:")))
|
||||||
|
|
||||||
(defconst factor-type-definition-regex
|
(defconst factor-type-definition-regex
|
||||||
(factor-second-word-regex
|
(factor-second-word-regex
|
||||||
'("C-STRUCT:" "C-UNION:" "COM-INTERFACE:" "MIXIN:" "TUPLE:" "SINGLETON:"
|
'("C-STRUCT:" "C-UNION:" "COM-INTERFACE:" "MIXIN:" "SINGLETON:"
|
||||||
"SPECIALIZED-ARRAY:" "STRUCT:" "UNION:" "UNION-STRUCT:")))
|
"SPECIALIZED-ARRAY:" "STRUCT:" "UNION:" "UNION-STRUCT:")))
|
||||||
|
|
||||||
(defconst factor-error-regex
|
(defconst factor-error-regex
|
||||||
(factor-second-word-regex '("ERROR:")))
|
(factor-second-word-regex '("ERROR:")))
|
||||||
|
|
||||||
(defconst factor-tuple-decl-regex
|
(defconst factor-simple-tuple-decl-regex
|
||||||
"^TUPLE: +\\([^ \n]+\\) +< +\\([^ \n]+\\)\\_>")
|
"\\(TUPLE\\):\\s-+\\(\\w+\\)\\s-+\\([^;]+\\);")
|
||||||
|
|
||||||
|
(defconst factor-subclassed-tuple-decl-regex
|
||||||
|
"\\(TUPLE\\):\\s-+\\(\\(?:\\sw\\|\\s_\\)+\\)\\s-+<\\s-+\\(\\(?:\\sw\\|\\s_\\)+\\)\\s-+\\([^;]+\\);")
|
||||||
|
|
||||||
(defconst factor-constructor-regex
|
(defconst factor-constructor-regex
|
||||||
"<[^ >]+>")
|
"<[^ >]+>")
|
||||||
|
@ -310,13 +316,11 @@ source/docs/tests file. When set to false, you'll be asked only once."
|
||||||
"\\_<>>.+?\\_>")
|
"\\_<>>.+?\\_>")
|
||||||
|
|
||||||
(defconst factor-symbol-definition-regex
|
(defconst factor-symbol-definition-regex
|
||||||
(factor-second-word-regex '("&:" "SYMBOL:" "VAR:")))
|
(factor-second-word-regex '("&:" "SYMBOL:" "VAR:" "CONSTANT:")))
|
||||||
|
|
||||||
(defconst factor-stack-effect-regex
|
(defconst factor-stack-effect-regex
|
||||||
"\\( ( [^\n]* )\\)\\|\\( (( [^\n]* ))\\)")
|
"\\( ( [^\n]* )\\)\\|\\( (( [^\n]* ))\\)")
|
||||||
|
|
||||||
(defconst factor-using-lines-regex "^USING: +\\([^;]+\\);")
|
|
||||||
|
|
||||||
(defconst factor-use-line-regex "^USE: +\\(.*\\)$")
|
(defconst factor-use-line-regex "^USE: +\\(.*\\)$")
|
||||||
|
|
||||||
(defconst factor-current-vocab-regex "^IN: +\\([^ \r\n\f]+\\)")
|
(defconst factor-current-vocab-regex "^IN: +\\([^ \r\n\f]+\\)")
|
||||||
|
@ -379,10 +383,9 @@ source/docs/tests file. When set to false, you'll be asked only once."
|
||||||
"POSTPONE:" "PRIVATE>" "<PRIVATE"
|
"POSTPONE:" "PRIVATE>" "<PRIVATE"
|
||||||
"QUALIFIED-WITH:" "QUALIFIED:"
|
"QUALIFIED-WITH:" "QUALIFIED:"
|
||||||
"RENAME:"
|
"RENAME:"
|
||||||
"SINGLETON:" "SLOT:" "SPECIALIZED-ARRAY:" "SYMBOL:"
|
"SINGLETON:" "SLOT:" "SPECIALIZED-ARRAY:"
|
||||||
"TYPEDEF:"
|
"TYPEDEF:"
|
||||||
"USE:"
|
"USE:")))
|
||||||
"VAR:")))
|
|
||||||
|
|
||||||
(defconst factor-begin-of-def-regex
|
(defconst factor-begin-of-def-regex
|
||||||
(format "^USING: \\|\\(%s\\)\\|\\(^%s .*\\)"
|
(format "^USING: \\|\\(%s\\)\\|\\(^%s .*\\)"
|
||||||
|
@ -433,7 +436,11 @@ source/docs/tests file. When set to false, you'll be asked only once."
|
||||||
(3 'factor-font-lock-word))
|
(3 'factor-font-lock-word))
|
||||||
(,factor-alien-callback-regex (1 'factor-font-lock-type-name)
|
(,factor-alien-callback-regex (1 'factor-font-lock-type-name)
|
||||||
(2 'factor-font-lock-word))
|
(2 'factor-font-lock-word))
|
||||||
(,factor-vocab-ref-regexp 2 'factor-font-lock-vocabulary-name)
|
(,factor-vocab-ref-regex 2 'factor-font-lock-vocabulary-name)
|
||||||
|
|
||||||
|
(,factor-using-lines-regex (1 'factor-font-lock-parsing-word)
|
||||||
|
(2 'factor-font-lock-vocabulary-name))
|
||||||
|
|
||||||
(,factor-constructor-decl-regex
|
(,factor-constructor-decl-regex
|
||||||
(1 'factor-font-lock-word)
|
(1 'factor-font-lock-word)
|
||||||
(2 'factor-font-lock-type-name)
|
(2 'factor-font-lock-type-name)
|
||||||
|
@ -466,11 +473,21 @@ source/docs/tests file. When set to false, you'll be asked only once."
|
||||||
(2 'factor-font-lock-word))
|
(2 'factor-font-lock-word))
|
||||||
(,factor-after-definition-regex (1 'factor-font-lock-type-name)
|
(,factor-after-definition-regex (1 'factor-font-lock-type-name)
|
||||||
(2 'factor-font-lock-word))
|
(2 'factor-font-lock-word))
|
||||||
(,factor-tuple-decl-regex 2 'factor-font-lock-type-name)
|
|
||||||
|
;; Order is important, otherwise "<" will be colorized as a slot.
|
||||||
|
(,factor-subclassed-tuple-decl-regex (1 'factor-font-lock-parsing-word)
|
||||||
|
(2 'factor-font-lock-type-name)
|
||||||
|
(3 'factor-font-lock-type-name)
|
||||||
|
(4 'factor-font-lock-symbol))
|
||||||
|
(,factor-simple-tuple-decl-regex (1 'factor-font-lock-parsing-word)
|
||||||
|
(2 'factor-font-lock-type-name)
|
||||||
|
(3 'factor-font-lock-symbol))
|
||||||
|
|
||||||
(,factor-constructor-regex . 'factor-font-lock-constructor)
|
(,factor-constructor-regex . 'factor-font-lock-constructor)
|
||||||
(,factor-setter-regex . 'factor-font-lock-setter-word)
|
(,factor-setter-regex . 'factor-font-lock-setter-word)
|
||||||
(,factor-getter-regex . 'factor-font-lock-getter-word)
|
(,factor-getter-regex . 'factor-font-lock-getter-word)
|
||||||
(,factor-symbol-definition-regex 2 'factor-font-lock-symbol)
|
(,factor-symbol-definition-regex (1 'factor-font-lock-parsing-word)
|
||||||
|
(2 'factor-font-lock-word))
|
||||||
(,factor-bad-string-regex . 'factor-font-lock-invalid-syntax)
|
(,factor-bad-string-regex . 'factor-font-lock-invalid-syntax)
|
||||||
("\\_<\\(P\\|SBUF\\|DLL\\)\"" 1 'factor-font-lock-parsing-word)
|
("\\_<\\(P\\|SBUF\\|DLL\\)\"" 1 'factor-font-lock-parsing-word)
|
||||||
(,factor-constant-words-regex . 'factor-font-lock-constant)
|
(,factor-constant-words-regex . 'factor-font-lock-constant)
|
||||||
|
@ -556,9 +573,6 @@ source/docs/tests file. When set to false, you'll be asked only once."
|
||||||
(beginning-of-line)
|
(beginning-of-line)
|
||||||
(re-search-forward factor-constructor-regex (line-end-position) t)))
|
(re-search-forward factor-constructor-regex (line-end-position) t)))
|
||||||
|
|
||||||
(defsubst factor-at-using ()
|
|
||||||
(looking-at factor-using-lines-regex))
|
|
||||||
|
|
||||||
(defun factor-in-using ()
|
(defun factor-in-using ()
|
||||||
(let ((p (point)))
|
(let ((p (point)))
|
||||||
(save-excursion
|
(save-excursion
|
||||||
|
@ -767,6 +781,9 @@ With prefix, non-existing files will be created."
|
||||||
|
|
||||||
;;; factor-mode:
|
;;; factor-mode:
|
||||||
|
|
||||||
|
;; I think it is correct to put almost all punctuation characters in
|
||||||
|
;; the word class because Factor words can be made up of almost
|
||||||
|
;; anything. Otherwise you get incredibly annoying regexps.
|
||||||
(defvar factor-mode-syntax-table
|
(defvar factor-mode-syntax-table
|
||||||
(let ((table (make-syntax-table prog-mode-syntax-table)))
|
(let ((table (make-syntax-table prog-mode-syntax-table)))
|
||||||
(modify-syntax-entry ?\" "\"" table)
|
(modify-syntax-entry ?\" "\"" table)
|
||||||
|
@ -776,7 +793,7 @@ With prefix, non-existing files will be created."
|
||||||
(modify-syntax-entry ?$ "_" table)
|
(modify-syntax-entry ?$ "_" table)
|
||||||
(modify-syntax-entry ?@ "_" table)
|
(modify-syntax-entry ?@ "_" table)
|
||||||
(modify-syntax-entry ?? "_" table)
|
(modify-syntax-entry ?? "_" table)
|
||||||
(modify-syntax-entry ?_ "_" table)
|
(modify-syntax-entry ?_ "w" table)
|
||||||
(modify-syntax-entry ?: "_" table)
|
(modify-syntax-entry ?: "_" table)
|
||||||
(modify-syntax-entry ?< "_" table)
|
(modify-syntax-entry ?< "_" table)
|
||||||
(modify-syntax-entry ?> "_" table)
|
(modify-syntax-entry ?> "_" table)
|
||||||
|
@ -786,8 +803,8 @@ With prefix, non-existing files will be created."
|
||||||
(modify-syntax-entry ?= "_" table)
|
(modify-syntax-entry ?= "_" table)
|
||||||
(modify-syntax-entry ?/ "_" table)
|
(modify-syntax-entry ?/ "_" table)
|
||||||
(modify-syntax-entry ?+ "_" table)
|
(modify-syntax-entry ?+ "_" table)
|
||||||
(modify-syntax-entry ?* "_" table)
|
(modify-syntax-entry ?* "w" table)
|
||||||
(modify-syntax-entry ?- "_" table)
|
(modify-syntax-entry ?- "w" table)
|
||||||
(modify-syntax-entry ?\; "_" table)
|
(modify-syntax-entry ?\; "_" table)
|
||||||
(modify-syntax-entry ?\( "()" table)
|
(modify-syntax-entry ?\( "()" table)
|
||||||
(modify-syntax-entry ?\) ")(" table)
|
(modify-syntax-entry ?\) ")(" table)
|
||||||
|
|
Loading…
Reference in New Issue