Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

ruby_parser support #4

Open
wants to merge 39 commits into from

4 participants

pete higgins Ryan Davis Andrew Grimm Dan Kubb
pete higgins
Owner

This is a first pass at getting heckle to work with ruby_parser instead of ParseTree. Most of the difficulty came from the interfaces used to interact with ParseTree vs. ruby_parser. ParseTree's ability to grab a class/method's sexp at runtime fits heckle's use case much better than the solution I came up with for ruby_parser, iterating over the files in the project directory and parsing them all. This way is also much slower.

Other things:

  • I've only done enough work to get the unit tests to pass, I haven't actually tried running heckle on anything, so bugs probably remain.
  • I had to change two unit tests to get them to pass. Lame, I know.
  • Only tested with 1.8.7-p358.
pete higgins
Owner

I wanted to add one more thing:

  • The method lookup code is incredibly naive, and will only work for un-nested classes, and can't handle multiple matching things in the directory tree (which is why I had to remove sample/lib/heckled.rb).
Ryan Davis
Owner
lib/heckle.rb
@@ -11,6 +11,25 @@ def to_class
end
end
+class Sexp
+ # REFACTOR: move to sexp.rb
+ def deep_each(&block)
+ self.each_sexp do |sexp|
+ block[sexp]
+ sexp.deep_each(&block)
+ end
+ end
+
+ # REFACTOR: move to sexp.rb
+ def each_sexp
+ self.each do |sexp|
Dan Kubb
dkubb added a note

What about:

def each_sexp(&block)
  grep(Sexp).each(&block)
end
pete higgins Owner
phiggins added a note

These methods were recently added to sexp_processor so hopefully they won't exist here much longer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
lib/heckle.rb
((57 lines not shown))
+ return pt if method_name.nil?
+
+ pt.deep_each do |node|
+ if class_method
+ return node if node[0] == :defs && node[2] == clean_name
+ else
+ return node if node[0] == :defn && node[1] == clean_name
+ end
+ end
+ end
+
+ nil
+ end
+
+ def expand_dirs_to_files *dirs
+ extensions = ['rb'] # + Flay.load_plugins
Dan Kubb
dkubb added a note

Did you mean to leave the reference to Flay.load_plugins here?

pete higgins Owner
phiggins added a note

That code was copied almost directly from Flay, so I most certainly did not. That'll have to be fixed before an actual release is done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Andrew Grimm

I have two minor commits on the branch ph_ruby_parser of my repo. Sorry this is a comment - I don't know how to do a pull request on a pull request.

Ryan Davis zenspider was assigned
Ryan Davis
Owner

@phiggins -- let's go through this Tuesday and get it reviewed and merged in.

Ryan Davis
Owner

@agrimm once we get this cleaned up and merged you should be able to do a pull req... tho we may mess up your merge in our cleanup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 20, 2012
  1. pete higgins

    WIP: some progress.

    phiggins authored
  2. pete higgins

    WIP: 2 errors, 2 failures...

    phiggins authored
Commits on Jul 1, 2012
  1. pete higgins
Commits on Jul 2, 2012
  1. pete higgins

    'Fix' another text. Sigh...

    phiggins authored
  2. pete higgins

    Cleanup.

    phiggins authored
  3. pete higgins
  4. pete higgins

    Cleanup.

    phiggins authored
  5. pete higgins

    Ghetto class method support.

    phiggins authored
  6. pete higgins

    Cleanup,

    phiggins authored
Commits on Jul 4, 2012
  1. pete higgins

    Tests pass in 1.9.

    phiggins authored
  2. pete higgins

    Merge remote-tracking branch 'upstream/master' into ruby_parser

    phiggins authored
    Conflicts:
    	test/test_heckle.rb
Commits on Jul 7, 2012
  1. pete higgins
Commits on Jul 8, 2012
  1. pete higgins

    Don't need this anymore.

    phiggins authored
  2. pete higgins
Commits on Jul 11, 2012
  1. pete higgins
  2. pete higgins

    Refactor tests.

    phiggins authored
Commits on Aug 1, 2012
  1. pete higgins

    Fix.

    phiggins authored
  2. pete higgins
  3. pete higgins

    Cleanup more tests.

    phiggins authored
Commits on Aug 6, 2012
  1. pete higgins

    "Fix" test_if_mutations.

    phiggins authored
Commits on Aug 7, 2012
  1. pete higgins

    Fix more tests.

    phiggins authored
Commits on Sep 12, 2012
  1. pete higgins

    Only run our test files.

    phiggins authored
  2. pete higgins
  3. pete higgins
  4. pete higgins
Commits on Sep 14, 2012
  1. pete higgins

    Oops, that doesn't work.

    phiggins authored
  2. pete higgins
  3. pete higgins
Commits on Sep 16, 2012
  1. pete higgins

    Things mostly work (?).

    phiggins authored
Commits on Sep 19, 2012
  1. pete higgins
Commits on Oct 3, 2012
  1. pete higgins
Commits on Jun 12, 2013
  1. pete higgins

    Restructure.

    phiggins authored
Commits on Jun 16, 2013
  1. pete higgins

    Fix a few things.

    phiggins authored
Commits on Jun 17, 2013
  1. pete higgins
  2. pete higgins
  3. pete higgins
Commits on Jun 18, 2013
  1. pete higgins

    Bump dependencies.

    phiggins authored
Commits on Jun 19, 2013
  1. pete higgins
Commits on Jun 29, 2013
  1. pete higgins
Something went wrong with that request. Please try again.