Class: LL::Branch
- Inherits:
-
Object
- Object
- LL::Branch
- 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
-
#ruby_code ⇒ Object
readonly
Returns the value of attribute ruby_code.
-
#source_line ⇒ Object
readonly
Returns the value of attribute source_line.
-
#steps ⇒ Object
readonly
Returns the value of attribute steps.
Instance Method Summary collapse
-
#first_set ⇒ Array<LL::Terminal>
Returns the FIRST() set of this branch.
-
#follow_set ⇒ Array<LL::Terminal>
Returns the FOLLOW() set of this branch.
-
#initialize(steps, source_line, ruby_code = nil) ⇒ Branch
constructor
A new instance of Branch.
- #inspect ⇒ String
Constructor Details
#initialize(steps, source_line, ruby_code = nil) ⇒ Branch
Returns a new instance of Branch.
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_code ⇒ Object (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_line ⇒ Object (readonly)
Returns the value of attribute source_line.
7 8 9 |
# File 'lib/ll/branch.rb', line 7 def source_line @source_line end |
#steps ⇒ Object (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_set ⇒ Array<LL::Terminal>
Returns the FIRST() set of this branch.
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_set ⇒ Array<LL::Terminal>
Returns the FOLLOW() set of this branch.
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 |
#inspect ⇒ String
59 60 61 |
# File 'lib/ll/branch.rb', line 59 def inspect return "Branch(steps: #{steps.inspect}, ruby_code: #{ruby_code.inspect})" end |