module Buildr module JavaCC JAVACC = "net.java.dev.javacc:javacc:jar:4.0" JJTREE = "net.java.dev.javacc:javacc:jar:4.0" def self.javacc(*args) options = Hash === args.last ? args.pop.clone : {} options[:verbose] ||= Rake.application.options.trace || false fu_check_options options, *Java::JAVA_OPTIONS + [:output] (options[:classpath] ||= []) << JAVACC java_args = ["javacc"] java_args << "-OUTPUT_DIRECTORY=#{options[:output]}" if options[:output] java_args += args.collect { |f| File.directory?(f) ? FileList[f + "/**/*.jj"] : f }.flatten java_args << options.reject { |k, v| !Java::JAVA_OPTIONS.include?(k) } Java.java(*java_args) end class JavaCCTask < Rake::FileTask def initialize(*args) super enhance do |task| JavaCC.javacc *(task.prerequisites + [task.options.merge(:output=>task.name)]) end end def options() @options ||= {} end def using(options) self.options.merge!(options) self end end def self.javacc_task(args) output = args.keys.first files = args.values.first.collect { |f| File.directory?(f) ? FileList[f + "/**/*.jj"] : f }.flatten JavaCCTask.define_task(output=>files) end def self.jjtree(*args) options = Hash === args.last ? args.pop.clone : {} options[:verbose] ||= Rake.application.options.trace || false fu_check_options options, *Java::JAVA_OPTIONS + [:output, :build_node_files] (options[:classpath] ||= []) << JJTREE java_args = ["jjtree"] java_args << "-OUTPUT_DIRECTORY=#{options[:output]}" if options[:output] java_args << "-BUILD_NODE_FILES=#{options[:build_node_files]}" if options.has_key?(:build_node_files) java_args += args.collect { |f| File.directory?(f) ? FileList[f + "/**/*.jjt"] : f }.flatten java_args << options.reject { |k, v| !Java::JAVA_OPTIONS.include?(k) } Java.java(*java_args) end class JJTreeTask < Rake::FileTask def initialize(*args) super enhance do |task| JavaCC.jjtree *(task.prerequisites + [task.options.merge(:output=>task.name)]) end end def options() @options ||= {} end def using(options) self.options.merge!(options) self end end def self.jjtree_task(args) output = args.keys.first files = args.values.first.collect { |f| File.directory?(f) ? FileList[f + "/**/*.jjt"] : f }.flatten JJTreeTask.define_task(output=>files) end end end