Created
May 18, 2016 08:20
-
-
Save inlinechan/c8ae5a2ace0c4bd8f774c843d6ed9f85 to your computer and use it in GitHub Desktop.
parse-compdb.el
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; package --- Summary | |
;;; Commentary: | |
;;; Code: | |
(defun parse-compdb (db file) | |
"Parse compilation database DB of FILE and return list of include path." | |
(when (file-exists-p db) | |
(with-temp-buffer | |
(insert-file-contents db) | |
(goto-char (point-min)) | |
(let ((end (search-forward file)) | |
(begin (search-backward "\"command\":"))) | |
;; (list begin end) | |
(get-include-path-list begin end) | |
)) | |
) | |
) | |
(defun get-include-path-list (begin end) | |
"Parse from BEGIN to END and return list of include path." | |
(let ((result nil) | |
(current begin)) | |
(while (and current (< current end)) | |
(setq current (re-search-forward "-I[A-Za-z0-9-_/.]+" end t)) | |
(if (null result) | |
(setq result (list (match-string 0))) | |
(add-to-list 'result (match-string 0)))) | |
result)) | |
(parse-compdb "/home/hyungchan/source/rtags/build/compile_commands.json" | |
"/home/hyungchan/source/rtags/src/rc.cpp") | |
(provide 'parse-compdb) | |
;;; parse-compdb.el ends here |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment