Class: Calyx::Result
- Inherits:
-
Object
- Object
- Calyx::Result
- Defined in:
- lib/calyx/result.rb
Overview
Value object representing a generated grammar result.
Instance Method Summary collapse
-
#initialize(expression) ⇒ Result
constructor
A new instance of Result.
-
#symbol ⇒ Symbol
(also: #to_sym)
Produces a symbol as the output of the grammar.
-
#text ⇒ String
(also: #to_s)
Produces a text string as the output of the grammar.
-
#tree ⇒ Array
(also: #to_exp)
Produces a syntax tree of nested nodes as the output of the grammar.
Constructor Details
#initialize(expression) ⇒ Result
Returns a new instance of Result.
4 5 6 |
# File 'lib/calyx/result.rb', line 4 def initialize(expression) @expression = expression.freeze end |
Instance Method Details
#symbol ⇒ Symbol Also known as: to_sym
Produces a symbol as the output of the grammar.
33 34 35 |
# File 'lib/calyx/result.rb', line 33 def symbol text.to_sym end |
#text ⇒ String Also known as: to_s
Produces a text string as the output of the grammar.
22 23 24 25 26 |
# File 'lib/calyx/result.rb', line 22 def text @expression.flatten.reject do |obj| obj.is_a?(Symbol) end.join end |
#tree ⇒ Array Also known as: to_exp
Produces a syntax tree of nested nodes as the output of the grammar. Each syntax node represents the production rules that were evaluated at each step of the generator.
13 14 15 |
# File 'lib/calyx/result.rb', line 13 def tree @expression end |