Function: smie-bnf--classify

smie-bnf--classify is a byte-compiled function defined in smie.el.gz.

Signature

(smie-bnf--classify BNF)

Documentation

Return a table classifying terminals.

Each terminal can either be an opener, a closer, or neither.

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/smie.el.gz
(defun smie-bnf--classify (bnf)
  "Return a table classifying terminals.
Each terminal can either be an `opener', a `closer', or `neither'."
  (let ((table (make-hash-table :test #'equal))
        (alist '()))
    (dolist (category bnf)
      (puthash (car category) t table)) ;Mark non-terminals.
    (dolist (category bnf)
      (dolist (rhs (cdr category))
        (if (null (cdr rhs))
            (smie-bnf--set-class table (pop rhs) 'neither)
          (smie-bnf--set-class table (pop rhs) 'opener)
          (while (cdr rhs)              ;Remove internals.
            (smie-bnf--set-class table (pop rhs) 'neither))
          (smie-bnf--set-class table (pop rhs) 'closer))))
    (maphash (lambda (tok v)
               (when (memq v '(closer opener))
                 (push (cons tok v) alist)))
             table)
    alist))