我想使用elisp来标记以下内容:
variable := "The symbol \" delimits strings"; (* Comments go here *)
为:
<variable> <:=> <The symbol \" delimits strings> <;>
基于缓冲区syntax-table
的信息。
我正确地设置了symbol-table
并且正在使用以下函数,该函数除了字符串常量之外正确运行(如果point不在标识符或正则表达式中的一个运算符,则返回token或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新手,所以任何指针都会受到赞赏。
答案 0 :(得分: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))))
处理字符串文字。