Function: antlr-file-dependencies

antlr-file-dependencies is a byte-compiled function defined in antlr-mode.el.gz.

Signature

(antlr-file-dependencies)

Documentation

Return dependencies for grammar in current buffer.

This function is for ANTLR v2 grammars only.

The result looks like (FILE (CLASSES . SUPERS) VOCABS . LANGUAGE)
  where CLASSES = ((CLASS . CLASS-EVOCAB) ...),
        SUPERS = ((SUPER . USE-EVOCAB-P) ...), and
        VOCABS = ((EVOCAB ...) . (IVOCAB ...))

FILE is the current buffer's file-name without directory part and LANGUAGE is the value of antlr-language in the current buffer. Each EVOCAB is an export vocabulary and each IVOCAB is an import vocabulary.

Each CLASS is a grammar class with its export vocabulary CLASS-EVOCAB. Each SUPER is a super-grammar class where USE-EVOCAB-P indicates whether its export vocabulary is used as an import vocabulary.

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/antlr-mode.el.gz
;;;===========================================================================
;;;  Compute dependencies
;;;===========================================================================
;; This whole section is ANTLR-v2 specific.  It is not used in v3 and v4.

(defun antlr-file-dependencies ()
  "Return dependencies for grammar in current buffer.
This function is for ANTLR v2 grammars only.

The result looks like \(FILE \(CLASSES . SUPERS) VOCABS .  LANGUAGE)
  where CLASSES = ((CLASS . CLASS-EVOCAB) ...),
        SUPERS  = ((SUPER . USE-EVOCAB-P) ...), and
        VOCABS  = ((EVOCAB ...) . (IVOCAB ...))

FILE is the current buffer's file-name without directory part and
LANGUAGE is the value of `antlr-language' in the current buffer.  Each
EVOCAB is an export vocabulary and each IVOCAB is an import vocabulary.

Each CLASS is a grammar class with its export vocabulary CLASS-EVOCAB.
Each SUPER is a super-grammar class where USE-EVOCAB-P indicates whether
its export vocabulary is used as an import vocabulary."
  (unless buffer-file-name
    (error "Grammar buffer does not visit a file"))
  (let (classes export-vocabs import-vocabs superclasses default-vocab)
    (goto-char (point-min))
    (while (antlr-re-search-forward antlr-grammar-header-regexp nil)
      ;; parse class definition --------------------------------------------
      (let* ((class (match-string-no-properties 2))
             (sclass (match-string-no-properties 4))
             ;; export vocab defaults to class name (first grammar in file)
             ;; or to the export vocab of the first grammar in file:
             (evocab (or default-vocab class))
             (ivocab nil))
        (goto-char (match-end 0))
        (antlr-c-forward-sws)
        (while (looking-at "options\\_>\\|\\(tokens\\)\\_>")
          (if (match-beginning 1)
              (antlr-skip-sexps 2)
            (goto-char (match-end 0))
            (antlr-c-forward-sws)
            ;; parse grammar option sections -------------------------------
            (when (eq (char-after (point)) ?\{)
              (let* ((beg (1+ (point)))
                     (end (1- (antlr-skip-sexps 1)))
                     (cont (point)))
		(goto-char beg)
		(if (re-search-forward "\\<exportVocab[ \t]*=[ \t]*\\([A-Za-z\300-\326\330-\337]\\(?:\\sw\\|\\s_\\)*\\)" end t)
		    (setq evocab (match-string-no-properties 1)))
		(goto-char beg)
		(if (re-search-forward "\\<importVocab[ \t]*=[ \t]*\\([A-Za-z\300-\326\330-\337]\\(?:\\sw\\|\\s_\\)*\\)" end t)
		    (setq ivocab (match-string-no-properties 1)))
		(goto-char cont)))))
        (unless (member sclass '("Parser" "Lexer" "TreeParser"))
          (let ((super (assoc sclass superclasses)))
            (if super
                (or ivocab (setcdr super t))
              (push (cons sclass (null ivocab)) superclasses))))
        ;; remember class with export vocabulary:
        (push (cons class evocab) classes)
        ;; default export vocab is export vocab of first grammar in file:
        (or default-vocab (setq default-vocab evocab))
        (or (member evocab export-vocabs) (push evocab export-vocabs))
        (or (null ivocab)
            (member ivocab import-vocabs) (push ivocab import-vocabs))))
    (if classes
	(cl-list* (file-name-nondirectory buffer-file-name)
                  (cons (nreverse classes) (nreverse superclasses))
                  (cons (nreverse export-vocabs) (nreverse import-vocabs))
                  antlr-action-mode))))