blob: b1445030e6eb9fbce72b3a46d8ef001b4b1ad562 [file] [log] [blame]
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with this
# work for additional information regarding copyright ownership. The ASF
# licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
module Buildr
# Provides ANTLR grammar generation tasks. Require explicitly using <code>require "buildr/antlr"</code>.
module ANTLR
REQUIRES = [ "org.antlr:antlr:jar:3.0", "antlr:antlr:jar:2.7.7", "org.antlr:stringtemplate:jar:3.0" ]
Java.classpath << REQUIRES
class << self
def antlr(*args)
options = Hash === args.last ? args.pop : {}
rake_check_options options, :output, :token
args = { |f| ? FileList[f + "/**/*.g"] : f }.flatten
args = ["-o", options[:output]] + args if options[:output]
if options[:token]
# antlr expects the token directory to exist when it starts
mkdir_p options[:token]
args = ["-lib", options[:token]] + args
Java.load"[Ljava.lang.String;", args).process
def antlr(*args)
if Hash === args.last
options = args.pop
in_package = options[:in_package].split(".")
token = options[:token].split(".") if options[:token]
in_package = []; token = nil
file(path_to(:target, :generated, :antlr)=>args.flatten) do |task|
args = {:output=>File.join(, in_package)}
args.merge!({:token=>File.join(, token)}) if token
ANTLR.antlr task.prerequisites, args
class Project
include ANTLR