Module: RDocF95::ParserFactory
- Included in:
- C_Parser, Fortran95parser, RubyParser
- Defined in:
- lib/rdoc-f95/parsers/parserfactory.rb
Defined Under Namespace
Classes: Parsers
Constant Summary collapse
- @@parsers =
[]
Class Method Summary collapse
-
.alias_extension(old_ext, new_ext) ⇒ Object
Alias an extension to another extension.
-
.can_parse(file_name) ⇒ Object
Return a parser that can handle a particular extension.
-
.parser_for(top_level, file_name, body, options, stats) ⇒ Object
Find the correct parser for a particular file name.
Instance Method Summary collapse
-
#parse_files_matching(regexp) ⇒ Object
Record the fact that a particular class parses files that match a given extension.
Class Method Details
.alias_extension(old_ext, new_ext) ⇒ Object
Alias an extension to another extension. After this call, files ending “new_ext” will be parsed using the same parser as “old_ext”
70 71 72 73 74 75 |
# File 'lib/rdoc-f95/parsers/parserfactory.rb', line 70 def ParserFactory.alias_extension(old_ext, new_ext) parser = ParserFactory.can_parse("xxx.#{old_ext}") return false unless parser @@parsers.unshift Parsers.new(Regexp.new("\\.#{new_ext}$"), parser.parser) true end |
.can_parse(file_name) ⇒ Object
Return a parser that can handle a particular extension
62 63 64 |
# File 'lib/rdoc-f95/parsers/parserfactory.rb', line 62 def ParserFactory.can_parse(file_name) @@parsers.find {|p| p.regexp.match(file_name) } end |
.parser_for(top_level, file_name, body, options, stats) ⇒ Object
Find the correct parser for a particular file name. Return a SimpleParser for ones that we don’t know
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/rdoc-f95/parsers/parserfactory.rb', line 80 def ParserFactory.parser_for(top_level, file_name, body, , stats) # If no extension, look for shebang if file_name !~ /\.\w+$/ && body =~ %r{\A#!(.+)} shebang = $1 case shebang when %r{env\s+ruby}, %r{/ruby} file_name = "dummy.rb" end end parser_description = can_parse(file_name) if parser_description parser = parser_description.parser else parser = SimpleParser end parser.new(top_level, file_name, body, , stats) end |
Instance Method Details
#parse_files_matching(regexp) ⇒ Object
Record the fact that a particular class parses files that match a given extension
56 57 58 |
# File 'lib/rdoc-f95/parsers/parserfactory.rb', line 56 def parse_files_matching(regexp) @@parsers.unshift Parsers.new(regexp, self) end |