前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >GitHub趋势榜第一:超级命令行工具Semantic,比较解析源代码

GitHub趋势榜第一:超级命令行工具Semantic,比较解析源代码

作者头像
新智元
发布2019-06-05 14:28:51
8250
发布2019-06-05 14:28:51
举报
文章被收录于专栏:新智元新智元

新智元报道

来源:GitHub

编辑:大明

【新智元导读】作为开发者,天天都要与源代码打交道,面对不同版本,不同语言的代码进行比较、分析,理顺开发流程往往是开发者的日常。近日,一款名为Semantic的源代码分析比较工具一举登上了GitHub趋势榜榜首,一起来看看!

作为开发者,你是否对不同源代码段之间的解析和比较困惑不已呢?今天的GitHub趋势热榜上排名第一的帖子介绍了一款多语言支持的“超级命令行工具”Semantic,或许可以解决这个令人头疼的问题。

Semantic是一个Haskell库,也是一个用于分析和比较源代码的命令行工具。

本文将从应用功能、语言支持、开发、技术和架构、许可等五个方面介绍Semantic这款工具。

用途及功能:源代码解析、比较、图应用

解析(Parse)

代码语言:javascript
复制
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)

代码语言:javascript
复制
Usage: semantic diff ([--sexpression] | [--json] | [--json-graph] | [--toc] |
                     [--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)

代码语言:javascript
复制
Usage: semantic graph ([--imports] | [--calls]) [--packages] ([--dot] | [--json]
                      | [--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. 

多语言支持:Python、Go,Java均可使用

开发环境及版本要求

我们使用cabal的Nix风格的本地版本进行开发。要快速入门,可以按照下图中的步骤:

代码语言:javascript
复制
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 -- --help

Semantic最低要求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

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2019-06-02,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 新智元 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 【新智元导读】作为开发者,天天都要与源代码打交道,面对不同版本,不同语言的代码进行比较、分析,理顺开发流程往往是开发者的日常。近日,一款名为Semantic的源代码分析比较工具一举登上了GitHub趋势榜榜首,一起来看看!
相关产品与服务
命令行工具
腾讯云命令行工具 TCCLI 是管理腾讯云资源的统一工具。使用腾讯云命令行工具,您可以快速调用腾讯云 API 来管理您的腾讯云资源。此外,您还可以基于腾讯云的命令行工具来做自动化和脚本处理,以更多样的方式进行组合和重用。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档