Class: Aurum::ProductionDefinition

Inherits:
Object
  • Object
show all
Defined in:
lib/aurum/grammar.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeProductionDefinition

Returns a new instance of ProductionDefinition.



153
154
155
# File 'lib/aurum/grammar.rb', line 153

def initialize
	@__definitions, @__literals = {}, {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/aurum/grammar.rb', line 157

def method_missing name, *args, &block
	name_string = name.to_s
	symbol = case name_string
		when /^[a-z]/ then Aurum::Symbol.new name_string, false
		when '_' then nil
		when /_.+/ then Aurum::Symbol.new name_string, true
	end
	symbol.action = block if block_given?
	(args.empty? || name_string == '_') and return symbol
	symbols = args.map do |sym|
		if sym.kind_of? String
			@__literals[Pattern.from_string(sym)] = RecognizeTokenAction.new "$literal_#{sym}"
			sym = Aurum::Symbol.new("$literal_#{sym}", true)
		end 									
		sym
	end	
	@__definitions[symbol] = [].to_set unless @__definitions.has_key? symbol
	production = Aurum::Production.new symbol, symbols.compact
	production.action = symbols.last.action if symbols.last.action
	@__definitions[symbol] << production
end

Instance Attribute Details

#__definitionsObject (readonly)

Returns the value of attribute __definitions.



151
152
153
# File 'lib/aurum/grammar.rb', line 151

def __definitions
  @__definitions
end

#__literalsObject (readonly)

Returns the value of attribute __literals.



151
152
153
# File 'lib/aurum/grammar.rb', line 151

def __literals
  @__literals
end