Class: Lrama::Rule

Inherits:
Struct
  • Object
show all
Defined in:
lib/lrama/grammar.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#codeObject

Returns the value of attribute code



5
6
7
# File 'lib/lrama/grammar.rb', line 5

def code
  @code
end

#idObject

Returns the value of attribute id



5
6
7
# File 'lib/lrama/grammar.rb', line 5

def id
  @id
end

#lhsObject

Returns the value of attribute lhs



5
6
7
# File 'lib/lrama/grammar.rb', line 5

def lhs
  @lhs
end

#linenoObject

Returns the value of attribute lineno



5
6
7
# File 'lib/lrama/grammar.rb', line 5

def lineno
  @lineno
end

#nullableObject

Returns the value of attribute nullable



5
6
7
# File 'lib/lrama/grammar.rb', line 5

def nullable
  @nullable
end

#precedence_symObject

Returns the value of attribute precedence_sym



5
6
7
# File 'lib/lrama/grammar.rb', line 5

def precedence_sym
  @precedence_sym
end

#rhsObject

Returns the value of attribute rhs



5
6
7
# File 'lib/lrama/grammar.rb', line 5

def rhs
  @rhs
end

Instance Method Details

#as_commentObject

Used by #user_actions



15
16
17
18
19
20
# File 'lib/lrama/grammar.rb', line 15

def as_comment
  l = lhs.id.s_value
  r = rhs.empty? ? "%empty" : rhs.map {|r| r.display_name }.join(" ")

  "#{l}: #{r}"
end

#initial_rule?Boolean



26
27
28
# File 'lib/lrama/grammar.rb', line 26

def initial_rule?
  id == 0
end

#precedenceObject



22
23
24
# File 'lib/lrama/grammar.rb', line 22

def precedence
  precedence_sym && precedence_sym.precedence
end

#to_sObject

TODO: Change this to display_name



7
8
9
10
11
12
# File 'lib/lrama/grammar.rb', line 7

def to_s
  l = lhs.id.s_value
  r = rhs.empty? ? "ε" : rhs.map {|r| r.id.s_value }.join(", ")

  "#{l} -> #{r}"
end

#translated_codeObject



30
31
32
33
34
35
36
# File 'lib/lrama/grammar.rb', line 30

def translated_code
  if code
    code.translated_code
  else
    nil
  end
end