| Class | OOParser::ParseState::VarSet |
| In: |
lib/ooparser/parsestate.rb
(CVS)
|
| Parent: | Object |
Variable set for matches against productions. The return value for each item in the production (if it matches) is placed in the varset with an index and one or more optional names. The varset is the argument to a matching production’s action after it matches completely, or the return value from a production with no action.
The index operator can be used to fetch items either by numerical index or by a symbolic name derived from the appearance of the item in the associated production. For example, given the following productions:
"[ <sectionname> ] : <sectionvalue>+"
the following keys would be valid (assuming a match had been made):
| 1: | ’[‘ |
| 2: | (whatever the ‘sectionname’ rule returned) |
| 3: | ’]’ |
| 4: | ’:’ |
| 5: | (the return of the first match of the ‘sectionvalue’ rule) |
| 6: | (the return of the second match of the ‘sectionvalue’ rule) |
| 7: | etc., etc. |
| sectionname: | (whatever the ‘sectionname’ rule returned) |
| sectionvalues: | (all of the returns from the ‘sectionvalue’ rule matches) |
| sectionvalue_1: | (the return of the first match of the ‘sectionvalue’ rule) |
| first_sectionvalue: | (the return of the first match of the ‘sectionvalue’ rule) |
| sectionvalue_2: | (the return of the second match of the ‘sectionvalue’ rule) |
| second_sectionvalue: | (the return of the second match of the ‘sectionvalue’ rule) |
| indexed | [R] | The match values in raw match order. |
| named | [R] | The match value by name, keyed with Symbols |
Create a new varset
# File lib/ooparser/parsestate.rb, line 81 def initialize @indexed = [nil] @named = {} end
Element reference — returns the element at index, which can be either a Fixnum or a name as either a Symbol or a String.
# File lib/ooparser/parsestate.rb, line 100 def []( index ) case index when 0 return @indexed[ 1 .. @indexed.length - 1 ] when Numeric return @indexed[ Integer(index) ] when String, Symbol return @named[ index.to_sym ] else raise TypeError, "%s as %s index" % [index.class.name, self.class.name] end end