public
Description: Convert Php to Ruby (Will soon die and be reborn as something different..)
Homepage: http://ionize.farleyknight.com
Clone URL: git://github.com/farleyknight/ionize.git
Click here to lend your support to: ionize and make a donation at www.pledgie.com !
ionize / Rakefile
100644 142 lines (116 sloc) 3.118 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# require 'config/requirements'
# require 'config/hoe' # setup Hoe + all gem configuration
 
# Process.setrlimit(Process::RLIMIT_AS, (1024 ** 2) * 100)
 
 
Dir['tasks/**/*.rake'].each { |rake| load rake }
 
require 'lib/ionize'
require 'spec/rake/spectask'
 
module Joomla
  def files
    files = Dir["spec/fixtures/joomla/*.php"] + Dir["spec/fixtures/joomla/**/*.php"]
    # The LICENSE and CHANGELONG is not an actual php file
    files = files.reject {|f| f =~ /LICENSE/ or f =~ /CHANGELOG/ }
    files
  end
end
 
namespace :joomla do
  include Joomla
 
  task :init do
    Ionize::Php::CharacterLimit = 999999999999
  end
  
  namespace :download do
    include Joomla
 
    desc "Download Joomla 1.0"
    task "1_0" do
      download("1_0")
    end
 
    desc "Download Joomla 1.5"
    task "1_5" do
      download("1_5")
    end
  end
 
  task :tokenize => :init do
    files.each do |f|
      puts "Tokenizing #{f}"
      Ionize::Php.to_tokens(File.read(f))
      GC.start
    end
  end
 
  task :parse => :init do
    unparsed = []
    files.each do |f|
      puts "Parsing #{f}"
      begin
        Ionize::Php.to_ast(File.read(f))
      rescue => error
        puts "Couldn't parse #{f}"
        unparsed << f
      end
      GC.start
    end
    puts "Couldn't parse #{unparsed.length} files"
  end
 
  task :sexpize => :init do
    files.each do |f|
      puts "Sexpizing #{f}"
      Ionize::Php.to_sexp(File.read(f))
      GC.start
    end
  end
 
end
 
namespace :treetop do
  task :init do
    require 'treetop'
    require 'etc/pre_parser'
    Treetop.load "etc/php"
  end
 
  namespace :joomla do
    include Joomla
 
    desc "Parse Joomla with Treetop Php parser"
    task :parse => "treetop:init" do
      parser = PhpParser.new
      unparsed = []
      
      files.each do |file|
        puts "Parsing #{file}"
        text = PreParser.new(File.read(file)).run
        result = parser.parse(text)
        if result.nil?
          puts "Couldn't parse #{file}"
          unparsed << file
        end
      end
      
      puts "Couldn't parse #{unparsed.length} files"
      puts unparsed.inspect
    end
  end
 
  desc "Parse tests with Treetop Php parser"
  task :parse => :init do
    require 'etc/pre_parser'
    parser = PhpParser.new
    unparsed = []
 
    files = Dir["spec/fixtures/*.php"]
    files.each do |file|
      puts "Parsing #{file}"
      text = PreParser.new(File.read(file)).run
      result = parser.parse(text)
      if result.nil?
        puts "Couldn't parse #{file}"
        unparsed << file
      end
    end
    
    if unparsed.empty?
      puts "Parsed all the files"
    else
      puts "Couldn't parse #{unparsed.length} files"
    end
  end
end
 
desc "Run parser specs"
Spec::Rake::SpecTask.new do |t|
  t.name = "spec_parser"
  t.spec_files = "spec/php_parser_spec.rb"
end
 
desc "Run translator specs"
Spec::Rake::SpecTask.new do |t|
  t.name = "spec_translator"
  t.spec_files = "spec/php_translator_spec.rb"
end