Add Rule#id

This commit is contained in:
Josh Holtrop 2022-06-06 22:30:28 -04:00
parent 9d850294a9
commit 2837dfda6b
2 changed files with 9 additions and 2 deletions

View File

@ -44,7 +44,7 @@ class Propane
elsif sliced = input.slice!(/\A(\S+)\s*->\s*(.*?)(?:;|<<\n(.*?)^>>\n)/m) elsif sliced = input.slice!(/\A(\S+)\s*->\s*(.*?)(?:;|<<\n(.*?)^>>\n)/m)
rule_name, components, code = $1, $2, $3 rule_name, components, code = $1, $2, $3
components = components.strip.split(/\s+/) components = components.strip.split(/\s+/)
@rules << Rule.new(rule_name, components, code, line_number) @rules << Rule.new(rule_name, components, code, line_number, @rules.size)
else else
if input.size > 25 if input.size > 25
input = input.slice(0..20) + "..." input = input.slice(0..20) + "..."

View File

@ -10,6 +10,10 @@ class Propane
# User code associated with the rule. # User code associated with the rule.
attr_reader :code attr_reader :code
# @return [Integer]
# Rule ID.
attr_reader :id
# @return [Integer] # @return [Integer]
# Line number where the rule was defined in the input grammar. # Line number where the rule was defined in the input grammar.
attr_reader :line_number attr_reader :line_number
@ -28,10 +32,13 @@ class Propane
# User code associated with the rule. # User code associated with the rule.
# @param line_number [Integer] # @param line_number [Integer]
# Line number where the rule was defined in the input grammar. # Line number where the rule was defined in the input grammar.
def initialize(name, components, code, line_number) # @param id [Integer]
# Rule ID.
def initialize(name, components, code, line_number, id)
@name = name @name = name
@components = components @components = components
@code = code @code = code
@id = id
@line_number = line_number @line_number = line_number
end end