| Class | OOParser |
| In: |
lib/ooparser.rb
(CVS)
|
| Parent: | Object |
OOParser - an object-oriented parser class
| SVNRev | = | %q$Rev: 5 $ | SVN Revision | |
| SVNId | = | %q$Id: ooparser.rb 5 2005-09-08 07:41:12Z ged $ | SVN Id |
| log | [R] | The Logger object for this particular parser instance |
Return the logging handle for the parser class, creating a new one if necessary.
# File lib/ooparser.rb, line 101 def self::log if !defined?( @log ) || @log.nil? @log = Logger::new( $deferr ) @log.level = Logger::WARN end return @log end
Create a new ooparser object.
# File lib/ooparser.rb, line 128 def initialize @log = self.class.log.clone @rules = {} self.install_grammar end
Return a human-readable programmatic representation of the object.
# File lib/ooparser.rb, line 145 def inspect return "#<%s:0x%0x @rules=%p>" % [ self.class.name, self.object_id, @rules, ] end
Install an OOParser::Grammar in this class
# File lib/ooparser.rb, line 165 def install_grammar grammar = self.class.grammar or raise OOParser::Error, "Cannot instantiate %s: no grammar defined" % self.class.name if grammar.rules.empty? raise OOParser::Error, "Cannot instantiate %s: grammar has no rules" end # Install a singleton method on the parser object for each rule of the # grammar grammar.rules.each do |name,rule| block = rule.as_proc( self ) @rules[ name.to_sym ] = block self.log.debug "Installing rule %p: %s" % [ rule, block ] self.metaclass.send( :define_method, name.to_sym, block ) end # Alias the #parse method to the grammar's default rule self.metaclass.send( :alias_method, :parse, grammar.default_rule ) end