Class: Calyx::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/calyx/result.rb

Overview

Value object representing a generated grammar result.

Instance Method Summary collapse

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

#symbolSymbol Also known as: to_sym

Produces a symbol as the output of the grammar.

Returns:

  • (Symbol)


33
34
35
# File 'lib/calyx/result.rb', line 33

def symbol
  text.to_sym
end

#textString Also known as: to_s

Produces a text string as the output of the grammar.

Returns:

  • (String)


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

#treeArray 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.

Returns:

  • (Array)


13
14
15
# File 'lib/calyx/result.rb', line 13

def tree
  @expression
end