Class: ParseStack

Inherits:
Object show all
Defined in:
lib/rpdf2txt-rockit/glr_parser.rb

Defined Under Namespace

Classes: Link

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(aState, aLexer) ⇒ ParseStack

Returns a new instance of ParseStack.



285
286
287
288
# File 'lib/rpdf2txt-rockit/glr_parser.rb', line 285

def initialize(aState, aLexer)
  @state, @lexer = aState, aLexer
  @links = Array.new
end

Instance Attribute Details

#lexerObject (readonly)

Returns the value of attribute lexer.



282
283
284
# File 'lib/rpdf2txt-rockit/glr_parser.rb', line 282

def lexer
  @lexer
end

Returns the value of attribute links.



282
283
284
# File 'lib/rpdf2txt-rockit/glr_parser.rb', line 282

def links
  @links
end

#pointerObject

ywesee



283
284
285
# File 'lib/rpdf2txt-rockit/glr_parser.rb', line 283

def pointer
  @pointer
end

#stateObject (readonly)

Returns the value of attribute state.



282
283
284
# File 'lib/rpdf2txt-rockit/glr_parser.rb', line 282

def state
  @state
end

Instance Method Details



295
296
297
298
299
# File 'lib/rpdf2txt-rockit/glr_parser.rb', line 295

def add_link(aParseStack, aTree, aProduction = nil)
aParseStack.pointer = @lexer.scanner.pointer # ywesee
  @links.push(l = Link.new(aParseStack, aTree, aProduction))
  l
end

#inspectObject



349
350
351
# File 'lib/rpdf2txt-rockit/glr_parser.rb', line 349

def inspect
  "PSt(#{@state}, #{@links.inspect}, #{@lexer.inspect})"
end

Returns:

  • (Boolean)


305
306
307
# File 'lib/rpdf2txt-rockit/glr_parser.rb', line 305

def links_to_stack?(stack)
  @links.detect {|link| link.stack == stack}
end

Returns:

  • (Boolean)


301
302
303
# File 'lib/rpdf2txt-rockit/glr_parser.rb', line 301

def links_to_stack_in_state?(state)
  @links.detect {|link| link.stack.state == state}
end

#paths_of_length(length, aLink = nil) ⇒ Object



309
310
311
312
313
314
315
316
317
318
319
320
321
# File 'lib/rpdf2txt-rockit/glr_parser.rb', line 309

def paths_of_length(length, aLink = nil)
  return [] if length == 0
  paths = Array.new
  @links.each do |link|
    child_paths = link.stack.paths_of_length(length-1)
    if child_paths.length > 0
	child_paths.each {|cpath| paths.push(StackPath.new(self, [link]).add_path(cpath))}
    else
	paths.push StackPath.new(self, [link])
    end
  end
  delete_paths_without_link(paths, aLink)
end

#valid_paths_of_length_with_pruning(length, aLink = nil, &validity_checker) ⇒ Object



323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
# File 'lib/rpdf2txt-rockit/glr_parser.rb', line 323

def valid_paths_of_length_with_pruning(length, aLink = nil, 
			 &validity_checker)
  return [] if length == 0
  paths, new_links = Array.new, Array.new
  @links.each do |link|
    if validity_checker.call(link, length-1)
	if length == 1
 new_links.push(link)
 paths.push(StackPath.new(self, [link]))
	else
 child_paths = 
   link.stack.valid_paths_of_length_with_pruning(length-1, 
					&validity_checker)
 if child_paths.length > 0
   new_links.push(link)
   child_paths.each do |cpath| 
     paths.push(StackPath.new(self, [link]).add_path(cpath))
   end
 end
	end
    end
  end
  @links = new_links
  delete_paths_without_link(paths, aLink)
end