class JJTreeTask

Implements programmatic control of the JJTree application.

Public Class Methods

new() click to toggle source

Constructor

Calls superclass method CLApp::new
# File lib/rakeutils/jjtreetask.rb, line 27
def initialize()
  super( find_app )   # Call parent constructor.

  app_path = find_app
  if app_path.nil? or app_path.empty? or !File.exist?(app_path)
    if Ktutils::OS.windows?
      msg = "JAVACC_HOME environment variable is not configured correctly "
      msg += "or JavaCC is not installed."
      msg += "\njjtree.bat not found"
      raise msg
    else
      raise "jjtree not found"
    end
  end

  @static = ""
  @output_file = ""
  @output_dir = ""
end

Public Instance Methods

find_app() click to toggle source
# File lib/rakeutils/jjtreetask.rb, line 47
def find_app
  if Ktutils::OS.windows?
    app_home = ENV["JAVACC_HOME"]
    unless app_home.nil? or app_home.empty?
      app_path = File.join(app_home, "bin", "jjtree.bat")
    end
  else
    app_path = `which jjtree`.chomp
  end
end
generate_from(grammar) click to toggle source

Generate javacc grammar file based on JJTree grammar description file.

grammar

grammar description file (.jjt)

# File lib/rakeutils/jjtreetask.rb, line 82
def generate_from(grammar)
  puts "Generating JavaCC grammar from: #{grammar}"

  # Note: jjtree help states that args can be supplied using either of
  #       2 forms:
  #         -OPTION=value
  #         -OPTION:value
  #
  #       So far, I get errors (and jjtree doesn't recognize) options
  #       passed with '='.
  #
  #       Use form -OPTION: instead.
  options = []
  options << "-STATIC:#{@static}" unless @static.empty?
  options << "-OUTPUT_FILE:#{@output_file}" unless @output_file.empty?
  options << "-OUTPUT_DIRECTORY:#{@output_dir}" unless @output_dir.empty?

  cmd_line = options.join(' ') + " #{grammar}"

  begin
      execute( cmd_line, false )
  rescue Exception => e
      puts "!!! Errors occured during parsing of JJTree grammar."
      puts e.message
      exit
  end
end
output_dir(pathname) click to toggle source

Set the output directory.

pathname

string path of output directory. Default = current directory.

# File lib/rakeutils/jjtreetask.rb, line 76
def output_dir(pathname)
  @output_dir = pathname
end
output_file(filename) click to toggle source

Set the output filename.

filename

string name of output file. Default = input filename with .jj suffix.

# File lib/rakeutils/jjtreetask.rb, line 70
def output_file(filename)
  @output_file = filename
end
static(true_or_false) click to toggle source

Set the static class generation flag.

true_or_false

string value (true or false). Default = true.

# File lib/rakeutils/jjtreetask.rb, line 60
def static(true_or_false)
  if (true_or_false != 'true' && true_or_false != 'false')
    puts "JJTreeTask Error: static must be string value ('true' or 'false')"
    return
  end
  @static = true_or_false.to_s
end