Function: ebnf-eliminate-empty
ebnf-eliminate-empty is a byte-compiled function defined in
ebnf-otz.el.gz.
Signature
(ebnf-eliminate-empty RULE)
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/ebnf-otz.el.gz
;; [production width-func entry height width name production action]
;; [sequence width-func entry height width list]
;; [alternative width-func entry height width list]
;; [non-terminal width-func entry height width name default]
;; [empty width-func entry height width]
;; [terminal width-func entry height width name default]
;; [special width-func entry height width name default]
(defun ebnf-eliminate-empty (rule)
(let ((kind (ebnf-node-kind rule)))
(cond
;; non-terminal
((eq kind 'ebnf-generate-non-terminal)
(if (member (ebnf-node-name rule) ebnf-empty-rule-list)
nil
rule))
;; sequence
((eq kind 'ebnf-generate-sequence)
(let ((seq (ebnf-node-list rule))
(header (ebnf-node-list rule))
before elt)
(while seq
(setq elt (car seq))
(if (ebnf-eliminate-empty elt)
(setq before seq)
(if before
(setcdr before (cdr seq))
(setq header (cdr header))))
(setq seq (cdr seq)))
(when header
(ebnf-node-list rule header)
rule)))
;; alternative
((eq kind 'ebnf-generate-alternative)
(let ((seq (ebnf-node-list rule))
(header (ebnf-node-list rule))
before elt)
(while seq
(setq elt (car seq))
(if (ebnf-eliminate-empty elt)
(setq before seq)
(if before
(setcdr before (cdr seq))
(setq header (cdr header))))
(setq seq (cdr seq)))
(when header
(if (= (length header) 1)
(car header)
(ebnf-node-list rule header)
rule))))
;; production
((eq kind 'ebnf-generate-production)
(let ((prod (ebnf-eliminate-empty (ebnf-node-production rule))))
(when prod
(ebnf-node-production rule prod)
rule)))
;; terminal, special and empty
(t
rule)
)))