Class: LL::Rule
- Inherits:
-
Object
- Object
- LL::Rule
- Defined in:
- lib/ll/rule.rb
Overview
Class containing details of a single rule in a grammar.
Instance Attribute Summary collapse
-
#branches ⇒ Object
readonly
Returns the value of attribute branches.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#references ⇒ Object
readonly
Returns the value of attribute references.
-
#source_line ⇒ Object
readonly
Returns the value of attribute source_line.
Instance Method Summary collapse
- #add_branch(steps, source_line, ruby_code = nil) ⇒ Object
-
#first_set ⇒ Array<LL::Terminal>
Returns an Array containing the terminals that make up the FIRST() set of this rule.
- #increment_references ⇒ Object
-
#initialize(name, source_line) ⇒ Rule
constructor
A new instance of Rule.
- #inspect ⇒ String
Constructor Details
#initialize(name, source_line) ⇒ Rule
12 13 14 15 16 17 |
# File 'lib/ll/rule.rb', line 12 def initialize(name, source_line) @name = name @branches = [] @source_line = source_line @references = 0 end |
Instance Attribute Details
#branches ⇒ Object (readonly)
Returns the value of attribute branches.
6 7 8 |
# File 'lib/ll/rule.rb', line 6 def branches @branches end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/ll/rule.rb', line 6 def name @name end |
#references ⇒ Object (readonly)
Returns the value of attribute references.
6 7 8 |
# File 'lib/ll/rule.rb', line 6 def references @references end |
#source_line ⇒ Object (readonly)
Returns the value of attribute source_line.
6 7 8 |
# File 'lib/ll/rule.rb', line 6 def source_line @source_line end |
Instance Method Details
#add_branch(steps, source_line, ruby_code = nil) ⇒ Object
22 23 24 |
# File 'lib/ll/rule.rb', line 22 def add_branch(steps, source_line, ruby_code = nil) branches << Branch.new(steps, source_line, ruby_code) end |
#first_set ⇒ Array<LL::Terminal>
Returns an Array containing the terminals that make up the FIRST() set of this rule.
36 37 38 39 40 41 42 43 44 |
# File 'lib/ll/rule.rb', line 36 def first_set terminals = [] branches.each do |branch| terminals += branch.first_set end return terminals end |
#increment_references ⇒ Object
26 27 28 |
# File 'lib/ll/rule.rb', line 26 def increment_references @references += 1 end |
#inspect ⇒ String
49 50 51 |
# File 'lib/ll/rule.rb', line 49 def inspect return "Rule(name: #{name.inspect}, branches: #{branches.inspect})" end |