Class: Production
- Includes:
- Indexable, SourceCodeDumpable
- Defined in:
- lib/rpdf2txt-rockit/grammar.rb,
lib/rpdf2txt-rockit/parsetable_generation.rb
Overview
Decorate Productions
Instance Attribute Summary collapse
-
#elements ⇒ Object
Right hand side.
-
#nonterminal ⇒ Object
Left hand side.
-
#tree_builder ⇒ Object
Returns the value of attribute tree_builder.
Attributes included from Indexable
Instance Method Summary collapse
- #==(other) ⇒ Object
- #clone_and_substitute(element, substitute) ⇒ Object
- #create_tree(childrenValues) ⇒ Object
-
#initialize(nonterminal, elements, treeBuilder = nil) ⇒ Production
constructor
A new instance of Production.
- #inspect ⇒ Object
- #length ⇒ Object
-
#normalize ⇒ Object
def clone Production.new(@nonterminal.clone, @elements.clone, @tree_builder.clone) end.
- #to_src(name = nil, nameHash = {}) ⇒ Object
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(nonterminal, elements, treeBuilder = nil) ⇒ Production
Returns a new instance of Production.
358 359 360 361 362 363 |
# File 'lib/rpdf2txt-rockit/grammar.rb', line 358 def initialize(nonterminal, elements, treeBuilder = nil) nonterminal = NonTerminal.new(nonterminal) if nonterminal.class == String @nonterminal = make_element(nonterminal) @elements = make_elements(elements) init_tree_builder(treeBuilder) end |
Instance Attribute Details
#elements ⇒ Object
Right hand side
354 355 356 |
# File 'lib/rpdf2txt-rockit/grammar.rb', line 354 def elements @elements end |
#nonterminal ⇒ Object
Left hand side
355 356 357 |
# File 'lib/rpdf2txt-rockit/grammar.rb', line 355 def nonterminal @nonterminal end |
#tree_builder ⇒ Object
Returns the value of attribute tree_builder.
356 357 358 |
# File 'lib/rpdf2txt-rockit/grammar.rb', line 356 def tree_builder @tree_builder end |
Instance Method Details
#==(other) ⇒ Object
386 387 388 389 390 391 392 393 |
# File 'lib/rpdf2txt-rockit/grammar.rb', line 386 def ==(other) #Profiler.__enter__("Production#==".intern, other) res = other.class == self.class and nonterminal == other.nonterminal and elements == other.elements and tree_builder == other.tree_builder #Profiler.__leave__("Production#==".intern, res) end |
#clone_and_substitute(element, substitute) ⇒ Object
395 396 397 398 399 400 401 402 403 404 405 |
# File 'lib/rpdf2txt-rockit/grammar.rb', line 395 def clone_and_substitute(element, substitute) index = elements.index element substitute = [substitute] unless substitute.kind_of?(Array) if index Production.new(nonterminal, elements[0...index] + substitute + elements[(index+1)..-1], tree_builder.copy) else self end end |
#create_tree(childrenValues) ⇒ Object
412 413 414 |
# File 'lib/rpdf2txt-rockit/grammar.rb', line 412 def create_tree(childrenValues) tree_builder.create_tree(childrenValues) end |
#inspect ⇒ Object
407 408 409 410 |
# File 'lib/rpdf2txt-rockit/grammar.rb', line 407 def inspect elements_inspect = @elements.map {|e| e.inspect}.join(" ") "#{nonterminal.inspect} -> #{elements_inspect}" end |
#length ⇒ Object
382 383 384 |
# File 'lib/rpdf2txt-rockit/grammar.rb', line 382 def length elements.length end |
#normalize ⇒ Object
def clone
Production.new(@nonterminal.clone, @elements.clone, @tree_builder.clone)
end
371 372 373 374 375 376 377 378 379 380 |
# File 'lib/rpdf2txt-rockit/grammar.rb', line 371 def normalize maybe_normalize, extra_productions = [self], [] @elements.each do |element| if element.kind_of?(Element) maybe_normalize, new_extra = element.normalize(maybe_normalize) extra_productions += new_extra end end (maybe_normalize + extra_productions).equality_uniq end |
#to_src(name = nil, nameHash = {}) ⇒ Object
416 417 418 419 420 |
# File 'lib/rpdf2txt-rockit/grammar.rb', line 416 def to_src(name = nil, nameHash = {}) assign_to(name, new_of_my_type(nonterm_to_symbol(nonterminal), as_code(elements_to_src(nameHash)), tree_builder)) end |