2013-01-02 109 views
1

需要將每行解析的過程輸出分解爲結構。收集緩衝區的行

sug skProc strutils.capitalize proc (string): string{.noSideEffect.} 
sug skProc strutils.quoteIfContainsWhite proc (string): string 
sug skProc system.gorge proc (string, string): string 
sug skProc system.of proc (T, S): bool{.noSideEffect.} 
sug skProc system.definedInScope proc (expr): bool{.noSideEffect.} 
sug skIterator system.items iterator (cstring): char{.inline.} 
sug skProc system.ord proc (T): int{.noSideEffect.} 

該數據位於緩衝區內。那麼如何讀取每一行並將它傳遞給一個返回解析表示並收集所有 行的函數呢?

編輯:

(defstruct nimrod-sug type namespace name signature) 

(defun nimrod-parse-suggestion-line (line) 
    (let ((split (split-string line "[\t\n]"))) 
    (make-nimrod-sug 
    :type (nth 1 split) 
    :namespace (first (split-string (nth 2 split) "\\.")) 
    :name (second (split-string (nth 2 split) "\\.")) 
    :signature (nth 3 split)) 
+0

輸出結構應該是什麼樣子? –

回答

1

對於一些小的改動解析器:用於解析線(未調試)代碼

(defun nimrod-parse-suggestion-line (line) 
    (destructuring-bind (_ type fn &rest sig) (split-string line "[[:space:]]+" t) 
    (make-nimrod-sug :type  type 
        :namespace (first (split-string fn "\\.")) 
        :name  (second (split-string fn "\\.")) 
        :signature (apply 'concat sig))))  

假設緩衝區的名字是*output*,可以像這樣解析它:

(with-current-buffer "*output*" 
    (mapcar 'nimrod-parse-suggestion-line 
      (split-string (buffer-string) "[\r\n]" t))) 

; => ([cl-struct-nimrod-sug "skProc" "strutils" "capitalize" "proc(string):string{.noSideEffect.}"] ...) 

如果您當前正在訪問輸出緩衝區,則您不會編輯with-current-buffer包裝。