GitHub上的实用工具还是挺多的,这不,又让我找到了一个堪称神器的支持多语言的命令行工具——Semantic,Semantic是一个解析,分析和比较多种语言源代码的命令行工具,也是一个Haskell库。

十多年的北安网站建设经验,针对设计、前端、开发、售后、文案、推广等六对一服务,响应快,48小时及时工作处理。营销型网站的优势是能够根据用户设备显示端的尺寸不同,自动调整北安建站的显示方式,使网站能够适用不同显示终端,在浏览器中调整网站的宽度,无论在任何一种浏览器上浏览网站,都能展现优雅布局与设计,从而大程度地提升浏览体验。成都创新互联公司从事“北安网站设计”,“北安网站推广”以来,每个客户项目都认真落实执行。
平常解析源代码也算是程序员的家常便饭了,如果有个工具帮你一把那是最好不过的了,Semantic具体如何使用,猿妹下面一说你就明白了:
首先呢,运行semantic --help获取最新的完整选项列表:
- 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
 
Semantic使用树形图来生成解析树,现在我们拿一个简单的程序来解析你会看的更明了,打开test.A.py文件,粘贴如下:
- def Foo(x):
 - return x
 - print Foo("hi")
 
现在,让我们生成一个抽象语法树(AST)
- $ semantic parse test.A.py
 - (Statements
 - (Annotation
 - (Function
 - (Identifier)
 - (Identifier)
 - (Return
 - (Identifier)))
 - (Empty))
 - (Call
 - (Identifier)
 - (Call
 - (Identifier)
 - (TextElement)
 - (Empty))
 - (Empty)))
 
默认的s-expression输出是一种很好的格式,可以快速可视化代码结构。我们可以看到有一个声明的函数,然后有一个调用表达式,嵌套在另一个调用表达式中,它与函数调用print和Foo。你还可以使用其他的输出格式。
- 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)
 
- 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.
 
多语言支持是Semantic的一大优势,目前支持Ruby、JavaScript、typescript、Python、Go、PHP、Java等主流编程语言都支持
Semantic最低要求GHC 8.6.4和Cabal 2.4,建议使用ghcup沙箱GHC版本,为通过操作系统的软件包管理器安装的GHC软件包可能无法安装静态链接版本的GHC启动库。
- git clone git@github.com:github/semantic.git
 - cd semantic
 - script/bootstrap
 - cabal new-build
 - cabal new-test
 - cabal new-run semantic -- --help
 
创建者使用cabal的Nix风格的本地版本进行开发。要快速入门,可以按照以上操作。
目前,semantic已经在GitHub上获得 8000 个Star,450 个Fork,感兴趣的可以到GitHub上查阅更多详情
(GitHub地址:https://github.com/github/semantic)。
                分享文章:我在GitHub上又找到一个堪称神器的命令行工具
                
                分享路径:http://www.csdahua.cn/qtweb/news2/491952.html
            
网站建设、网络推广公司-快上网,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 快上网