Class: OrElement

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

#==, #name, #to_src

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

#initialize(*args) ⇒ OrElement

Returns a new instance of OrElement.

Raises:

  • (ArgumentError)


277
278
279
280
# File 'lib/rpdf2txt-rockit/grammar.rb', line 277

def initialize(*args)
  super(*args)
  raise ArgumentError, "At least two sub-elements needed" unless @sub_elements.length > 1
end

Instance Method Details

#inspectObject



296
297
298
# File 'lib/rpdf2txt-rockit/grammar.rb', line 296

def inspect
  inspect_sub_elements(" | ")
end

#normalize(productions) ⇒ Object

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

is normalized to

NT -> a b se1 c d

|  a b ... c d
|  a b sen c d


289
290
291
292
293
294
# File 'lib/rpdf2txt-rockit/grammar.rb', line 289

def normalize(productions)
  normalized_productions = @sub_elements.map do |subelement|
    clone_and_substitute_productions(productions, [subelement])
  end
  [normalized_productions.flatten, []]
end