class JavaCCTask
Implements programmatic control of the JavaCC application.
Public Class Methods
new()
click to toggle source
Constructor
Calls superclass method
CLApp::new
# File lib/rakeutils/javacctask.rb, line 26 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 += "\njavacc.bat not found" raise msg else raise "javacc not found" end end @look_ahead = "" @static = "" @output_dir = "" end
Public Instance Methods
find_app()
click to toggle source
# File lib/rakeutils/javacctask.rb, line 46 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", "javacc.bat") end else app_path = `which javacc`.chomp end end
generate_from(grammar)
click to toggle source
Generate java classes based on JavaCC grammar description file.
- grammar
-
grammar description file (.jj)
# File lib/rakeutils/javacctask.rb, line 81 def generate_from(grammar) puts "Generating Java classes based on grammar file: #{grammar}" # Note: javacc help states that args can be supplied using either of # 2 forms: # -OPTION=value # -OPTION:value # # So far, I get errors (and javacc doesn't recognize) options # passed with '='. # # Use form -OPTION: instead. options = [] options << "-STATIC:#{@static}" unless @static.empty? options << "-LOOKAHEAD:#{@look_ahead}" unless @look_ahead.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 JavaCC 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/javacctask.rb, line 75 def output_dir(pathname) @output_dir = pathname end
output_file(look_ahead)
click to toggle source
Set the lookahead depth.
- look_ahead
-
string; depth of lookahead. Default = 1.
# File lib/rakeutils/javacctask.rb, line 69 def output_file(look_ahead) @look_ahead = look_ahead.to_s 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/javacctask.rb, line 59 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 end