class Calyx::Result

Value object representing a generated grammar result.

Public Class Methods

new(expression) click to toggle source
# File lib/calyx/result.rb, line 4
def initialize(expression)
  @expression = expression.freeze
end

Public Instance Methods

symbol() click to toggle source

Produces a symbol as the output of the grammar.

@return [Symbol]

# File lib/calyx/result.rb, line 33
def symbol
  text.to_sym
end
Also aliased as: to_sym
text() click to toggle source

Produces a text string as the output of the grammar.

@return [String]

# File lib/calyx/result.rb, line 22
def text
  @expression.flatten.reject do |obj|
    obj.is_a?(Symbol)
  end.join
end
Also aliased as: to_s
to_exp()
Alias for: tree
to_s()
Alias for: text
to_sym()
Alias for: symbol
tree() click to toggle source

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.

@return [Array]

# File lib/calyx/result.rb, line 13
def tree
  @expression
end
Also aliased as: to_exp