1

我想使用 elisp 来标记以下内容:

variable := "The symbol \" delimits strings"; (* Comments go here *)

作为:

<variable> <:=> <The symbol \" delimits strings> <;>

基于来自缓冲区的信息syntax-table

我已经进行了symbol-table适当的设置,并且目前正在使用以下函数,该函数除了字符串常量之外正常运行(如果点不在标识符或正则表达式中的运算符之一处,则返回令牌或 nil)。

(defun forward-token ()
  (forward-comment (point-max))
  (cond
   ((looking-at  (regexp-opt '("=" ":=" "," ";")))
    (goto-char (match-end 0))
    (match-string-no-properties 0))
   (t (buffer-substring-no-properties
       (point)
       (progn (skip-syntax-forward "w_")
              (point))))))

我是一个elisp新手,所以任何指针都表示赞赏。

4

1 回答 1

1

我认为您skip-syntax-forward对字符串的使用不正确。我认为您需要添加这样的cond子句:

((looking-at "\"")
 (let* ((here (point)) (there (scan-sexps here 1)))
   (goto-char there)
   (buffer-substring-no-properties
    (1+ here) (1- there))))

处理字符串文字。

于 2013-03-13T15:20:05.223 回答