sorcerer 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -12,7 +12,7 @@ end
12
12
 
13
13
  PROJ = 'sorcerer'
14
14
  RUBY = 'ruby19'
15
- PKG_VERSION = '0.0.2'
15
+ PKG_VERSION = '0.0.3'
16
16
 
17
17
  PKG_FILES = FileList[
18
18
  'README.textile',
@@ -25,7 +25,7 @@ PKG_FILES = FileList[
25
25
 
26
26
  BASE_RDOC_OPTIONS = [
27
27
  '--line-numbers', '--inline-source',
28
- '--main' , 'README.rdoc',
28
+ '--main' , 'README.textile',
29
29
  '--title', 'Rake -- Ruby Make'
30
30
  ]
31
31
 
@@ -1,8 +1,13 @@
1
1
  module Sorcerer
2
2
  # Generate the source code for teh given Ripper S-Expression.
3
- def Sorcerer.source(sexp, debug=false)
3
+ def self.source(sexp, debug=false)
4
4
  Sorcerer::Resource.new(sexp, debug).source
5
5
  end
6
+
7
+ # Generate a list of interesting subexpressions for sexp.
8
+ def self.subexpressions(sexp)
9
+ Sorcerer::Subexpression.new(sexp)
10
+ end
6
11
  end
7
12
 
8
13
  require 'sorcerer/resource'
@@ -33,15 +33,15 @@ module Sorcerer
33
33
  def tagged_sexp(sexp)
34
34
  case sexp.first
35
35
  when :var_ref, :binary, :call, :array, :hash, :unary
36
- list_sexp(sexp)
37
36
  @result << sexp
37
+ list_sexp(sexp)
38
38
  when :aref
39
- recur(sexp[2])
40
39
  @result << sexp
40
+ recur(sexp[2])
41
41
  when :method_add_arg
42
- list_sexp(sexp[2])
43
- recur(sexp[1][1])
44
42
  @result << sexp
43
+ recur(sexp[1][1])
44
+ list_sexp(sexp[2])
45
45
  else
46
46
  list_sexp(sexp)
47
47
  end
@@ -9,7 +9,7 @@ class SubexpressionTest < Test::Unit::TestCase
9
9
  if debug
10
10
  pp sexp
11
11
  end
12
- sub = Sorcerer::Subexpression.new(sexp)
12
+ sub = Sorcerer.subexpressions(sexp)
13
13
  assert_equal subexpressions, sub.subexpressions
14
14
  end
15
15
 
@@ -20,55 +20,59 @@ class SubexpressionTest < Test::Unit::TestCase
20
20
 
21
21
  def test_unary_expressions
22
22
  assert_subexpressions "-(a+b)", [
23
- "a", "b", "a + b", "-(a + b)"
23
+ "-(a + b)", "a + b", "a", "b",
24
24
  ]
25
25
  end
26
26
 
27
27
  def test_binary_expressions
28
- assert_subexpressions "a + b", ["a", "b", "a + b"]
28
+ assert_subexpressions "a + b", ["a + b", "a", "b"]
29
29
  assert_subexpressions("a + b + c",
30
- ["a", "b", "a + b", "c", "a + b + c"])
30
+ ["a + b + c", "a + b", "a", "b", "c", ])
31
31
  end
32
32
 
33
33
  def test_method_calls_without_args
34
- assert_subexpressions "o.f", ["o", "o.f"]
34
+ assert_subexpressions "o.f", ["o.f", "o"]
35
35
  assert_subexpressions "f()", ["f()"]
36
36
  end
37
37
 
38
38
  def test_method_calls_with_args
39
- assert_subexpressions "o.f", ["o", "o.f"]
39
+ assert_subexpressions "o.f()", ["o.f()", "o"]
40
40
  assert_subexpressions "o.f(a, b)", [
41
- "a", "b", "o", "o.f(a, b)"
41
+ "o.f(a, b)", "o", "a", "b"
42
42
  ]
43
43
  assert_subexpressions "f(a, b)", [
44
- "a", "b", "f(a, b)"
44
+ "f(a, b)", "a", "b"
45
45
  ]
46
46
  end
47
47
 
48
48
  def test_array_reference
49
- assert_subexpressions "a[i]", ["i", "a[i]"]
49
+ assert_subexpressions "a[i]", ["a[i]", "i"]
50
50
  end
51
51
 
52
52
  def test_array_literal
53
53
  assert_subexpressions "[a, b, c]", [
54
- "a", "b", "c", "[a, b, c]"
54
+ "[a, b, c]", "a", "b", "c"
55
55
  ]
56
56
  end
57
57
 
58
58
  def test_hash_literal
59
59
  assert_subexpressions "{:a => aa, :b => bb}", [
60
- "aa", "bb", "{:a => aa, :b => bb}"
60
+ "{:a => aa, :b => bb}", "aa", "bb"
61
61
  ]
62
62
  end
63
63
 
64
64
  def test_pattern_matching
65
- assert_subexpressions "a =~ /r/", ["a", "a =~ /r/"]
65
+ assert_subexpressions "a =~ /r/", ["a =~ /r/", "a"]
66
66
  end
67
67
 
68
68
  def test_complex_expression
69
69
  assert_subexpressions "o.f(a+b, c*d, x.y, z(k, 2, 3))", [
70
- "a", "b", "a + b", "c", "d", "c * d", "x", "x.y", "k", "z(k, 2, 3)",
71
- "o", "o.f(a + b, c * d, x.y, z(k, 2, 3))"
70
+ "o.f(a + b, c * d, x.y, z(k, 2, 3))",
71
+ "o",
72
+ "a + b", "a", "b",
73
+ "c * d", "c", "d",
74
+ "x.y", "x",
75
+ "z(k, 2, 3)", "k",
72
76
  ]
73
77
  end
74
78
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sorcerer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jim Weirich
@@ -39,7 +39,7 @@ rdoc_options:
39
39
  - --line-numbers
40
40
  - --inline-source
41
41
  - --main
42
- - README.rdoc
42
+ - README.textile
43
43
  - --title
44
44
  - Rake -- Ruby Make
45
45
  require_paths: