1

elispを使用して以下をトークン化したいと思います。

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

なので:

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

バッファのからの情報に基づいていますsyntax-table

私はsymbol-table適切に設定し、現在、文字列定数を除いて正しく動作する次の関数を使用しています(ポイントが識別子または正規表現の演算子の1つにない場合は、トークンまたは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 に答える