Class: OrElement
- Inherits:
-
OperatorElement
- Object
- Element
- OperatorElement
- OrElement
- Defined in:
- lib/rpdf2txt-rockit/grammar.rb
Instance Attribute Summary
Attributes inherited from OperatorElement
Attributes inherited from Element
#sub_elements, #tree_specification
Instance Method Summary collapse
-
#initialize(*args) ⇒ OrElement
constructor
A new instance of OrElement.
- #inspect ⇒ Object
-
#normalize(productions) ⇒ Object
NT -> a b (se1 | … | sen) c d.
Methods inherited from OperatorElement
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.
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
#inspect ⇒ Object
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 |