All Projects → quasilyte → Astnorm

quasilyte / Astnorm

Licence: mit
AST normalization experiment

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects
types
53 projects

Projects that are alternatives of or similar to Astnorm

Yaep
Yet Another Earley Parser
Stars: ✭ 110 (+161.9%)
Mutual labels:  ast, library
Math Engine
Mathematical expression parsing and calculation engine library. 数学表达式解析计算引擎库
Stars: ✭ 123 (+192.86%)
Mutual labels:  ast, library
Phplrt
PHP Language Recognition Tool
Stars: ✭ 127 (+202.38%)
Mutual labels:  ast, library
Cordova Plugin Inappbrowser
Apache Cordova Plugin inappbrowser
Stars: ✭ 994 (+2266.67%)
Mutual labels:  library
Lara Eye
Filter your Query\Builder using a structured query language
Stars: ✭ 39 (-7.14%)
Mutual labels:  library
Cppast
Library to parse and work with the C++ AST
Stars: ✭ 1,003 (+2288.1%)
Mutual labels:  ast
Cordova Firefoxos
[DEPRECATED] Apache Cordova firefoxos
Stars: ✭ 41 (-2.38%)
Mutual labels:  library
Gifloader
An Android Library to load your GIF files
Stars: ✭ 38 (-9.52%)
Mutual labels:  library
8bp
8 bits de poder ( 8 bits of power)
Stars: ✭ 41 (-2.38%)
Mutual labels:  library
Xna.js
WebGL framework strongly inspired by the XNA library
Stars: ✭ 40 (-4.76%)
Mutual labels:  library
Rxdownloader
- Reactive Extension Library for Android to download files
Stars: ✭ 40 (-4.76%)
Mutual labels:  library
Arcads
ArcAds is a DFP wrapper created by Arc Publishing with publishers in mind.
Stars: ✭ 39 (-7.14%)
Mutual labels:  library
Webrix
Powerful building blocks for React-based web applications
Stars: ✭ 41 (-2.38%)
Mutual labels:  library
Stealtool
📚 盗取手机敏感信息,Android 6.0之上兼容
Stars: ✭ 39 (-7.14%)
Mutual labels:  library
Gmtwitch
Lightweight, open source Twitch interface for Game Maker: Studio
Stars: ✭ 41 (-2.38%)
Mutual labels:  library
Olingo Odata4 Js
Mirror of Apache Olingo
Stars: ✭ 38 (-9.52%)
Mutual labels:  library
Depressurizer
A Steam library categorizing tool.
Stars: ✭ 1,008 (+2300%)
Mutual labels:  library
Easygo
基于Kotlin、OkHttp的声明式网络框架,像写HTML界面一样写网络调用代码
Stars: ✭ 40 (-4.76%)
Mutual labels:  library
Localize and translate
Flutter localization in easy steps, really simple
Stars: ✭ 40 (-4.76%)
Mutual labels:  library
Redash
Tiny functional programming suite for JavaScript.
Stars: ✭ 40 (-4.76%)
Mutual labels:  library

Go Report Card GoDoc Build Status

logo

astnorm

Go AST normalization experiment.

THIS IS NOT A PROPER LIBRARY (yet?).
DO NOT USE.
It will probably be completely re-written before it becomes usable.

Normalized code examples

  1. Swap values.
Before After
tmp := xs[i]
xs[i] = ys[i]
ys[i] = tmp
xs[i], ys[i] = ys[i], xs[i]
  1. Remove elements that are equal to toRemove+1.
Before After
const toRemove = 10
var filtered []int
filtered = xs[0:0]
for i := int(0); i < len(xs); i++ {
        x := xs[i]
        if toRemove+1 != x {
                filtered = append(filtered, x)
        }
}
return (filtered)
filtered := []int(nil)
filtered = xs[:0]
for _, x := range xs {
       if x != 11 {
               filtered = append(filtered, x)
       }
}
return filtered

Usage examples

Potential workflow for code searching:

1. Code search

  • Normalize the entire Go stdlib
  • Then normalize your function
  • Run grepfunc against normalized stdlib
  • If function you implemented has implementation under the stdlib, you'll probably find it

Basically, instead of stdlib you can use any kind of Go corpus.

Another code search related tasks that can be simplified by astnorm are code similarity evaluation and code duplication detection of any kind.

2. Static analysis

Suppose we have badcode.go file:

package badpkg

func NotEqual(x1, x2 int) bool {
	return (x1) != x1
}

There is an obvious mistake there, x1 used twice, but because of extra parenthesis, linters may not detect this issue:

$ staticcheck badcode.go
# No output

Let's normalize the input first and then run staticcheck:

go-normalize badcode.go > normalized_badcode.go
staticcheck normalized_badcode.go
normalized_badcode.go:4:9: identical expressions on the left and right side of the '!=' operator (SA4000)

And we get the warning we deserve! No changes into staticcheck or any other linter are required.

See also: demo script.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].