Function: antlr-option-level

antlr-option-level is a byte-compiled function defined in antlr-mode.el.gz.

Signature

(antlr-option-level REQUESTED)

Documentation

Return level for option to insert near point.

Remove any restrictions from current buffer and return level for the option to insert near point, i.e., 1, 2, 3, 4, or nil if no such option can be inserted. If REQUESTED is non-nil, it is the only possible value to return except nil. If REQUESTED is nil, return level for the nearest option kind, i.e., the highest number possible.

If the result is 2, point is at the beginning of the class after the class definition. If the result is 3 or 4, point is at the beginning of the rule/subrule after the init action. Otherwise, the point position is undefined.

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/antlr-mode.el.gz
(defun antlr-option-level (requested)
  "Return level for option to insert near point.
Remove any restrictions from current buffer and return level for the
option to insert near point, i.e., 1, 2, 3, 4, or nil if no such option
can be inserted.  If REQUESTED is non-nil, it is the only possible value
to return except nil.  If REQUESTED is nil, return level for the nearest
option kind, i.e., the highest number possible.

If the result is 2, point is at the beginning of the class after the
class definition.  If the result is 3 or 4, point is at the beginning of
the rule/subrule after the init action.  Otherwise, the point position
is undefined."
  (widen)
  (if (eq requested 1)
      1
    (with-syntax-table antlr-action-syntax-table
      (antlr-invalidate-context-cache)
      (let* ((orig (point))
	     (outsidep (antlr-outside-rule-p))
	     bor depth)
	(if (eq (char-after) ?\{) (antlr-skip-sexps 1))
	(setq bor (point))		; beginning of rule (after init action)
	(cond ((eq requested 2)		; grammar options required?
	       (let (boc)		; beginning of class
		 (goto-char (point-min))
		 (while (and (<= (point) bor)
			     (antlr-re-search-forward antlr-class-header-regexp
						      nil))
		   (if (<= (match-beginning 0) bor)
		       (setq boc (match-end 0))))
		 (when boc
		   (goto-char boc)
		   2)))
	      ((save-excursion		; in region of file options?
		 (goto-char (point-min))
		 (antlr-skip-file-prelude t) ; ws/comment after: OK
		 (< orig (point)))
	       (and (null requested) 1))
	      (outsidep			; outside rule not OK
	       nil)
	      ((looking-at antlr-class-header-regexp) ; rule = class def?
	       (goto-char (match-end 0))
	       (and (null requested) 2))
	      ((eq requested 3)		; rule options required?
	       (goto-char bor)
	       3)
	      ((setq depth (antlr-syntactic-grammar-depth orig bor))
	       (if (> depth 0)		; move out of actions
		   (goto-char (scan-lists (point) -1 depth)))
	       (set-syntax-table antlr-mode-syntax-table)
	       (antlr-invalidate-context-cache)
	       (if (eq (antlr-syntactic-context) 0) ; not in subrule?
		   (unless (eq requested 4)
		     (goto-char bor)
		     3)
		 (goto-char (1+ (scan-lists (point) -1 1)))
		 4)))))))