Function: antlr-syntax-propertize-charsets

antlr-syntax-propertize-charsets is a byte-compiled function defined in antlr-mode.el.gz.

Signature

(antlr-syntax-propertize-charsets START END)

Documentation

Function used to properly highlight ANTLR v4 charsets.

This function is as value for syntax-propertize-function and makes sure that charsets like [a-z] in token rule bodies are considered literals.

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/antlr-mode.el.gz
;; font-lock.el and/or syntax.el should say something about the use of
;; `syntax-ppss' when `font-lock-syntax-table' is set - we should not use the
;; same cache for calls inside and outside font-lock, don't we?

(defun antlr-syntax-propertize-charsets (start end)
  ;; checkdoc-params: (start end)
  "Function used to properly highlight ANTLR v4 charsets.
This function is as value for `syntax-propertize-function' and makes
sure that charsets like [a-z] in token rule bodies are considered
literals."
  (goto-char start)
  (let ((mode (if (bolp) :start :next)))
    (while (< (point) end)
      (let ((context (antlr-syntactic-context)))
        (cond ((numberp context)
               (goto-char (or (ignore-errors (scan-lists (point) 1 context))
                              end)))
              ((eq mode :start)         ; TODO: only if context = 0
               (when (looking-at "fragment\\_>")
                 (forward-char 8)
                 (skip-chars-forward " \t\n"))
               (setq mode (if (antlr-upcase-p (char-after))
                              :scanner
                            (if (eq (char-syntax (char-after)) ?w)
                                :end
                              :next))))
              ((eq mode :end)
               (skip-chars-forward "^;" end)
               (while (and (< (point) end) (antlr-syntactic-context))
                 (forward-char)
                 (skip-chars-forward "^;" end))
               (setq mode :next))
              ((eq mode :next)
               (beginning-of-line 2)
               (while (and (< (point) end) (looking-at "[ \t\n@}]"))
                 (beginning-of-line 2))
               (setq mode :start))
              ((eq mode :scanner)
               (skip-chars-forward "^:;" end)
               (while (and (< (point) end) (antlr-syntactic-context))
                 (forward-char)
                 (skip-chars-forward "^:;" end))
               (if (eq (char-after) ?:)
                   (if (eq (char-after (1+ (point))) ?:)
                       (forward-char 2) ; "::" for namespace
                     (setq mode :charset))
                 (setq mode :next)))
              ((eq mode :charset)
               ;; LEXER_CHAR_SET :
               ;;     '[' ( '\\' ~('\r'|'\n') |	~('\r'|'\n'|'\\'|']') )* ']'
               (skip-chars-forward "^;[" end)
               (while (and (< (point) end) (antlr-syntactic-context))
                 (forward-char)
                 (skip-chars-forward "^;[" end))
               (if (not (eq (char-after) ?\[))
                   (setq mode :next)
                 (put-text-property (point) (progn (forward-char) (point))
                                    'syntax-table
                                    (eval-when-compile
                                      (string-to-syntax "|")))
                 (let (char (esc nil))
                   (while (and (setq char (char-after))
                               (not (eq char ?\n))
                               (or esc (not (eq char ?\]))))
                     (setq esc (if esc nil (eq char ?\\)))
                     (forward-char)))
                 (put-text-property (point) (1+ (point))
                                    'syntax-table
                                    (eval-when-compile
                                      (string-to-syntax "|"))))))))))