GitHub趋势榜第一:超级命令行工具Semantic,比较解析源代码
??新智元報道??
來源:GitHub
編輯:大明
【新智元導讀】作為開發者,天天都要與源代碼打交道,面對不同版本,不同語言的代碼進行比較、分析,理順開發流程往往是開發者的日常。近日,一款名為Semantic的源代碼分析比較工具一舉登上了GitHub趨勢榜榜首,一起來看看!
作為開發者,你是否對不同源代碼段之間的解析和比較困惑不已呢?今天的GitHub趨勢熱榜上排名第一的帖子介紹了一款多語言支持的“超級命令行工具”Semantic,或許可以解決這個令人頭疼的問題。
Semantic是一個Haskell庫,也是一個用于分析和比較源代碼的命令行工具。
?
本文將從應用功能、語言支持、開發、技術和架構、許可等五個方面介紹Semantic這款工具。
解析(Parse)
Usage: semantic parse ([--sexpression] | [--json] | [--json-graph] | [--symbols]
| [--dot] | [--show] | [--quiet]) [FILES...]
Generate parse trees for path(s)
Available options:
--sexpression Output s-expression parse trees (default)
--json Output JSON parse trees
--json-graph Output JSON adjacency list
--symbols Output JSON symbol list
--dot Output DOT graph parse trees
--show Output using the Show instance (debug only, format
subject to change without notice)
--quiet Don't produce output, but show timing stats
比較(Diff)
[--dot] | [--show]) [FILE_A] [FILE_B]
Compute changes between paths
Available options:
--sexpression Output s-expression diff tree (default)
--json Output JSON diff trees
--json-graph Output JSON diff trees
--toc Output JSON table of contents diff summary
--dot Output the diff as a DOT graph
--show Output using the Show instance (debug only, format
subject to change without notice)
?
圖(Graph)
| [--show]) ([--root DIR] [--exclude-dir DIR]
DIR:LANGUAGE | FILE | --language ARG (FILES... | --stdin))
Compute a graph for a directory or from a top-level entry point module
Available options:
--imports Compute an import graph (default)
--calls Compute a call graph
--packages Include a vertex for the package, with edges from it
to each module
--dot Output in DOT graph format (default)
--json Output JSON graph
--show Output using the Show instance (debug only, format
subject to change without notice)
--root DIR Root directory of project. Optional, defaults to
entry file/directory.
--exclude-dir DIR Exclude a directory (e.g. vendor)
--language ARG The language for the analysis.
--stdin Read a list of newline-separated paths to analyze
from stdin.?
?
開發環境及版本要求我們使用cabal的Nix風格的本地版本進行開發。要快速入門,可以按照下圖中的步驟:
?
git clone git@github.com:github/semantic.git cd semantic git submodule sync --recursive && git submodule update --init --recursive --force cabal new-update cabal new-build cabal new-test cabal new-run semantic -- --helpSemantic最低要求GHC 8.6.4。我們建議使用ghcup沙箱GHC版本。我們使用的版本基于StackageLTS版。目前的LTS版本是13.13。如果您愿意,也可以使用堆棧版。
從架構上看,Semantic具備以下特點:
?
可以讀取blob。
可以為樹形保護程序的blob生成解析樹(用于編程工具的增量解析系統)。
將這些樹分配為語法的通用表示。
執行分析,計算差異,或僅返回解析樹。
以多種支持格式呈現輸出。
?
Semantic利用了許多有趣的算法和技術:
?
Myers算法(SES)如論文An O(ND)差分算法及其變化所述
RWS-Diff:在分層數據中靈活高效的變化檢測中描述的RWS。
可以單獨打開Union和數據類型。
簡要定義解釋器(Abstracting Definitional Interpreters)的實現。可擴展為基于語法術語的單點表示。
Semantic基于MIT許可。
參考鏈接:
https://github.com/github/semantic
總結
以上是生活随笔為你收集整理的GitHub趋势榜第一:超级命令行工具Semantic,比较解析源代码的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 万字综述,核心开发者全面解读PyTorc
- 下一篇: 如何入手卷积神经网络