2013-03-13 29 views
1

語法表的信息,我想elisp的使用來標記如下:使用中的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新手,所以任何指針都讚賞。

+0

順便說一句,如果你使用這個SMIE,你不需要爲字符串做任何特殊的事情:使用上面的tokenizer函數,SMIE應該已經正確解析字符串(和匹配的parens /大括號/括號)。 – Stefan 2013-03-13 18:11:30

+0

@Stefan是的,這個函數在我的SMIE代碼中使用,但也在其他地方用於標記。我認爲它不會傷害任何東西來標記SMIE的字符串,對吧? – RandomBits 2013-03-13 18:55:21

+0

事實上,如果您將字符串標記爲字符串,SMIE仍應該正常工作。 – Stefan 2013-03-13 21:28:29

回答

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)))) 

處理字符串文字。

+0

謝謝。函數'scan-sexps'是我不知道的函數。 – RandomBits 2013-03-13 18:45:34