Function: treesit-parse-string

treesit-parse-string is a byte-compiled function defined in treesit.el.gz.

Signature

(treesit-parse-string STRING LANGUAGE)

Documentation

Parse STRING using a parser for LANGUAGE.

Return the root node of the syntax tree.

Other relevant functions are documented in the treesit group.

View in manual

Shortdoc

;; treesit
(treesit-parse-string "int c = 0;" 'c)
    e.g. => #<treesit-node (translation_unit) in 1-11>

Source Code

;; Defined in /usr/src/emacs/lisp/treesit.el.gz
;;; Parser API supplement

(defun treesit-parse-string (string language)
  "Parse STRING using a parser for LANGUAGE.
Return the root node of the syntax tree."
  ;; We can't use `with-temp-buffer' because it kills the buffer when
  ;; returning from the form.
  (let ((buf (generate-new-buffer " *treesit-parse-string*")))
    (with-current-buffer buf
      (insert string)
      (treesit-parser-root-node
       (treesit-parser-create language)))))