Giter VIP home page Giter VIP logo

goblin's Introduction

Goblin

Build Status codecov.io

goblin is an executable that uses Go's ast, parser, and token modules to dump a Go expression, statement, or file to JSON. It is small, fast, self-contained, and incurs no dependencies.

Usage

goblin --file [FILENAME] dumps a given file. goblin --expr EXPR dumps an expression. goblin --stmt STMT dumps a statement—due to a quirk in the Go AST API, this statement will be surrounded by a dummy function.

Format

Every node is a JSON object containing at least two guaranteed keys:

  • kind (string): this corresponds to the data type of the given node. Expressions (Prim and Expr) are "expression", statements (Statement and Simp) are "statement", binary and unary expressions are "unary" and "binary" respectively.
  • type (string): this corresponds to the data constructor associated with the node. Casts have kind "expression"" and type "cast". Floats have kind "literal" and type "FLOAT". Pointer types have kind "type" and type "pointer".

I apologize for the semantic overlap associated with the vagueness of the words "kind" and "type". Suggestions as to better nomenclature are welcomed.

FAQ's

Why not use the ast.Visitor interface instead of recursing manually into every node? Because Visitor is inherently side-effectual: it declares no return type, so it is not possible to use it to express an algebra (which is all this program really is).

Licensing

goblin is open-source software © Reconfigure.io, released to the public under the terms of the Apache 2.0 license. A copy can be found under the LICENSE file in the project root.

Contributing

Pull requests are enthusiastically accepted!

By participating in this project you agree to follow the Contributor Code of Conduct.

TODO

  • Use JSON Schema to ensure well-formedness of the AST.
  • Pull in github.com/stretchr/testify for assertions and glog for logging.

Known Issues

  • The built-in make and new functions can be shadowed. Since goblin expects make and new to take types as arguments, it will reject a shadowing as a syntax error. The chances of this happening in real code are pretty low, as shadowing built-in functions is discouraged in real-world code.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.