Class: LL::Branch

Inherits:
Object
  • Object
show all
Defined in:
lib/ll/branch.rb

Overview

The Branch class contains information of a single rule branch such as the steps and the associated callback code.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(steps, source_line, ruby_code = nil) ⇒ Branch

Returns a new instance of Branch.

Parameters:

  • (defaults to: nil)


14
15
16
17
18
# File 'lib/ll/branch.rb', line 14

def initialize(steps, source_line, ruby_code = nil)
  @steps       = steps
  @source_line = source_line
  @ruby_code   = ruby_code
end

Instance Attribute Details

#ruby_codeObject (readonly)

Returns the value of attribute ruby_code.



7
8
9
# File 'lib/ll/branch.rb', line 7

def ruby_code
  @ruby_code
end

#source_lineObject (readonly)

Returns the value of attribute source_line.



7
8
9
# File 'lib/ll/branch.rb', line 7

def source_line
  @source_line
end

#stepsObject (readonly)

Returns the value of attribute steps.



7
8
9
# File 'lib/ll/branch.rb', line 7

def steps
  @steps
end

Instance Method Details

#first_setArray<LL::Terminal>

Returns the FIRST() set of this branch.

Returns:



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/ll/branch.rb', line 25

def first_set
  first = steps[0]

  if first.is_a?(Rule)
    return first.first_set
  elsif first
    return [first]
  else
    return []
  end
end

#follow_setArray<LL::Terminal>

Returns the FOLLOW() set of this branch.

Returns:



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/ll/branch.rb', line 42

def follow_set
  follow = steps[1]

  if follow.is_a?(Rule)
    set = follow.first_set
  elsif follow
    set = [follow]
  else
    set = []
  end

  return set
end

#inspectString

Returns:



59
60
61
# File 'lib/ll/branch.rb', line 59

def inspect
  return "Branch(steps: #{steps.inspect}, ruby_code: #{ruby_code.inspect})"
end