Class: MaybeElement

Inherits:
OperatorElement show all
Defined in:
lib/rpdf2txt-rockit/grammar.rb

Instance Attribute Summary

Attributes inherited from OperatorElement

#sub_elements

Attributes inherited from Element

#sub_elements, #tree_specification

Instance Method Summary collapse

Methods inherited from OperatorElement

#==, #initialize, #name, #to_src

Methods inherited from Element

#initialize

Methods included from SourceCodeDumpable

as_code, as_method_named, as_module_method_named, #create_new, indent_lines, name_hash, #new_of_my_type, #parameter_named, #to_compact_src, #to_src_in_module, #type_to_src

Constructor Details

This class inherits a constructor from OperatorElement

Instance Method Details

#inspectObject



189
190
191
# File 'lib/rpdf2txt-rockit/grammar.rb', line 189

def inspect
  "#{inspect_sub_elements}?"
end

#normalize(productions) ⇒ Object

NT -> a b (se1 … sen)? c d

is normalized to

NT -> a b se1 … sen c d

|  a b c d


199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# File 'lib/rpdf2txt-rockit/grammar.rb', line 199

def normalize(productions)
  p1 = clone_and_substitute_productions(productions, 
			  @sub_elements) do |prod, elemindex|
    endindex = elemindex+@sub_elements.length-1
    prod.tree_builder = 
	GroupingSyntaxTreeBuilder.new(elemindex, 
		      endindex,
		      prod.tree_builder)
    prod
  end
  p2 = clone_and_substitute_productions(productions, []) do |p,ei|
    p.tree_builder.inactivate_child(ei)
    p
  end 
  [p1 + p2, []]
end