ruby_scribe 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -2,15 +2,15 @@
2
2
 
3
3
  == Introduction
4
4
 
5
- Seattle RB's ruby_parser is a great tool for parsing ruby code into syntax trees. Ruby Scribe is the reverse of this - a tool for taking an S-expression in Ruby and emitting clean code. It does this by providing a series of rules that intelligently formats code much as a real developer would.
5
+ Seattle RB's ruby_parser is a great tool for parsing ruby code into syntax trees. Ruby Scribe is the reverse of this - a tool for taking an S-expression in Ruby and emitting clean code.
6
+
7
+ This project is similar to the ruby2ruby project (also by seattlerb) in that it is a pretty-printer for Ruby s-expressions, but ruby_scribe goes beyond emitting "runnable" Ruby code and attempts to intelligently format code much as a real developer would, through a series of configurable options. Running this against the Rails codebase (as in, parsing the file and emitting it back out) shows very few differences.
6
8
 
7
9
  == Example
8
10
 
9
11
  Imagine this crappily-formatted Ruby code:
10
12
 
11
13
  module RubyScribe
12
-
13
-
14
14
  # My Comment
15
15
  class Sample < Base;
16
16
  def method; do_something_here; end
@@ -23,31 +23,15 @@ Imagine this crappily-formatted Ruby code:
23
23
  end
24
24
  end
25
25
 
26
- Here is the syntax tree for the above:
27
-
28
- s(:module,
29
- :RubyScribe,
30
- s(:scope,
31
- s(:class,
32
- :Sample,
33
- s(:const, :Base),
34
- s(:scope,
35
- s(:block,
36
- s(:defn,
37
- :method,
38
- s(:args),
39
- s(:scope, s(:block, s(:call, nil, :do_something_here, s(:arglist))))),
40
- s(:if,
41
- s(:call, nil, :new_record?, s(:arglist)),
42
- s(:call, nil, :puts, s(:arglist, s(:str, "Yes"))),
43
- s(:call, nil, :puts, s(:arglist, s(:str, "No")))))))))
44
-
45
- Parse that with RubyParser, then emit it with RubyScribe:
26
+ Parse that with RubyParser:
46
27
 
47
28
  sexp = RubyParser.new.parse(File.read("bad_code.rb"))
29
+
30
+ Then emit it with Ruby Scribe:
31
+
48
32
  RubyScribe::Emitter.new.emit(sexp)
49
33
 
50
- And out pops this:
34
+ And out pops this, nice and clean:
51
35
 
52
36
  module RubyScribe
53
37
  # My Comment
@@ -65,15 +49,6 @@ And out pops this:
65
49
  end
66
50
 
67
51
 
68
- == Applications
69
-
70
- The combination of these two tools allows some other interesting tools to be written. One of example tool (and indeed the entire reason I started this project) is my rspecify tool, which can take a test directory with code written using Test::Unit and, via a Ruby Scribe Preprocessor, convert it into RSpec, automating 99% of what a human developer would normally have to do.
71
-
72
- Future projects using these two gems could be:
73
- * Automated refactoring tools
74
- * Tools that take a project and try to apply a set of "coding standards"
75
- * Tools that produce metrics on how much your code differs from the project's "coding standards" implementation.
76
-
77
52
  == Usage
78
53
 
79
54
  The entire project simply takes an incoming Sexp object (from the ruby_parser project) and emits a single string. To do this just use an Emitter:
@@ -86,17 +61,13 @@ The +Emitter+ class is nothing but a bunch of recursion. The main emit method i
86
61
 
87
62
  To extend or implement your own Emitter, just subclass +RubyScribe::Emitter+ and override the necessary methods.
88
63
 
89
- == Preprocess Implementation
90
-
91
- This feature is not developed yet, but is intended on presenting a standard recursion-based class for implementing transformations of S-expressions.
92
-
93
64
  == Known Issues
94
65
 
95
66
  * Since there are still some holes in the implementation, any s-expression type that is unknown will cause the following to be emitted: "## RubyScribe-UNKNOWN: :type ##". Once stable any unknown type will instead throw an exception.
96
- * Anything involving order of operations currently much surround the expression in ( ). Will probably expand later to omit this when order of operations is implied, but this requires a context stack. There may actually be other issues related to order of operations. To do this properly requires maintaining context of operations and, starting with the case for parenthesis, remove parentheses when the emitter determines that the order of operations is implied by Ruby syntax rules. Right now the emitter more or less assumes order of operations is implied and does not use parantheses, except in the cases of || and && in which case it does.
97
- * Some of the more obscure types are not implemented.
67
+ * Anything involving order of operations currently much surround the expression in ( ). Will probably expand later to omit this when order of operations is implied, but this requires a context stack. There may actually be other issues related to order of operations. To do this properly requires maintaining context of operations and, starting with the case for parenthesis, remove parentheses when the emitter determines that the order of operations is implied by Ruby syntax rules. Right now the emitter more or less assumes order of operations is implied and does not use parentheses, except in the cases of || and && in which case it does.
98
68
  * Only comments on methods, class, and module declarations are retained. This is actually a limitation of ruby_parser as for whatever reason
99
69
  in-line comments cannot be parsed correctly.
70
+ * Markers such as __FILE__ and __LINE__ are not parsed as you would expect from ruby_parser. A monkey patch to ruby_parser is required for this to work.
100
71
 
101
72
  == Future Features
102
73
 
@@ -1,3 +1,3 @@
1
1
  module RubyScribe
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/ruby_scribe.rb CHANGED
@@ -6,8 +6,6 @@ require "ruby_scribe/sexp_helpers"
6
6
  require "ruby_scribe/emitter_helpers"
7
7
  require "ruby_scribe/emitter_config"
8
8
  require "ruby_scribe/emitter"
9
- require "ruby_scribe/transformer_helpers"
10
- require "ruby_scribe/transformer"
11
9
  require "ruby_scribe/ext/sexp"
12
10
 
13
11
  Dir[File.join(File.dirname(__FILE__), "ruby_scribe/transformers/**/*.rb")].each do |file|
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_scribe
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ben Hughes