           symbol ws+
           "\\(=>\\)" ws+ symbols-to-semicolon))
 
+(defconst factor-group-name-to-face
+  #s(hash-table test equal data
+                ("C" 'factor-font-lock-comment
+                 "CO" 'factor-font-lock-constructor
+                 "CT" 'factor-font-lock-constant
+                 "P" 'factor-font-lock-parsing-word
+                 "V" 'factor-font-lock-vocabulary-name
+                 "T" 'factor-font-lock-type-name
+                 "W" 'factor-font-lock-word)))
+
+(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)
+              (setq i (1+ i))
+              (list i (factor-group-name-to-face x)))
+            groups)))
+
+(defun factor-syntax (regex groups)
+  (append (list regex) (factor-groups-to-font-lock groups)))
+
  
 ;;; Font lock:
 
 (defconst factor-font-lock-keywords
   `(
-    (,factor-brace-words-regex 1 'factor-font-lock-parsing-word)
-    (,factor-vocab-ref-regex (1 'factor-font-lock-parsing-word)
-                             (2 'factor-font-lock-vocabulary-name))
-    (,factor-using-lines-regex (1 'factor-font-lock-parsing-word)
-                               (2 'factor-font-lock-vocabulary-name)
-                               (3 'factor-font-lock-parsing-word))
-    (,factor-symbols-lines-regex (1 'factor-font-lock-parsing-word)
-                                 (2 'factor-font-lock-word)
-                                 (3 'factor-font-lock-parsing-word))
-    (,factor-from/exclude-regex (1 'factor-font-lock-parsing-word)
-                                (2 'factor-font-lock-vocabulary-name)
-                                (3 'factor-font-lock-parsing-word)
-                                (4 'factor-font-lock-word)
-                                (5 'factor-font-lock-parsing-word))
-    (,factor-rename-regex (1 'factor-font-lock-parsing-word)
-                          (2 'factor-font-lock-word)
-                          (3 'factor-font-lock-vocabulary-name)
-                          (4 'factor-font-lock-parsing-word)
-                          (5 'factor-font-lock-word))
-    (,factor-constructor-decl-regex (1 'factor-font-lock-parsing-word)
-                                    (2 'factor-font-lock-word)
-                                    (3 'factor-font-lock-type-name))
-    (,factor-symbol-definition-regex (1 'factor-font-lock-parsing-word)
-                                     (2 'factor-font-lock-word))
-    (,factor-typedef-regex (1 'factor-font-lock-parsing-word)
-                           (2 'factor-font-lock-type-name)
-                           (3 'factor-font-lock-type-name))
-    (,factor-c-global-regex (1 'factor-font-lock-type-name)
-                            (2 'factor-font-lock-word)
-                            (3 'factor-font-lock-invalid-syntax nil t))
-    (,factor-c-type-regex (1 'factor-font-lock-type-name)
-                          (2 'factor-font-lock-invalid-syntax nil t))
-    (,factor-rename-regex (1 'factor-font-lock-word)
-                          (2 'factor-font-lock-vocabulary-name)
-                          (3 'factor-font-lock-word)
-                          (4 'factor-font-lock-invalid-syntax nil t))
-    (,factor-declaration-words-regex . 'factor-font-lock-comment)
-    (,factor-word-definition-regex (1 'factor-font-lock-parsing-word)
-                                   (2 'factor-font-lock-word))
-    (,factor-alias-regex (1 'factor-font-lock-parsing-word)
-                         (2 'factor-font-lock-word)
-                         (3 'factor-font-lock-word))
-    (,factor-qualified-with-regex (1 'factor-font-lock-parsing-word)
-                                  (2 'factor-font-lock-vocabulary-name)
-                                  (3 'factor-font-lock-word))
-    (,factor-int-constant-def-regex 2 'factor-font-lock-constant)
+    ,(factor-syntax factor-brace-words-regex '("P"))
+    ,(factor-syntax factor-vocab-ref-regex '("P" "V"))
+    ,(factor-syntax factor-using-lines-regex '("P" "V" "P"))
+    ,(factor-syntax factor-symbols-lines-regex '("P" "W" "P"))
+    ,(factor-syntax factor-from/exclude-regex '("P" "V" "P" "W" "P"))
+    ,(factor-syntax (syntax-and-2-symbols '("C")) '("P" "W" "T"))
+    ,(factor-syntax factor-symbol-definition-regex '("P" "W"))
+    ,(factor-syntax factor-typedef-regex '("P" "T" "T"))
+    ,(factor-syntax (syntax-and-2-symbols '("C-GLOBAL")) '("P" "T" "W"))
+    ,(factor-syntax (syntax-and-2-symbols '("QUALIFIED-WITH")) '("P" "V" "W"))
+    ,(factor-syntax factor-rename-regex '("P" "W" "V" "P" "W"))
+    ,(factor-syntax factor-declaration-words-regex '("C"))
+    ,(factor-syntax factor-word-definition-regex '("P" "W"))
+    ,(factor-syntax (syntax-and-2-symbols '("ALIAS")) '("P" "W" "W"))
+    ,(factor-syntax (syntax-and-1-symbol '("ALIEN" "CHAR" "NAN")) '("P" "CT"))
     (,factor-integer-regex . 'factor-font-lock-number)
     (,factor-float-regex . 'factor-font-lock-number)
     (,factor-ratio-regex . 'factor-font-lock-ratio)
-    (,factor-type-definition-regex 2 'factor-font-lock-type-name)
-    (,factor-method-definition-regex (1 'factor-font-lock-type-name)
-                                     (2 'factor-font-lock-word))
-    (,factor-before-definition-regex (1 'factor-font-lock-type-name)
-                                     (2 'factor-font-lock-word))
-    (,factor-after-definition-regex  (1 'factor-font-lock-type-name)
-                                     (2 'factor-font-lock-word))
+    ,(factor-syntax factor-type-definition-regex '("P" "T"))
+    ,(factor-syntax (syntax-and-2-symbols '("M" "M:" "BEFORE" "AFTER"))
+                    '("P" "T" "W"))
 
     ;; Highlights tuple and struct definitions. The TUPLE/STRUCT
     ;; parsing word, class name and optional parent classes are

;; Excludes parsing words that are handled by other regexps
(defconst factor-parsing-words
  '(":" "::" ";" ":>" "&:" "<<" "<PRIVATE" ">>"
    "ABOUT:" "AFTER:" "ALIEN:" "ARTICLE:"
    "B" "BEFORE:"
    "C-GLOBAL:" "C-TYPE:" "CHAR:" "COLOR:" "COM-INTERFACE:"
    "CONSULT:" "call-next-method"
    "EBNF:" ";EBNF" "ENUM:" "ERROR:"
    "FOREIGN-ATOMIC-TYPE:" "FOREIGN-ENUM-TYPE:" "FOREIGN-RECORD-TYPE:" "FUNCTION-ALIAS:"

      (2 'factor-font-lock-stack-effect nil t)
      (3 'factor-font-lock-stack-effect nil t)))
    (factor-match-brackets . 'factor-font-lock-stack-effect)
    ,(factor-syntax factor-constructor-regex '("CO"))
    (,factor-setter-regex . 'factor-font-lock-setter-word)
    (,factor-getter-regex . 'factor-font-lock-getter-word)
    (,factor-bad-string-regex . 'factor-font-lock-invalid-syntax)
    ("\\_<\\(P\\|SBUF\\|DLL\\)\"" 1 'factor-font-lock-parsing-word)
    (,factor-constant-words-regex . 'factor-font-lock-constant)
    ,(factor-syntax factor-parsing-words-regex '("P"))
    (,"\t" . 'whitespace-highlight-face)))

;; Handling of multi-line constructs
