Class OOParser::ParseState
In: lib/ooparser/parsestate.rb  (CVS)
Parent: Object

Parse state object class. An instance of this class is created by rule methods when they are passed a String with text to parse. It contains a StringScanner instance wrapped around the target text, a stack for keeping track of where in the grammar the parse is currently executing, and various other housekeeping data.

Methods

Classes and Modules

Class OOParser::ParseState::VarSet

Constants

SVNRev = %q$Rev: 4 $   SVN Revision
SVNId = %q$Id: parsestate.rb 4 2005-09-08 07:36:41Z ged $   SVN Id
DefaultSkipPattern = /\s*/   The default <@skip> pattern

Attributes

parser  [R]  The parser object which the parse is running in
scanner  [R]  The StringScanner which is wrapping the target text
skip_pattern  [RW]  The Regexp to skip before every rule
start_rule  [R]  The rule which served as the entry point to the parse

Public Class methods

Create a new ParseState object for the given parser and rule which will be used to parse the specified target text.

[Source]

# File lib/ooparser/parsestate.rb, line 139
    def initialize( parser, rule, target, skip_pattern=DefaultSkipPattern )
        @parser = parser
        @start_rule = rule
        @skip_pattern = skip_pattern
        @scanner = StringScanner::new( target )
    end

Public Instance methods

Skip any content in the target specified as skippable within the current production.

[Source]

# File lib/ooparser/parsestate.rb, line 219
    def do_skip
        @scanner.skip( @skip_pattern )
    end

Register an item match against the given item with the parse state.

[Source]

# File lib/ooparser/parsestate.rb, line 193
    def item_match( item )
        raise LocalJumpError, "no block given" unless block_given?

        parser.log.debug "Starting item match for %p" % [item]
        rval = yield( self )
        parser.log.debug "back from item match for %p:\n\t%p" %
            [item, rval]

        return rval
    end

Register a production match against the given production with the parse state.

[Source]

# File lib/ooparser/parsestate.rb, line 180
    def production_match( production )
        raise LocalJumpError, "no block given" unless block_given?
        
        parser.log.debug "Starting production match for %p" % [production]
        rval = yield( self )
        parser.log.debug "Back from production match for %p:\n\t%p" %
            [production, rval]

        return rval
    end

Register a rule match against the given rule with the parse state.

[Source]

# File lib/ooparser/parsestate.rb, line 165
    def rule_match( rule )
        raise LocalJumpError, "no block given" unless block_given?

        parser.log.debug "Starting rule match for %p" % [rule]
        rval = catch( :fail ) do
            yield( self )
        end
        parser.log.debug "Back from rule match for %p:\n\t%p" % [ rule, rval ]

        return rval
    end

Register and execute a transition to another rule (rulename) within the current parse.

[Source]

# File lib/ooparser/parsestate.rb, line 207
    def subrule_match( rulename )
        parser.log.debug "Starting subrule match for rule %s" % [rulename]
        rval = @parser.send( rulename, self )
        parser.log.debug "Back from subrule match for rule %s:\n\t%p" %
            [rulename, rval]

        return rval
    end

[Validate]