Function: meson-smie-backward-token

meson-smie-backward-token is a natively compiled function defined in meson-mode.el.

Signature

(meson-smie-backward-token)

Documentation

Move backward by one lexer token.

Source Code

;; Defined in /nix/store/57kn62wrv0z1jads9j9blmagdm8rh132-emacs-packages-deps/share/emacs/site-lisp/elpa/meson-mode-20240601.1647/meson-mode.el
(defun meson-smie-backward-token ()
  "Move backward by one lexer token."
  (let ((token 'unknown))
    (while (eq token 'unknown)
      (let ((eopl (max ;; end of previous line (to properly match "eol_cont" below it is actually a character before)
		   (1- (line-end-position 0))
		   (point-min)))
	    (ppss (syntax-ppss)))
	;; Skip comments
	(when (nth 4 ppss)		 ; We are in a comment
	  (goto-char (nth 8 ppss))	 ; goto its beginning
	  (setq ppss (syntax-ppss)))	 ; update ppss after move
	(setq token
	      ;; Determine token and move before it
	      (cond
	       ;; Let syntactic parser handle parentheses (even inside
	       ;; strings - this ensures that parentheses are NOT
	       ;; indented inside strings according to meson
	       ;; indentation rules)
	       ((looking-back (rx (or (syntax open-parenthesis)
				      (syntax close-parenthesis)))
			      (1- (point)))
		"")
	       ;; Check for strings. Relying on syntactic parser allows us to
	       ;; find the beginning of multi-line strings efficiently.
	       ((nth 3 ppss)		; We're inside string or
		(let ((string-start (nth 8 ppss)))
		  (when (not (equal (point) string-start))
		    (goto-char string-start)
		    "string")))
	       ((equal (char-before) ?\') ; We're just after a string
		(let* ((ppss- (syntax-ppss (1- (point)))))
		  (goto-char (nth 8 ppss-))
		  "string"))
	       ;; Regexp-based matching
	       (t (let ((tok
			 ;; Determine token but do not move before it
			 (cond
			  ((looking-back meson-keywords-regexp (- (point) meson-keywords-max-length) t)
			   (match-string-no-properties 0))
			  ((looking-back meson-literate-tokens-regexp
					 (- (point) meson-literate-tokens-max-length) t)
			   (match-string-no-properties 0))
			  ((cl-some (lambda (spec) (when (looking-back (cdr spec) eopl t) (car spec)))
				    meson-token-spec)))))
		    (when tok
		      (goto-char (match-beginning 0)) ; Go before token now
		      (setq ppss (syntax-ppss))) ; update ppss
		    tok))))
	(when (or (equal token "ignore")
		  (equal token "eol_cont")
		  (and (equal token "eol")  ; Skip EOL when:
		       (or (> (nth 0 ppss) 0) ; - inside parentheses
			   (and (looking-back ; - after operator but not inside comments
				 meson-literate-tokens-regexp
				 (- (point) meson-literate-tokens-max-length))
				(not (nth 4 ppss)))
			   (meson--comment-bolp ppss)))) ;- at empty line
	  (setq token 'unknown))))
    token))