FUEL: font-locking improvments

Highlighting of flags{, HEX{ and of array parameters passed to c
functions.
char-rename
Björn Lindqvist 2016-08-20 03:41:51 +02:00
parent eb8ce16277
commit a26d910b06
2 changed files with 27 additions and 9 deletions

View File

@ -180,6 +180,8 @@ these lines in your .emacs:
;; Utility regexp used by other regexps to match a Factor symbol name
(setq-local symbol-nc "\\(?:\\sw\\|\\s_\\|\"\\|\\s(\\|\\s)\\|\\s\\\\)+")
(setq-local symbol (format "\\(%s\\)" symbol-nc))
(setq-local c-symbol-nc "\\(?:\\sw\\|\\s_\\|\\[\\|\\]\\)+")
(setq-local c-symbol (format "\\(%s\\)" c-symbol-nc))
(setq-local ws+ "[ \n\t]+")
(setq-local symbols-to-semicolon "\\([^;\t]*\\)\\(;\\)")
@ -239,7 +241,7 @@ these lines in your .emacs:
(regexp-opt factor-constant-words 'symbols))
(defconst factor-bracer-words
'("B" "BV" "C" "CS" "H" "HS" "S" "T" "V" "W"))
'("B" "BV" "C" "CS" "HEX" "H" "HS" "S" "T" "V" "W" "flags"))
(defconst factor-brace-words-regex
(format "%s{" (regexp-opt factor-bracer-words t)))
@ -399,6 +401,11 @@ these lines in your .emacs:
ws+ symbol
ws+ symbol ws+))
;; Regexp from hell that puts every type name in the first group,
;; names and brackets in the second and third.
(defconst factor-function-params-regex
(format "\\(?:%s%s\\(%s,?\\(?:%s)\\)?\\)\\|\\([()]\\)\\)" c-symbol ws+ c-symbol-nc ws+))
(defconst factor-function-alias-regex
(concat (syntax-begin '("FUNCTION-ALIAS"))
ws+ symbol
@ -419,7 +426,6 @@ these lines in your .emacs:
(defun factor-group-name-to-face (group-name)
(gethash group-name factor-group-name-to-face))
(defun factor-groups-to-font-lock (groups)
(let ((i 0))
(mapcar (lambda (x)
@ -452,7 +458,7 @@ these lines in your .emacs:
,(factor-syntax (syntax-and-2-symbols '("LOG")) '("P" "W" ""))
,(factor-syntax (syntax-and-1-symbol '("ALIEN" "CHAR" "NAN")) '("P" "CT"))
,(factor-syntax factor-types-lines-regex '("P" "T"))
,(factor-syntax factor-integer-regex '("N"))
(,factor-float-regex . 'factor-font-lock-number)
(,factor-ratio-regex . 'factor-font-lock-ratio)
,(factor-syntax factor-type-definition-regex '("P" "T"))
@ -499,9 +505,7 @@ these lines in your .emacs:
(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-function-params-regex
(factor-find-ending-bracket)
nil
(1 'factor-font-lock-type-in-stack-effect nil t)
@ -514,12 +518,13 @@ these lines in your .emacs:
(2 'factor-font-lock-word)
(3 'factor-font-lock-type-name)
(4 'factor-font-lock-word)
("\\(?:\\(\\(?:\\sw\\|\\s_\\)+\\)[ \n]+\\(\\(?:\\sw\\|\\s_\\)+,?\\(?:[ \n]+)\\)?\\)\\|\\([()]\\)\\)"
(,factor-function-params-regex
(factor-find-ending-bracket)
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-syntax factor-integer-regex '("N"))
(factor-match-brackets . 'factor-font-lock-stack-effect)
,(factor-syntax factor-constructor-regex '("CO"))
(,factor-setter-regex . 'factor-font-lock-setter-word)

View File

@ -1,4 +1,5 @@
USING: accessors ;
USING: accessors alien.c-types alien.syntax byte-arrays.hex kernel
literals logging math ;
IN: strange
! FUEL Syntax Demo
@ -36,7 +37,9 @@ TUPLE: tup
: slash\hack ( m -- y )
get\it>> dup >>get\it ;
LOG: what ever
: very-weird[33] ( -- ) ;
LOG: what NOTICE
TUPLE: oh\no { and/again initial: "meh" } ;
@ -77,3 +80,13 @@ ID-SYNTAX ID-SYNTAX
! ! Containers
V{ 1 2 3 } drop
HS{ 9 8 3 } drop
flags{ 10 20 } drop
! TODO: Highlight contents too.
HEX{ ab cd ef } drop
! ! Alien functions
FUNCTION: int futimes ( int id, timeval[2] times )
FUNCTION: int booyah ( int x )
FUNCTION-ALIAS: test int bah ( int* ah, int[] eh )