class ANTLR3::CompileTask::GrammarFile
Constants
- GRAMMAR_TYPES
- LANGUAGES
Attributes
group[R]
ATTRIBUTES AND ATTRIBUTE-ISH METHODS ####################
imported_grammars[R]
ATTRIBUTES AND ATTRIBUTE-ISH METHODS ####################
imports[R]
ATTRIBUTES AND ATTRIBUTE-ISH METHODS ####################
language[R]
ATTRIBUTES AND ATTRIBUTE-ISH METHODS ####################
name[R]
ATTRIBUTES AND ATTRIBUTE-ISH METHODS ####################
path[R]
ATTRIBUTES AND ATTRIBUTE-ISH METHODS ####################
source[R]
ATTRIBUTES AND ATTRIBUTE-ISH METHODS ####################
token_vocab[R]
ATTRIBUTES AND ATTRIBUTE-ISH METHODS ####################
type[R]
ATTRIBUTES AND ATTRIBUTE-ISH METHODS ####################
Public Class Methods
new( group, path, options = {} ) { |self| ... }
click to toggle source
CONSTRUCTOR #############################################
# File lib/antlr3/task.rb, line 259 def initialize( group, path, options = {} ) @group = group @path = path.to_s @imports = [] @language = 'Java' @token_vocab = nil @tasks_defined = false @extra_dependencies = [] if extra = options[ :extra_dependencies ] extra = [ extra ].flatten @extra_dependencies.concat( extra ) end study yield( self ) if block_given? fetch_imports end
Public Instance Methods
all_imported_files()
click to toggle source
# File lib/antlr3/task.rb, line 356 def all_imported_files imported_files = [] for grammar in @imported_grammars imported_files.push( grammar.path, *grammar.all_imported_files ) end return imported_files end
clean()
click to toggle source
# File lib/antlr3/task.rb, line 364 def clean deleted = [] for target in target_files if test( ?f, target ) rm( target ) deleted << target end end for grammar in @imported_grammars deleted.concat( grammar.clean ) end return deleted end
define_tasks( shared_depends )
click to toggle source
# File lib/antlr3/task.rb, line 380 def define_tasks( shared_depends ) unless @tasks_defined depends = [ @path, *all_imported_files ] for f in depends file( f ) end depends = shared_depends + depends target_files.each do | target | file( target => ( depends - [ target ] ) ) do # prevents recursive .tokens file dependencies @group.compile( self ) end end @tasks_defined = true end end
delegate_files( delegate_suffix )
click to toggle source
# File lib/antlr3/task.rb, line 326 def delegate_files( delegate_suffix ) file_names( "#{ name }_#{ delegate_suffix }" ) end
file_names( base )
click to toggle source
# File lib/antlr3/task.rb, line 312 def file_names( base ) LANGUAGES.fetch( @language ).map do | ext | File.join( output_directory, base + ext ) end end
lexer_files()
click to toggle source
# File lib/antlr3/task.rb, line 292 def lexer_files if lexer? then base = @name elsif combined? then base = @name + 'Lexer' else return( [] ) end return( file_names( base ) ) end
parser_files()
click to toggle source
# File lib/antlr3/task.rb, line 300 def parser_files if parser? then base = @name elsif combined? then base = @name + 'Parser' else return( [] ) end return( file_names( base ) ) end
target_files( all = true )
click to toggle source
# File lib/antlr3/task.rb, line 334 def target_files( all = true ) targets = [ tokens_file ] for target_type in %w( lexer parser tree_parser ) for file in self.send( :"#{ target_type }_files" ) targets << file end end if all for grammar in @imported_grammars targets.concat( grammar.target_files ) end end return targets end
tokens_file()
click to toggle source
# File lib/antlr3/task.rb, line 330 def tokens_file File.join( output_directory, name + '.tokens' ) end
tree_parser_files()
click to toggle source
# File lib/antlr3/task.rb, line 308 def tree_parser_files return( tree? ? file_names( @name ) : [] ) end
update()
click to toggle source
# File lib/antlr3/task.rb, line 352 def update touch( @path ) end
Private Instance Methods
fetch_imports()
click to toggle source
# File lib/antlr3/task.rb, line 400 def fetch_imports @imported_grammars = @imports.map do | imp | file = group.locate( "#{ imp }.g" ) or raise( Util.tidy( <<-END ) ) | #{ @path }: unable to locate imported grammar file #{ imp }.g | search directories ( @load_path ): | - #{ load_path.join( "\n - " ) } END Imported.new( self, file ) end end
study()
click to toggle source
# File lib/antlr3/task.rb, line 411 def study @source = File.read( @path ) @source =~ /^\s*(lexer|parser|tree)?\s*grammar\s*(\S+)\s*;/ or raise Grammar::FormatError[ @source, @path ] @name = $2 @type = $1 || 'combined' if @source =~ /^\s*options\s*\{(.*?)\}/m option_block = $1 if option_block =~ /\s*language\s*=\s*(\S+)\s*;/ @language = $1 LANGUAGES.has_key?( @language ) or raise( Grammar::FormatError, "Unknown ANTLR target language: %p" % @language ) end option_block =~ /\s*tokenVocab\s*=\s*(\S+)\s*;/ and @token_vocab = $1 end @source.scan( /^\s*import\s+(\w+\s*(?:,\s*\w+\s*)*);/ ) do list = $1.strip @imports.concat( list.split( /\s*,\s*/ ) ) end end