Giter VIP home page Giter VIP logo

rubysonar's Introduction

RubySonar - an advanced semantic indexer for Ruby

RubySonar is a semantic indexer for Ruby, which does interprocedural analysis to infer types. It is one of the underlying technologies that powers the code search site Sourcegraph.

RubySonar is modeled after PySonar2, which does a similar analysis for Python and has been in use by Sourcegraph and Google. To understand its technical properties, please refer to my blog posts:

Demo

How to build

mvn package

System Requirements

  • irb

RubySonar uses the irb interpreter to parse Ruby code, so please make sure you have it installed and pointed to by the PATH environment variable.

How to use

RubySonar is mainly designed as a library for IDEs and other developer tools, so its interface may not be as appealing as an end-user tool, but for your understanding of the library's capabilities, a reasonably nice demo program has been built.

You can build a simple "code-browser" of your ruby code with the following command line:

java -jar target/rubysonar-0.1-SNAPSHOT.jar /path/to/project ./html

This will take a few minutes. You should find some interactive HTML files inside the html directory after this process.

License (BSD Style)

RubySonar - an advanced semantic indexer for Ruby

Copyright (c) 2013-2019 Yin Wang

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

  3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

rubysonar's People

Contributors

chenyukang avatar dependabot[bot] avatar handsomecheung avatar jprovim avatar kenpusney avatar passy avatar sqs avatar yinwang0 avatar yukangchen avatar zfy0701 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rubysonar's Issues

A state safety check for TypeStack

Because you make "typeStack" a static field in Type, I propose a check to fail at mis-operations and (future?) concurrency problem (ah, my own analyzer program is multi-threaded). And so that the method parameters can be taken use of.

We can write TypeStack#pop(...) as below:

    public void pop(Object first, Object second) {
        Pair removed = stack.remove(stack.size() - 1);
        if (removed.first != first || removed.second != second) {
            throw new IllegalStateException("TypeStack is not in its expected state!");
        }
    }

JSONDump usage info is inconsistent with new arg layout

The JSONDump help message says:

$ java -cp target/rubysonar-0.1-SNAPSHOT.jar org.yinwang.rubysonar.JSONDump
Usage: java org.yinwang.rubysonar.dump <source-path> <include-paths> <out-root> [verbose]
  <source-path> is path to source unit (package directory or module file) that will be graphed
  <include-paths> are colon-separated paths to included libs
  <out-root> is the prefix of the output files.  There are 3 output files: <out-root>-doc, <out-root>-sym, <out-root>-ref
  [verbose] if set, then verbose logging is used (optional)

but the code for parsing args expects them in a different order:

        if (args.length >= 3) {
            projectDir = args[0];
            outroot = args[1];
            inclpaths = Arrays.asList(args[2].split(":"));
            srcpath.addAll(Arrays.asList(args).subList(3, args.length));
        } else {
            usage();
            return;
        }

build error

localhost:rubysonar apple$ mvn package
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building rubysonar 0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ rubysonar ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 5 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ rubysonar ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 73 source files to /Users/apple/projects/rubysonar/target/classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.971s
[INFO] Finished at: Wed Feb 19 02:19:51 CST 2014
[INFO] Final Memory: 5M/81M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project rubysonar: Fatal error compiling: ??Ч??Ŀ??汾?? 1.7 -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

License description

"""
License (GNU AGPLv3)

RubySonar - a type inferencer and indexer for Python

Copyright (c) 2013-2014 Yin Wang

"""

It should be "Ruby"

Ruby attribute references

For code as follow

class A
  @f = 0
  def self.f
    @f
  end
end

a = A.new
a.f

it will create a definition for the instance variable f (qname: A::f), and one for the class method (qname: A.f)
however, the reference generated is strange:
f in line 4 referenced to A.f
a.f in last line referenced to A::f

it looks like we want the contrary result

it looks like the reason is: f in line 4 is a Name node, which should really be a attribute node.

and a.f in last line is attribute node, which should be a method call I believe.

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.